NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Zuragt.mn Retreaver // @namespace http://www.zuragt.mn // @include http://www.zuragt.mn/* // @require https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js // @version 1.2 // @grant none // ==/UserScript== $.urlParam = function(name, url) { if (!url) { url = window.location.href; } var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url); if (!results) { return undefined; } return results[1] || undefined; } Handlebars.registerHelper('tocustomdate', function(date) { var timezone = -date.getTimezoneOffset(); var d = date.toLocaleString("en-GB").split(", "); var k = d[0].split("/").reverse().join("") + d[1].split(":").join(""); return k + " " + ((timezone>=0)?"+":"-") + ("0"+parseInt(timezone/60)).slice(-2) + ("0"+(timezone%60)).slice(-2); }); var pTemplate = ` <?xml version="1.0" encoding="utf-8"?> <tv date="{{ now }}" source-info-url="{{ sourceinfo.url }}" source-info-name="{{ sourceinfo.name }}"> {{#channels}} <channel id="{{ id }}"> <display-name>{{ displayName }}</display-name> </channel> {{/channels}} {{#channels}} <!--this is all programs of channel {{ id }}--> {{#programs}} <programme start="{{tocustomdate sdate}}" stop="{{tocustomdate edate}}" channel="{{ ../id }}"> <title lang="mn">{{ title }}</title> <desc lang="mn">{{ desc }}</desc> <category lang="mn">{{ category }}</category> <language>{{ language }}</language> <rating system="{{ rating.system }}"> <value>{{ rating.value }}</value> </rating> </programme> {{/programs}} {{/channels}} </tv> `; $(document).ready(function(){ var dateString = $.urlParam("date"); if(!dateString) dateString = (new Date()).toISOString().substring(0,10); var dateArr = dateString.split("-").map(function(el){return parseInt(el);}); var channels = []; $(".middle-content").find(".tv-box").each(function(){ var channel = {}; var $this = $(this); var displayname = $this.find(".tv-header h1").html(); var $programLine = $this.find(".program-line"); var channelId = $programLine.attr("class").split(" ")[1]; channel = { id: channelId, displayName: displayname }; var programs = []; var prevDate; $programLine.children().each(function(){ var $pg = $(this); var timeArr = $pg.find(".time").html().split(":").map(function(el){return parseInt(el);}); var sdate = new Date(dateArr[0], dateArr[1]-1, dateArr[2], timeArr[0], timeArr[1], 0, 0); if(!prevDate) {prevDate = sdate;} else { if(prevDate > sdate) { sdate.setDate(sdate.getDate()+1); } } programs.push({ sdate: sdate, title: $pg.find(".program").html(), desc: "Тайлбар: " + $pg.find(".program").html(), language: 'mn', category: ["Зар", "Мэдээ", "Кино", "Цэнгээнт", "Хүүхэлдэйн кино"][Math.floor(Math.random()*5)], rating: { system: "VCHIP", value: "G" } }); }); for(var i = 0; i < programs.length-1; i++) { programs[i]["edate"] = new Date((programs[i+1]["sdate"]).getTime()); } var tmpProgram = programs[programs.length-1]; tmpProgram["edate"] = new Date(tmpProgram.sdate.getTime()+ 1 * 60 * 60 * 1000); channel["programs"] = programs; channels.push(channel); }); var $div = $("<textarea style='width:100%;height:400px'>"); var tmpl = Handlebars.compile(pTemplate); var rendered = tmpl({ now: function() {return (new Date()).toLocaleString("en-US");}, channels:channels, sourceinfo: { url: window.location.href, name: document.title } }); $div.html(rendered); $("body").prepend($div); });