Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name RuTorrent remote
- // @namespace http://example.com
- // @description remotly add torrents from eztv
- // @version 0.1
- // @date 2010-05-10
- // @creator author
- // @include http://eztv.it/
- // @include http://eztv.it/shows/*/*
- // @include https://eztv.it/
- // @include https://eztv.it/shows/*/*
- // ==/UserScript==
- //==//==//==//==//==//==//==//== LIBRARY FUNCTIONS ==//==//==//==//==//==//==//==//
- $i = function(id) {
- return document.getElementById(id);
- }
- $x = function(xpath, root) {
- var doc = root ? root.evaluate?root:root.ownerDocument : document;
- var got = doc.evaluate( xpath, root||doc, null, 0, null ), next;
- var result = [];
- while( next = got.iterateNext() )
- result.push( next );
- return result;
- }
- importNode = function(e4x, doc) {
- var me = importNode, xhtml, domTree, importMe;
- me.Const = me.Const || { mimeType: 'text/xml' };
- me.Static = me.Static || {};
- me.Static.parser = me.Static.parser || new DOMParser;
- xhtml = <testing xmlns="http://www.w3.org/1999/xhtml" />;
- xhtml.test = e4x;
- domTree = me.Static.parser.parseFromString( xhtml.toXMLString(),
- me.Const.mimeType );
- importMe = domTree.documentElement.firstChild;
- while( importMe && importMe.nodeType != 1 )
- importMe = importMe.nextSibling;
- if( !doc ) doc = document;
- return importMe ? doc.importNode( importMe, true ) : null;
- }
- function appendTo(e4x, node, doc) {
- return node.appendChild( importNode( e4x, doc || node.ownerDocument ) );
- }
- var Base64 = {
- // private property
- _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
- // public method for encoding
- encode : function (input) {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
- input = Base64._utf8_encode(input);
- while (i < input.length) {
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
- output = output +
- this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
- this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
- }
- return output;
- },
- // public method for decoding
- decode : function (input) {
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
- while (i < input.length) {
- enc1 = this._keyStr.indexOf(input.charAt(i++));
- enc2 = this._keyStr.indexOf(input.charAt(i++));
- enc3 = this._keyStr.indexOf(input.charAt(i++));
- enc4 = this._keyStr.indexOf(input.charAt(i++));
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
- output = output + String.fromCharCode(chr1);
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
- }
- output = Base64._utf8_decode(output);
- return output;
- },
- // private method for UTF-8 encoding
- _utf8_encode : function (string) {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
- for (var n = 0; n < string.length; n++) {
- var c = string.charCodeAt(n);
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- }
- return utftext;
- },
- // private method for UTF-8 decoding
- _utf8_decode : function (utftext) {
- var string = "";
- var i = 0;
- var c = c1 = c2 = 0;
- while ( i < utftext.length ) {
- c = utftext.charCodeAt(i);
- if (c < 128) {
- string += String.fromCharCode(c);
- i++;
- }
- else if((c > 191) && (c < 224)) {
- c2 = utftext.charCodeAt(i+1);
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- }
- else {
- c2 = utftext.charCodeAt(i+1);
- c3 = utftext.charCodeAt(i+2);
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
- }
- return string;
- }
- }
- //==//==//==//==//==//==//==//== LIBRARY FUNCTIONS END ==//==//==//==//==//==//==//
- meta = new Array();
- auth = null;
- rr_serverchange = function() {
- for(var i=0; i<2; i++)
- if($i('ssb'+i).checked)
- s = i;
- GM_setValue('server',s);
- }
- rr_download_statechange = function(id, rd) {
- alert(id + ' ' + rd.readyStatus);
- if(rd.readyState < 4)
- return;
- if(rd==200)
- meta[id][2].src = "https://127.0.0.1/testing/img/16/weather-clear.png";
- else
- meta[id][2].src = "https://127.0.0.1/testing/img/16/weather-storm.png";
- }
- rr_download_start = function(id,/*obj*/) {
- alert(id);
- //alert(obj.id.match(/rr_down_(.*)/)[1]);
- meta[id][2].src = "https://127.0.0.1/testing/img/16/software-update-available.png";
- GM_xmlhttpRequest
- ({
- method: "POST",
- url: "https://example.com/rt/addtorrent.php",
- headers: { "Content-Type": "application/x-www-form-urlencoded"},
- data: 'url='+encodeURI(meta[id][3]),
- onreadystatechange: function(rd) {rr_download_statechange(id,rd)}
- });
- }
- rr_onload = function() {
- // create authorization token
- auth = Base64.encode('rr:vnurnalurnfhzab4kzhb'); //example credentials
- // prepare server switch boxes
- var ssbp = <div id="ssb_parent" style="border: 1px #0F559D solid; background-color: #D8EAFC; position: fixed; right: 10px; top: 10px; padding: 2px;">
- <input type="radio" name="ssb" id="ssb0" value="0"/> <label for="ssb0">lgw</label><br/>
- <input type="radio" name="ssb" id="ssb1" value="1"/> <label for="ssb1">root</label>
- </div>;
- // insert server switch boxes
- appendTo(ssbp, document.body);
- // add listener
- for(var i=0; i<2; i++)
- $i('ssb'+i).addEventListener('click',rr_serverchange,false);
- // get last selected server
- if(GM_getValue('server'))
- s = GM_getValue('server');
- else
- s = 0;
- // set selection
- $i('ssb'+s).checked = true;
- rr_releasetypes = new Array(new Array(/720p/i,"720p","B63ABA"),
- new Array(/hdtv/i,"HDTV","429BF5"),
- new Array(/pdtv/i,"PDTV","09E34E")
- );
- rr_releaseimprovements = new Array(/prope?r/i,
- /repack/i);
- // scan for torrents
- var trs = $x("//tr[@class='forum_header_border']");
- for(var i=0; i<trs.length; i++) {
- var rt = 0;
- var imp = false;
- var td = $x("./td[2]",trs[i]);
- if(!td.length)
- continue;
- else
- td = td[0];
- var desc = $x("./a",td);
- if(!desc.length)
- continue;
- else
- desc = desc[0].title
- for(j=0; j<rr_releasetypes.length; j++) {
- if(desc.match(rr_releasetypes[j][0])) {
- for(k=0; k<rr_releaseimprovements.length; k++) {
- if(desc.match(rr_releaseimprovements[k])) {
- imp = true;
- break;
- }
- }
- rt = j;
- break;
- }
- }
- var tlink = $x("./td[3]/a[@class='magnet']",trs[i])[0];
- var reltype = appendTo(<span style="float: right; font-size: -2; color: {rr_releasetypes[j][2]}">{rr_releasetypes[rt][1]}</span>,td);
- if(imp)
- td.style.backgroundColor = "#9AF5CB";
- var linkid = "rr_down_"+i;
- var link = appendTo(<a id={linkid} style="cursor: pointer; margin-left: 3px;"/>, reltype);
- var img = appendTo(<img src="https://127.0.0.1/testing/img/16/go-bottom.png" style="vertical-align: middle;"/>, link);
- // save pointers to html elements for later editing
- meta[i] = new Array(reltype,link,img,tlink.href);
- // add event handler
- link.addEventListener('click',function(){rr_download_start(i,this);},false);
- }
- //debug
- unsafeWindow.meta=meta;
- }
- window.addEventListener('load',rr_onload,false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement