Advertisement
Guest User

Untitled

a guest
May 10th, 2010
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          RuTorrent remote
  3. // @namespace     http://example.com
  4. // @description   remotly add torrents from eztv
  5. // @version       0.1
  6. // @date          2010-05-10
  7. // @creator       author
  8. // @include       http://eztv.it/
  9. // @include       http://eztv.it/shows/*/*
  10. // @include       https://eztv.it/
  11. // @include       https://eztv.it/shows/*/*
  12. // ==/UserScript==
  13.  
  14.  
  15. //==//==//==//==//==//==//==//== LIBRARY FUNCTIONS ==//==//==//==//==//==//==//==//
  16.  
  17. $i = function(id) {
  18.   return document.getElementById(id);
  19. }
  20.  
  21. $x = function(xpath, root) {
  22.   var doc = root ? root.evaluate?root:root.ownerDocument : document;
  23.   var got = doc.evaluate( xpath, root||doc, null, 0, null ), next;
  24.   var result = [];
  25.   while( next = got.iterateNext() )
  26.     result.push( next );
  27.   return result;
  28. }
  29.  
  30. importNode = function(e4x, doc) {
  31.   var me = importNode, xhtml, domTree, importMe;
  32.   me.Const = me.Const || { mimeType: 'text/xml' };
  33.   me.Static = me.Static || {};
  34.   me.Static.parser = me.Static.parser || new DOMParser;
  35.   xhtml = <testing xmlns="http://www.w3.org/1999/xhtml" />;
  36.   xhtml.test = e4x;
  37.   domTree = me.Static.parser.parseFromString( xhtml.toXMLString(),
  38.            me.Const.mimeType );
  39.   importMe = domTree.documentElement.firstChild;
  40.   while( importMe && importMe.nodeType != 1 )
  41.     importMe = importMe.nextSibling;
  42.   if( !doc ) doc = document;
  43.   return importMe ? doc.importNode( importMe, true ) : null;
  44. }
  45.  
  46. function appendTo(e4x, node, doc) {
  47.   return node.appendChild( importNode( e4x, doc || node.ownerDocument ) );
  48. }
  49.  
  50. var Base64 = {
  51.  
  52.   // private property
  53.   _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  54.  
  55.   // public method for encoding
  56.   encode : function (input) {
  57.     var output = "";
  58.     var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  59.     var i = 0;
  60.  
  61.     input = Base64._utf8_encode(input);
  62.  
  63.     while (i < input.length) {
  64.  
  65.       chr1 = input.charCodeAt(i++);
  66.       chr2 = input.charCodeAt(i++);
  67.       chr3 = input.charCodeAt(i++);
  68.  
  69.       enc1 = chr1 >> 2;
  70.       enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  71.       enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  72.       enc4 = chr3 & 63;
  73.  
  74.       if (isNaN(chr2)) {
  75.         enc3 = enc4 = 64;
  76.       } else if (isNaN(chr3)) {
  77.         enc4 = 64;
  78.       }
  79.  
  80.       output = output +
  81.       this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
  82.       this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
  83.  
  84.     }
  85.  
  86.     return output;
  87.   },
  88.  
  89.   // public method for decoding
  90.   decode : function (input) {
  91.     var output = "";
  92.     var chr1, chr2, chr3;
  93.     var enc1, enc2, enc3, enc4;
  94.     var i = 0;
  95.  
  96.     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  97.  
  98.     while (i < input.length) {
  99.  
  100.       enc1 = this._keyStr.indexOf(input.charAt(i++));
  101.       enc2 = this._keyStr.indexOf(input.charAt(i++));
  102.       enc3 = this._keyStr.indexOf(input.charAt(i++));
  103.       enc4 = this._keyStr.indexOf(input.charAt(i++));
  104.  
  105.       chr1 = (enc1 << 2) | (enc2 >> 4);
  106.       chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  107.       chr3 = ((enc3 & 3) << 6) | enc4;
  108.  
  109.       output = output + String.fromCharCode(chr1);
  110.  
  111.       if (enc3 != 64) {
  112.         output = output + String.fromCharCode(chr2);
  113.       }
  114.       if (enc4 != 64) {
  115.         output = output + String.fromCharCode(chr3);
  116.       }
  117.  
  118.     }
  119.  
  120.     output = Base64._utf8_decode(output);
  121.  
  122.     return output;
  123.  
  124.   },
  125.  
  126.   // private method for UTF-8 encoding
  127.   _utf8_encode : function (string) {
  128.     string = string.replace(/\r\n/g,"\n");
  129.     var utftext = "";
  130.  
  131.     for (var n = 0; n < string.length; n++) {
  132.  
  133.       var c = string.charCodeAt(n);
  134.  
  135.       if (c < 128) {
  136.         utftext += String.fromCharCode(c);
  137.       }
  138.       else if((c > 127) && (c < 2048)) {
  139.         utftext += String.fromCharCode((c >> 6) | 192);
  140.         utftext += String.fromCharCode((c & 63) | 128);
  141.       }
  142.       else {
  143.         utftext += String.fromCharCode((c >> 12) | 224);
  144.         utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  145.         utftext += String.fromCharCode((c & 63) | 128);
  146.       }
  147.  
  148.     }
  149.  
  150.     return utftext;
  151.   },
  152.  
  153.   // private method for UTF-8 decoding
  154.   _utf8_decode : function (utftext) {
  155.     var string = "";
  156.     var i = 0;
  157.     var c = c1 = c2 = 0;
  158.  
  159.     while ( i < utftext.length ) {
  160.  
  161.       c = utftext.charCodeAt(i);
  162.  
  163.       if (c < 128) {
  164.         string += String.fromCharCode(c);
  165.         i++;
  166.       }
  167.       else if((c > 191) && (c < 224)) {
  168.         c2 = utftext.charCodeAt(i+1);
  169.         string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  170.         i += 2;
  171.       }
  172.       else {
  173.         c2 = utftext.charCodeAt(i+1);
  174.         c3 = utftext.charCodeAt(i+2);
  175.         string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  176.         i += 3;
  177.       }
  178.  
  179.     }
  180.  
  181.     return string;
  182.   }
  183.  
  184. }
  185.  
  186. //==//==//==//==//==//==//==//== LIBRARY FUNCTIONS END ==//==//==//==//==//==//==//
  187.  
  188. meta = new Array();
  189. auth = null;
  190.  
  191. rr_serverchange = function() {
  192.   for(var i=0; i<2; i++)
  193.     if($i('ssb'+i).checked)
  194.       s = i;
  195.   GM_setValue('server',s);
  196. }
  197.  
  198. rr_download_statechange = function(id, rd) {
  199.   alert(id + ' ' + rd.readyStatus);
  200.   if(rd.readyState < 4)
  201.     return;
  202.    
  203.   if(rd==200)
  204.     meta[id][2].src = "https://127.0.0.1/testing/img/16/weather-clear.png";
  205.   else
  206.     meta[id][2].src = "https://127.0.0.1/testing/img/16/weather-storm.png";
  207. }
  208.  
  209. rr_download_start = function(id,/*obj*/) {
  210.   alert(id);
  211.   //alert(obj.id.match(/rr_down_(.*)/)[1]);
  212.   meta[id][2].src = "https://127.0.0.1/testing/img/16/software-update-available.png";
  213.  
  214.   GM_xmlhttpRequest
  215.   ({
  216.     method:   "POST",
  217.     url:      "https://example.com/rt/addtorrent.php",
  218.     headers:  { "Content-Type": "application/x-www-form-urlencoded"},
  219.     data:     'url='+encodeURI(meta[id][3]),
  220.     onreadystatechange: function(rd) {rr_download_statechange(id,rd)}
  221.   });
  222. }
  223.  
  224. rr_onload = function() {
  225.   // create authorization token
  226.   auth = Base64.encode('rr:vnurnalurnfhzab4kzhb'); //example credentials
  227.   // prepare server switch boxes
  228.   var ssbp = <div id="ssb_parent" style="border: 1px #0F559D solid; background-color: #D8EAFC; position: fixed; right: 10px; top: 10px; padding: 2px;">
  229.                <input type="radio" name="ssb" id="ssb0" value="0"/> <label for="ssb0">lgw</label><br/>
  230.                <input type="radio" name="ssb" id="ssb1" value="1"/> <label for="ssb1">root</label>
  231.              </div>;
  232.   // insert server switch boxes
  233.   appendTo(ssbp, document.body);
  234.  
  235.   // add listener
  236.   for(var i=0; i<2; i++)
  237.     $i('ssb'+i).addEventListener('click',rr_serverchange,false);
  238.  
  239.   // get last selected server
  240.   if(GM_getValue('server'))
  241.     s = GM_getValue('server');
  242.   else
  243.     s = 0;
  244.  
  245.   // set selection
  246.   $i('ssb'+s).checked = true;
  247.  
  248.   rr_releasetypes = new Array(new Array(/720p/i,"720p","B63ABA"),
  249.                               new Array(/hdtv/i,"HDTV","429BF5"),
  250.                               new Array(/pdtv/i,"PDTV","09E34E")
  251.                              );
  252.   rr_releaseimprovements = new Array(/prope?r/i,
  253.                                      /repack/i);
  254.  
  255.  
  256.  
  257.   // scan for torrents
  258.   var trs = $x("//tr[@class='forum_header_border']");
  259.   for(var i=0; i<trs.length; i++) {
  260.  
  261.     var rt = 0;
  262.     var imp = false;
  263.  
  264.     var td = $x("./td[2]",trs[i]);
  265.     if(!td.length)
  266.       continue;
  267.     else
  268.       td = td[0];
  269.    
  270.     var desc = $x("./a",td);
  271.     if(!desc.length)
  272.       continue;
  273.     else
  274.       desc = desc[0].title
  275.  
  276.     for(j=0; j<rr_releasetypes.length; j++) {
  277.       if(desc.match(rr_releasetypes[j][0])) {
  278.         for(k=0; k<rr_releaseimprovements.length; k++) {
  279.           if(desc.match(rr_releaseimprovements[k])) {
  280.             imp = true;
  281.             break;
  282.           }
  283.         }
  284.         rt = j;
  285.  
  286.         break;
  287.       }
  288.     }
  289.     var tlink = $x("./td[3]/a[@class='magnet']",trs[i])[0];
  290.  
  291.     var reltype = appendTo(<span style="float: right; font-size: -2; color: {rr_releasetypes[j][2]}">{rr_releasetypes[rt][1]}</span>,td);
  292.     if(imp)
  293.       td.style.backgroundColor = "#9AF5CB";
  294.  
  295.     var linkid = "rr_down_"+i;
  296.     var link = appendTo(<a id={linkid} style="cursor: pointer; margin-left: 3px;"/>, reltype);
  297.     var img  = appendTo(<img src="https://127.0.0.1/testing/img/16/go-bottom.png" style="vertical-align: middle;"/>, link);
  298.    
  299.     // save pointers to html elements for later editing
  300.     meta[i] = new Array(reltype,link,img,tlink.href);
  301.  
  302.     // add event handler
  303.     link.addEventListener('click',function(){rr_download_start(i,this);},false);
  304.   }
  305. //debug
  306. unsafeWindow.meta=meta;
  307. }
  308. window.addEventListener('load',rr_onload,false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement