NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name DDL@ScanLibs.com // @namespace DDL@ScanLibs.com // @description Enables direct/faster downloads of ebooks on ScanLibs.com - collects and delegates download links to JDownloader (needs to run in background) // @updateURL https://openuserjs.org/meta/Paxae3/DDLScanLibs.com.meta.js // @include http://scanlibs.com/* // @icon http://scanlibs.com/favicon.png // @require https://code.jquery.com/jquery-3.1.1.min.js // @author Paxae3 // @version 1.0 // @copyright 2017, Paxae3 // @license MIT License // @grant none // ==/UserScript== var logging = false; var jCount = 0; // // logs param into console, depending on global logging value // function log(text) { if(!logging)return; console.log("DDL@scanlibs.com:"+text); } // // counts link-counter up and updates GUI // function addCount() { $("#jdown > span").html(""+(++jCount)); } // // processes AJAX-data of overview-page // function handleOverview(data, url) { // getting ad-page link(s) if (jQuery(data).find('span.mybtn.mylink').length == 1) { $("#clipboardInput").append(" "+getTargetUrlFromDataUrl(jQuery(data).find('span.mybtn.mylink').attr('data-url'))); log('ajax_performed:found_one_file_link:'); $('[url=\'' + url + '\']').css('color', 'green'); addCount(); return true; } else if (jQuery(data).find('span.mylink').length >= 1) { var i=0; jQuery(data).find("span.mylink").each(function() { i++; $("#clipboardInput").append(" "+getTargetUrlFromDataUrl($(this).attr("data-url"))); addCount(); }); log('ajax_performed:found_multiple_file_links:'+i); $('[url=\'' + url + '\']').css('color', 'green'); return true; } log('ajax_performed:found_no_file_links'); $('[url=\'' + url + '\']').css('color', 'red'); return false; } // // extracts target-url out of base64 encoded data-url // function getTargetUrlFromDataUrl(dataUrl) { log('extract:start:' + dataUrl); // strip prefix var ret = dataUrl.substr(dataUrl.indexOf('/') + 1); log('extract:unprefix:' + ret); // get full url ret = atob(ret); log('extract:decode:' + ret); // extract target url ret = ret.substr(ret.lastIndexOf('http')); log('extract:finish:' + ret); return ret } // // selects all entries of textarea and copy them into clipboard // function clipboardCallback() { $("#clipboardInput").select(); log('clipboard:selected'); document.execCommand('copy'); log('clipboard:copied'); jCount = -1; addCount(); // delete content of textarea after 2 seconds window.setTimeout(function(){ $("#clipboardInput").html(""); document.execCommand('copy');}, 2000); } log('START'); // START // // Setting actions into buttons (only when in root of page) if ((window.location.pathname == '/') || (window.location.pathname.indexOf("/page/")==0 )) { log('buttons:init'); // adding input field $("body").prepend('<textarea id="clipboardInput" style="position:fixed;top:0px;left:-100px;height:50px;width:50px;"></textarea>'); // switching buttons $(".read-more").each(function(){$(this).before('<span class="btn btn-default read-more" url="'+$(this).attr("href")+ '" style="margin-left:20px;">Download</span>');}); // add copy-to-jdownloader-field $("body").prepend('<div style="position:fixed;right:5px;top:5px;width:100px;height:105px;z-index:999;box-shadow: 5px 5px 5px #2F4F4F;border: 1px solid black;" class="btn btn-default" id="jdown">'+ '<img src="http://www.freeiconspng.com/uploads/jdownloader-icon-2.png" /><br /><span>0</span></div>'); $("#jdown").click(clipboardCallback); // adding events on buttons $('span.read-more').click(function () { log('button:click'); // button-text in "pending" orange $(this).css('color', 'orange'); log('ajax_start:' + $(this).attr('url')); // Getting Overview page $.get($(this).attr('url'), function (data) { handleOverview(data, $(this).attr('url')) }).fail( function () { log('ajax:failed'); $(this).css('color', 'red'); }); }); }