UserScript: PhantomP2P ED2K Multi-Download

Having a problem with the site? Got a good idea/suggestion? Come and tell us.

Moderator: Admins

Post Reply
User avatar
Atheo
Spectre
Spectre
Posts: 175
Joined: September 15th 2011 - 3:06 am
Been thanked: 1 time

UserScript: PhantomP2P ED2K Multi-Download

Post by Atheo » September 8th 2014 - 8:45 pm

This UserScript adds Multi-Download capabilities to pages with ED2K links. You can now easily select which links you want to download and click on a new button called "Get Selected". There is also a button "Select All/None" which allow you to select all links or remove all selections. The buttons are for the Dark Theme, so they might not fit in perfectly with other themes, but they are easily implemented if there is a demand.

Image

Code: Select all

// ==UserScript==
// @name        PhantomP2P ED2K Multi-Download
// @namespace   phantomp2p
// @description Select the files you want to download
// @include     http://phantomp2p.com/forum/*
// @version     1
// @grant       none
// ==/UserScript==

// ==UserScript==
// @name        PhantomP2P Magnet Multi-Download
// @namespace   phantomp2p
// @description Enable multi-download for magnet links with on-site JavaScript activated
// @include     http://phantomp2p.com/forum/*
// @version     1
// @grant       none
// ==/UserScript==

var posts = document.getElementsByClassName('content');
var ed2k_count=0;

for(var i=0; i < (posts.length-1); i++) {

    var atags = posts[i].getElementsByTagName('a');

    for(var ii = 0; ii < atags.length; ii++) {
    
        if(atags[ii].getAttribute('href')==null) { continue; }
          
        if(atags[ii].getAttribute('href').substr(0,7) == 'ed2k://') {
        
            ed2k_count++;
            
            var el_span = document.createElement('span');
            var el_input = document.createElement('input');
    		el_input.setAttribute('type', 'checkbox');
            el_input.setAttribute('class', 'ed2kcheck');
        
            var el_img = atags[ii].previousSibling;
        
            // Gecko white-space workaround
            if (el_img.tagName != "img") {
                el_img = el_img.previousSibling;
            }
        
            atags[ii].parentNode.insertBefore(el_span, el_img);
            el_span.appendChild(atags[ii].parentNode.removeChild(el_img));
            el_span.appendChild(el_input);
            el_span.appendChild(atags[ii].parentNode.removeChild(atags[ii]));
    	}
    }
}

function toggle_select()
{
    var checkboxes = document.getElementsByClassName('ed2kcheck');
    var selected = false;
    for(var i=0; i < checkboxes.length; i++) {
       if(checkboxes[i].checked) {
           selected = true;
           break;
       }
    }
    if(selected) {
            for(var i=0; i < checkboxes.length; i++) {
                checkboxes[i].checked = false;
            }
    } else {
            for(var i=0; i < checkboxes.length; i++) {
                checkboxes[i].checked = true;
            }        
    }
}

var checkboxes;
var selected;
var n=0;
var iv=false;

function add_file()
{
    n++;
    if(n==selected.length && iv) {
        top.clearInterval(iv);
        n=0;
    }
    
    top.document.location = checkboxes[selected[n]].parentNode.getElementsByTagName('a')[0].getAttribute('href');
    
    return;
}

function get_selected()
{
    checkboxes = document.getElementsByClassName('ed2kcheck');
    selected = new Array;
    for(var i=0; i < checkboxes.length; i++) {
       if(checkboxes[i].checked) {
           selected.push(i);
       }
    }
    if(selected.length > 0) {
       iv = top.setInterval(add_file, 250);
    }
}

if(ed2k_count>1) {

    var btnstyle = document.createElement('style');
    btnstyle.innerHTML = '.getselected-icon span {\n' +
		                 '\tbackground: transparent none 0 0 no-repeat;\n' +
		                 '}\n' +
                         '.buttons div.getselected-icon {\n' +
                         '\twidth: 96px; height: 25px;\n' +
                         '}\n' +
                         '.getselected-icon span {\n' +
                         '\tbackground-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAyCAYAAACj3t7EAAAHD0lEQVR42u2aa1BU5xnHf+fsFQQWWHYRY5BUkAByqSBKVJxMTRpt2iaxNTGTTi9pbo1pP9S0qdQp7TgZq7Hjl2qSMdNJ7cQ2TatJp9VEWmuioSoxGAgg3ijI/bbLddmF8/YDSLI7cNhdDSdJz/NlZ3ef93/+8/7P/zzv+5xX+sYLxwR6aBZGIQQ1rW59JjSIzCQbshC6AbQKIQSyougCaCaAIpCFUPSZ0CgUoegO0FQA3QFa1wAFWVF0AbRzwOdMgJrSez5T11YUBWM4AhQssPPE6nSyb4rDKEvUtrr53bsXKatrDYpoZumhaf+fHxvJ5juzyE+2E2UxUtXsYt/Jet6+0DErk6jG7ZNwQMgCFKbY2bG+gJ1vVvP0axX0j/jITIrle7el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vnmyHhUiTzPnuEf5U6+ZUq2dWJlGN2ydRA0IWINdpYUuRgxcqe3j23U4GvYLUeDMbMmxBCTBT/GKlkxNNg+w+08WQT5CRYOH+DNusCKBFEQ5ZgO9kx7LnbA/Hm4Ymf6vt9vLLEx+dFYoxS2xelkCu00r74CjPne6ivsc3adNrn1PdbUlzjBy9Mkifd7w2VXWOUNXZMSN2YKjl2a0yP1mewGKHFYtRZs2Bhim5qWEkRhrYusJBss3E6/X94a+CQhUgLc7M2Tb1O/3JfDvvNA2x/q9NvFjZy48LE/wmfM2Bhmmt/nK1i713JbGt2MljeXHkOS1BYQfLAeCpAjuXXD7u/UujH6dAbmoYT+bHU9E2zP0HmxDX7QA5tIFimuJzjXjBXCtfSonip0UOILSDWQfr+ym7MsBih4UUm5lN+XbKm4d46QNXSNhqeblOKztPXcU7Ay01jByHle3lXQyPwR9r3DyYFRuuAGMhDbrY6yUv0cqJq8N+kx64CthwsJEeT3grrH6foLzFQ3mLh79f6uf3d8+fFCAU7OvhcCMxphdgLPRH0B8+dLMpP57imyOJNksYJUiJMfrlnGkd5tG8OGLMEgkRMj8r+si6A94xEiMN0+JvK3aQ7bBgkiDSKHHXF6LpGBoNCjtYDpUdHjZm2jAFOD+QmxrGB50eNmTEYDXAA5m2sPcB0lf3nRJDkc6QBhbMtfJQlo3UODMCON/jZX+1i3Md40f4okwST+XbWTrPyoBXYd85F29PFO1vZdlYf2sMUWbDlHWgMMnKAxk20u0WPKMK53u8PP9+D419ozNif3wZqZZnt8o8U+RgscOCySBPjgnkpoYRWIQ3ZsWGvISNHOpE+sqL/xGeqER9W6pBWAfa9XfCmjfjdAG0FkBvR2sngFD0FzJaxvi5IN0BugP+nx1gFEIw1n5Znw2N4n+aY0PPs5PaaQAAAABJRU5ErkJggg==");\n' +
                         '}\n' +
                         '.toggleselect-icon span {\n' +
                         '\tbackground: transparent none 0 0 no-repeat;\n' +
                         '}\n' +
                         '.buttons div.toggleselect-icon {\n' +
                         '\twidth: 96px; height: 25px;\n' +
                         '}\n' +
                         '.toggleselect-icon span {\n' +
                         '\tbackground-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAyCAYAAACj3t7EAAAIr0lEQVR42u2be1BU1x3HP3tZ2OUhz2WRVRAf+EARIr5BWhWMWHwlBsfOdBpr0jZGk3a0adQmYTrGRButzcSktqapOo1OohVxFBXUTmhq8QkoiBhEWeX9lvfj3v6Bri7sLruZ1mvj/f1zZ8/53d895/c939/5nceqluw8I6GIbKKWJIn8sgbFEzJIWKAXgiQpBJBLJElCEEUFANkAECUESRIVT8gkoiQqDJAVAIUBcs8BIoIo/vcByE9eJFunHv22nO2wjwE2ABjs7cb2pElkrp3L5Q2J7HkxhthQ/WN3ojWZEqIjP3kR04b52213nMGb1JWzTN/YnjRJ1oFjE4DtSZMoKG9g/o5TTH7vKB+evsayScOemNGzICKIwooGFkYE2f3Os2EGTuaXmn6PNXgTbvCWlQFqqwzwcedwdgn1rZ0AXCip4cLnNaZ6b1dnNi6cwOQQP+7Wt/JW6mWultb3sWNLTz9Aw6ZFE4gK9kPjrCYsOcU0Ch88w5JT+tjUqAVmjhrIj/6Syd9WxKJVC7R19R9K48MMrN6fZfq940wBa+LH8uLur/voBnpqeW9xFGEGb/JK61l36CLljW2mtv3hVD7Lp4+guaOL5CPZZH5T6ZBf+mXAjn8UcODnM/nkh1P51ZyxTAnRmdWvTxjPyfxSoreksTU9j98uiLRox5beb+ZFUFDeyNTNx0yOfvRpyfkAcaMDuWyspai6iUslNcSPMfTr/NEDPRFFiRuV90xlh3NK8HZzIXZE39C6YV4El421fH/rcXLv1LE+YbxZvbOTwMxtx9l84irr5oY77JdeDBD6VO7NuklqjpEJwb6E6j3ZMG88p6+Xsf3UNQCih+tJHB/E+89FAdBtBUhbepNCdGxIuUR7l2OJwMLIYA5eug1Aao6R5ycM4ciVO/2En0GceCT8AEio2JaRxy/jxpL5TYVZXdQQP948dJGWjm52/bOQE6/Hm9XvzLxOZ7dEen4pW5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v1vPJ3EA2xur5WaQPkXpzqr8a5UemsYXn/27kT9l1rJmss2jHlt7qiX4U1Xey+GCJydGPPi05HyAmyI28qnZKGru4Wt1GTJBbv84f7u1MtwTFDV2mspPFTXi6CEy2EFpXTfQlv7qdpSlGrtW082qUn/kWgqBi6WEjf7xcx8ooX4f9Ys4AC2fChwrvkVHcxDh/DSFeLqyK8uPs3RY+ze052J44UMvsEA9+Pa0njlq7gGRLL0Kv5XdZd+hwMBGLD/Eg7WYTAOnFzSQM9+DU7Rbb4SfYnUxjS5+NsU9z6ngpwodzZea3JsL9tbx/tprWbth/rYG98weZ1X+e10CnBJnGZjZM19nVX4cAALjXKXG2tI2zpW0cLbrHnsTBJgAAkg6VUNvWv/fs1bNHfDQCzwRomWR4OOq7RRFfrWDzGzMGu7HxX1V9yrPK2kgaIzInxLGbIZ33k0cJlfnFLAf6ez8EdVus3BjrT7i/BmcVuKlVzB02gMqWh/Q9X9bKTyN98HRRoXMVWDfNMtVs6WVXtrEszAvnXgOgqaObADcni/Zmh7iTfqvZFKLi9t0i7WYTs4a4W+3oUC81TgIU1VuOxX/OruPH4ea3pK9UtZE0xhOtEywd40VupX03++z1Sw8A3dbngNQb91ge7k3KkmD2zh9EZIDWbAR9dLEWFSr+mjiIbbMH8vUdyyHAlt5HF2oY5ashdUmwWQp4sKCRnQkGi2lh/FAPThY3maePxU02s6HYIEvh56EU1HZwvbbDvN0Xahnnr+WLxUGE+WnYcdG+m3H2+uXBOkA1f1eW1OL2eP54IZfsSjCwJavKajYil7i1VKF+Gq6lvJRW+uTuBSlnwgoATzkAyna0fABIonIgI6f03AtSGKAw4GlmgFqSJLorbirekEn+A2kzbk6bXI7vAAAAAElFTkSuQmCC");\n' +
                         '}';
    document.head.appendChild(btnstyle);
    
    var btn_bar = document.getElementsByClassName('buttons');

    var selectbtn_top = document.createElement('div');
    selectbtn_top.setAttribute('class', 'toggleselect-icon');
    selectbtn_top.innerHTML = '<a href="javascript:toggle_select()" title="Toggle Select"><span></span>Toggle Select</a>';
    btn_bar[0].appendChild(selectbtn_top);
    selectbtn_top.addEventListener('click', toggle_select, false);

    var selectbtn_bottom = document.createElement('div');
    selectbtn_bottom.setAttribute('class', 'toggleselect-icon');
    selectbtn_bottom.innerHTML = '<a href="javascript:toggle_select()" title="Toggle Select"><span></span>Toggle Select</a>';
    btn_bar[1].appendChild(selectbtn_bottom);
    selectbtn_bottom.addEventListener('click', toggle_select, false);

    var downloadbtn_top = document.createElement('div');
    downloadbtn_top.setAttribute('class', 'getselected-icon');
    downloadbtn_top.innerHTML = '<a href="javascript:get_selected()" title="Get Selected"><span></span>Get Selected</a>';
    btn_bar[0].appendChild(downloadbtn_top);
    downloadbtn_top.addEventListener('click', get_selected, false);

    var downloadbtn_bottom = document.createElement('div');
    downloadbtn_bottom.setAttribute('class', 'getselected-icon');
    downloadbtn_bottom.innerHTML = '<a href="javascript:get_selected()" title="Get Selected"><span></span>Get Selected</a>';
    btn_bar[1].appendChild(downloadbtn_bottom);
    downloadbtn_bottom.addEventListener('click', get_selected, false);
}
Installation
This UserScript is usable by (at least) the GreaseMonkey extension for Firefox.

You can get the GreaseMonkey extension here:
http://addons.mozilla.org/firefox/addon/greasemonkey/

To install a UserScript, you first need to have it in a file. That file needs to be named like this name.user.js where "name" is of your choosing. The file just needs to end with .user.js

When you have copied the UserScript to you favourite plaintext editor and saved it to a file that ends with .user.js you just have to open the file with Firefox and follow the instructions.

Windows
I recommend using Notepad to be sure there is no formatting involved. When saving the file, add quotes around the name to prevent adding the .txt extension to the filename. If you name the file myname.user.js without quotes it will end up being named myname.user.js.txt, if you save it as "myname.user.js" with quotes it will end up being named correctly as myname.user.js

Post Reply

Return to “Site Requests / Problems / Suggestions”