SVN: toys/rsget.pl/rsget_pl.user.js
sparky
sparky at pld-linux.org
Thu Mar 11 03:07:13 CET 2010
Author: sparky
Date: Thu Mar 11 03:07:12 2010
New Revision: 11244
Added:
toys/rsget.pl/rsget_pl.user.js
Log:
- new userscript, still somewhat problematic, but it isn't limited to
GreaseMonkey unlike the previous one; besides mozilla browsers also
epiphany, chromium and opera are supported
Added: toys/rsget.pl/rsget_pl.user.js
==============================================================================
--- (empty file)
+++ toys/rsget.pl/rsget_pl.user.js Thu Mar 11 03:07:12 2010
@@ -0,0 +1,602 @@
+// ==UserScript==
+// @name rsget.pl
+// @namespace http://rsget.pl/
+// @description quickly add links to rsget.pl
+// @include http://*/*
+// @include https://*/*
+// @include file://*
+// ==/UserScript==
+
+var server = 'http://localhost:5666/';
+
+/* supported links {{{ */
+var supported2 = {
+ "4gk.com": 1, "4shared.com": 1, "anonym.to": 1,
+ "archiv.to": 1, "badongo.com": 1, "bitroad.net": 1,
+ "break.com": 2, "crypted.biz": 1, "crypt-it.com": 1,
+ "dailymotion.com": 2, "dailymotion.pl": 2, "depositfiles.com": 1,
+ "extremetube.com": 2, "filefactory.com": 1, "flyfile.us": 1,
+ "freakshare.net": 1, "gigasize.com": 1, "goear.com": 2,
+ "hotfile.com": 1, "imageshack.us": 2, "linkhider.com": 1,
+ "link-protector.com": 1, "liveleak.com": 2, "lix.in": 1,
+ "mediafire.com": 1, "megaporn.com": 2, "megarotic.com": 1,
+ "megaupload.com": 1, "megavideo.com": 2, "metacafe.com": 2,
+ "netload.in": 1, "pornhub.com": 2, "protectlinks.com": 1,
+ "przeklej.pl": 1, "rapidshare.de": 1, "rapidshark.pl": 1,
+ "redtube.com": 2, "rapidshare.com": 1, "rsprotect.com": 1,
+ "secured.in": 1, "sendspace.com": 1, "sendspace.pl": 1,
+ "sexuploader.com": 1, "sharebee.com": 1, "shareplace.com": 1,
+ "sharingmatrix.com": 1, "spankwire.com": 2, "storage.to": 1,
+ "tinyurl.com": 1, "turbobit.net": 1, "turbobit.ru": 1,
+ "turboupload.com": 1, "ul.to": 1, "up-file.com": 1,
+ "uploaded.to": 1, "uploading.com": 1, "veoh.com": 2,
+ "vimeo.com": 2, "easy-share.com": 1, "zippyshare.com": 1,
+ "x7.to": 1, "xhamster.com": 2, "xurl.jp": 1,
+ "youporn.com": 2, "youtube.com": 2, "zshare.net": 1,
+};
+
+var supported3 = {
+ "d01.megashares.com": 1, "save.raidrush.ws": 1,
+ "tv.delfi.ee": 2, "video.banzaj.pl": 2,
+ "video.google.com": 2, "video.interia.pl": 2,
+ "vids.myspace.com": 2,
+};
+/* }}} */
+
+/* tools: async, el {{{ */
+function async( f )
+{
+ window.setTimeout( f, 0 );
+}
+
+function el( tag, attrib )
+{
+ var el = document.createElement( tag );
+
+ if ( attrib )
+ for ( var name in attrib )
+ el.setAttribute( name, attrib[ name ] );
+
+ return el;
+}
+
+function stop_propagation( ev )
+{
+ ev.stopPropagation();
+}
+
+var _cnt = 1;
+function cnt()
+{
+ return ++_cnt;
+}
+/* }}} */
+
+var finder = { /* {{{ */
+ page_supported: false,
+
+ _text_tags: [ "pre", "div", "td", "p", "span" ],
+ _text_i: 0,
+ _text_nodes: null,
+ _a_i: 0,
+ _a_nodes: 0,
+ links: [],
+
+ init: function ()
+ {
+ if ( finder.page_supported = finder._check_support( document.location.href ) ) {
+ menu.init();
+ }
+ finder._get_text();
+ },
+
+ _get_text: function ()
+ {
+ finder._text_i = 0;
+ finder._text_nodes = null;
+ if ( ! finder._text_tags.length )
+ return finder._get_a();
+
+ finder._text_nodes = document.getElementsByTagName(
+ finder._text_tags.shift()
+ );
+ async( finder._check_text );
+ },
+ _check_text: function ()
+ {
+ if ( finder._text_i >= finder._text_nodes.length )
+ return finder._get_text();
+
+ var text_node = finder._text_nodes[ finder._text_i++ ];
+ async( finder._check_text );
+
+ var node = text_node.firstChild;
+ if ( ! node )
+ return;
+
+ var found = false;
+
+ do {
+ if ( node.nodeName != '#text' )
+ continue;
+ var text = node.nodeValue;
+ if ( text == null || text.length < 15 )
+ continue;
+
+ var hrefs = text.match( /(http:\/\/\S+\/\S+)/g );
+
+ if ( ! hrefs || hrefs.length <= 0 )
+ continue;
+
+ for ( var i = 0; i < hrefs.length; i++ ) {
+ var href = hrefs[ i ];
+ if ( ! finder._check_support( href ) )
+ continue;
+ var start = text.indexOf( href );
+ if ( start < 0 )
+ continue;
+
+ text_node.insertBefore(
+ document.createTextNode( text.substr( 0, start ) ),
+ node );
+
+ /* class is a special word, must have quotes */
+ var a = el( 'a', { href: href, 'class': 'get_link_text' } );
+ a.addEventListener( 'DOMActivate', finder._click, false );
+ a.addEventListener( 'click', finder._click, false );
+ a.appendChild( document.createTextNode( href ) );
+ text_node.insertBefore( a, node );
+
+ text = text.substr( start + href.length );
+ node.nodeValue = text;
+
+ found = true;
+ }
+ } while ( node = node.nextSibling );
+
+ if ( found )
+ menu.init();
+ },
+
+ _get_a: function ()
+ {
+ finder._a_i = 0;
+ finder._a_nodes = document.getElementsByTagName( 'a' );
+ async( finder._check_a );
+ },
+ _check_a: function ()
+ {
+ if ( finder._a_i + 10 < finder._a_nodes.length )
+ async( finder._check_a );
+ else {
+ async( finder._end );
+ }
+
+ for ( var i = 0; i < 10; i++, finder._a_i++ ) {
+ if ( finder._a_i >= finder._a_nodes.length )
+ break;
+
+ var a = finder._a_nodes[ finder._a_i ];
+ var cl = a.getAttribute( 'class' );
+ if ( cl && cl == 'get_link_text' ) {
+ finder._link( a );
+ continue;
+ }
+
+ var href = a.getAttribute( 'href' );
+ if ( href == null )
+ continue;
+
+ if ( finder._check_support( href ) ) {
+ a.setAttribute( 'class',
+ cl == null ? 'get_link' : cl + ' get_link' );
+ finder._link( a );
+ } else if ( finder.page_supported ) {
+ var m = href.match( /^[a-zA-Z0-9]+:/ );
+ if ( !m || m.length < 1 ) {
+ if ( href.indexOf( "/" ) == 0 ) {
+ m = document.location.href.match( /^(.*?\/\/.*?)\// );
+ href = m[ 1 ] + href;
+ } else {
+ m = document.location.href.match( /^(.*?\/\/.*\/)/ );
+ href = m[ 1 ] + href;
+ }
+ a.setAttribute( 'class',
+ cl == null ? 'get_link' : cl + ' get_link' );
+ a.setAttribute( 'href', href );
+ finder._link( a );
+ }
+ }
+ }
+ },
+ _end: function ()
+ {
+ finder._a_i = 0;
+ finder._a_nodes = null;
+ if ( finder.page_supported == 1 )
+ menu.open();
+ },
+ _link: function ( a )
+ {
+ if ( finder.links.length == 0 )
+ menu.init();
+
+ finder.links.push( a );
+ },
+ _check_support: function ( href )
+ {
+ var m = href.match( /http:\/\/.*?([a-z0-9-]+\.[a-z]{2,3})\// );
+ if ( m && m.length ) {
+ var s = supported2[ m[1] ];
+ if ( s )
+ return s;
+
+ var m = href.match( /http:\/\/.*?([a-z0-9-]+\.[a-z0-9-]+\.[a-z]{2,3})\// );
+ if ( m && m.length ) {
+ s = supported3[ m[1] ];
+ return s;
+ }
+ }
+
+ return 0;
+ },
+ _click: function ( ev )
+ {
+ ev.stopPropagation();
+ ev.preventDefault();
+
+ var get = server + "add?links=" + escape( this.getAttribute( 'href' ) )
+ + "&comment=" + escape( "source: " + document.location.href );
+ try {
+ GM_openInTab( get );
+ } catch ( e ) {
+ window.open( get, "_blank" )
+ }
+ }
+}; /* }}} */
+
+var selection = { /* {{{ */
+ init: function ()
+ {
+ document.addEventListener( 'mouseup', selection._check_ev, false );
+ document.addEventListener( 'keyup', selection._check_ev, false );
+ },
+ get: function ()
+ {
+ var sel = window.getSelection();
+ var links = [];
+ if ( sel.isCollapsed === true )
+ return links;
+ var srclinks = finder.links;
+ var len = srclinks.length;
+ for ( var i = 0; i < len; i++ ) {
+ if ( sel.containsNode( srclinks[ i ], true ) )
+ links.push( srclinks[ i ] );
+ }
+
+ return links;
+ },
+ _check_ev: function ( ev )
+ {
+ if ( menu.manual_open )
+ async( menu.open );
+ else
+ async( selection._check );
+ },
+ _check: function ()
+ {
+ var l = selection.get();
+
+ if ( l.length )
+ menu.open();
+ else
+ menu.close();
+ }
+}; /* }}} */
+
+var menu = { /* {{{ */
+ _interval: null, // toggling interval
+ _opened: false, // is menu opened ?
+ _move: 10, // opening/closing movement
+ _width: 0, // actual menu width
+ _box: null, // container node
+ _initialized: false, // is menu shown ?
+ manual_open: false,
+ init: function ()
+ {
+ if ( menu._initialized )
+ return;
+ menu._initialized = true;
+
+ var css = getCss();
+ try {
+ GM_addStyle( css );
+ } catch ( e ) {
+ var cssEl = el( 'link', { rel: 'stylesheet', type: 'text/css',
+ href: 'data:text/css,' + encodeURIComponent( css ) } );
+ var head;
+ if ( head = document.getElementsByTagName('head')[0] ) {
+ head.appendChild( cssEl );
+ } else {
+ var doc = document.documentElement;
+ doc.insertBefore( cssEl, doc.firstChild );
+ }
+ }
+
+ var body = document.getElementsByTagName( 'body' )[0];
+
+ menu._box = el( 'div', { id: 'rsget_pl' } );
+ var button = el( 'span' );
+ menu._box.appendChild( button );
+
+ body.appendChild( menu._box );
+
+ menu._box.addEventListener( 'DOMActivate', stop_propagation, false );
+ menu._box.addEventListener( 'click', stop_propagation, false );
+ button.addEventListener( 'DOMActivate', menu._toggle_ev, false );
+ button.addEventListener( 'click', menu._toggle_ev, false );
+ window.addEventListener( 'scroll', menu._update_position, false );
+
+ async( selection.init );
+ async( menu._update_position );
+ },
+ _toggle_ev: function ( ev )
+ {
+ ev.stopPropagation();
+ ev.preventDefault();
+ async( menu._toggle );
+ },
+ _toggle: function ()
+ {
+ if ( menu._opened ) {
+ menu.manual_open = false;
+ menu.close();
+ } else {
+ menu.manual_open = true;
+ menu.open();
+ }
+ },
+ open: function ()
+ {
+ menu.init();
+
+ var rm = menu._box.lastChild;
+ if ( rm.nodeName == 'DIV' )
+ menu._box.removeChild( rm );
+
+ var div = el( 'div' );
+ var ul = el( 'ul' );
+
+ if ( finder.page_supported ) {
+ ul.appendChild( menu._li_form(
+ [ document.location.href ],
+ window.top.location.href,
+ "add this page to rsget.pl"
+ ) );
+ }
+ if ( finder.links.length ) {
+ ul.appendChild( menu._li_form(
+ finder.links,
+ document.location.href,
+ "add the only link to rsget.pl",
+ "add all %d links to rsget.pl"
+ ) );
+
+ var l = selection.get();
+ if ( l.length )
+ ul.appendChild( menu._li_form(
+ l,
+ document.location.href,
+ "add selected link to rsget.pl",
+ "add %d selected links to rsget.pl"
+ ) );
+ }
+
+ div.appendChild( ul );
+ menu._box.appendChild( div );
+
+ if ( menu._opened )
+ return;
+ menu._move = +10;
+ if ( ! menu._interval )
+ menu._interval = window.setInterval( menu._slide, 20 );
+ menu._opened = true;
+ },
+ close: function ()
+ {
+ if ( ! menu._opened || menu.manual_open )
+ return;
+ menu._move = -10;
+ if ( ! menu._interval )
+ menu._interval = window.setInterval( menu._slide, 20 );
+ menu._opened = false;
+ },
+ _slide: function ()
+ {
+ menu._width += menu._move;
+ if ( menu._move > 0 ) {
+ if ( menu._width >= 250 ) {
+ menu._width = 250;
+ window.clearInterval( menu._interval );
+ menu._interval = null;
+ }
+ } else {
+ if ( menu._width <= 0 ) {
+ menu._width = 0;
+ window.clearInterval( menu._interval );
+ menu._interval = null;
+
+ var rm = menu._box.lastChild;
+ if ( rm.nodeName == 'DIV' )
+ menu._box.removeChild( rm );
+ }
+ }
+
+ menu._box.style.width = ( 16 + menu._width ) + "px";
+ menu._box.style.opacity = 0.2 + menu._width * 0.003;
+ },
+ _update_position: function ( ev )
+ {
+ var y = window.pageYOffset || document.documentElement.scrollTop || 0;
+ menu._box.style.top = ( y + 100 ) + "px";
+ },
+ _li_form: function ( links, source, text1, textN )
+ {
+ var ltext = links.join( "\n" );
+ var text = links.length == 1 ? text1 : textN.replace( /%d/, links.length );
+
+ var form = el( 'form', { action: server + "add#cnt_" + cnt(),
+ method: 'POST', target: '_blank' } );
+
+ form.appendChild( el( 'input', { type: 'hidden',
+ name: 'links', value: ltext } ) );
+ form.appendChild( el( 'input', { type: 'hidden',
+ name: 'comment', value: "source: " + source } ) );
+ form.appendChild( el( 'input', { type: 'submit', value: text } ) );
+
+ var li = el( 'li' );
+ li.appendChild( form );
+
+ return li;
+ }
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gaWMnwVaDrWo1a/d'
+ + 'BvotA+RuuHIYaw7MKTI4DkhH8weLNjQwiIMFRuokUsE7p/mQA+/QXXHYH2csmRBZOCQOJrX2yMLc'
+ + '6FtgzkQJX7uV/5G1Szj91jn+FTztkc+tWM/bfzTpViSa6M6aAAAAAElFTkSuQmCC'
+ + ')';
+
<<diff output has been trimmed to 500 lines, 103 line(s) remained.>>
More information about the pld-cvs-commit
mailing list