-
Notifications
You must be signed in to change notification settings - Fork 4
/
pyload_bookmarklet.min.js
2 lines (2 loc) · 8.35 KB
/
pyload_bookmarklet.min.js
1
2
javascript:"use strict";(function(A,B,C,u){function D(){for(var c=[],d={},b=0;b<m.document.links.length;b++){var a=m.document.links[b];a.href.match(/^(?:mailto:|javascript:|data:)/)||d[a.href]||(d[a.href]=!0,c.push({href:a.href,name:a.text.replace(/(<([^>]+)>)/ig,"").trim()}))}return c}function x(){var c=e.document.getElementById("searchInput").value;if(c)var d="<h4>Filtered links: ""+c+""</h4>";else c="",d="<h4>Links:</h4>";c=c.toLocaleLowerCase();d+='<div id="container" class="form-group form-check"><input type="checkbox" id="checkall" class="form-check-input"><label for="checkall">All</label><div class="form-check">';for(var b=0;b<k.length;b++)if(-1!==k[b].href.toLocaleLowerCase().indexOf(c)||-1!==k[b].name.toLocaleLowerCase().indexOf(c))d+='<div class="form-check"><input class="form-check-input" type="checkbox"'+(n[b]?" checked":"")+' id="link'+b+'"><label class="form-check-label small" for="link'+b+'">'+(k[b].name?'<span class="badge badge-warning">'+k[b].name+"</span> ":"")+'<a href="'+k[b].href+'">'+k[b].href+"</a></label></div>";d+="</div></div>";e.document.getElementById("divLinks").innerHTML=d}function v(c,d){var b=e.document.getElementById("link"+c);b&&(b.checked=d);p+=(n[c]===d?0:1)*(d?1:-1);n[c]=d;b=e.document.getElementById("checkall");b.checked=0<p;b.indeterminate=0<p&&p<n.length}function w(){var c=0===p&&!e.document.getElementById("checkurl").checked;e.document.getElementById("toClipboard").disabled=c;e.document.getElementById("toPyload").disabled=c||0===e.document.getElementById("packagename").value.length}function E(){var c,d=[],b=e.document.getElementById("packagename").value,a=e.document.getElementById("serveraddr").value;e.document.getElementById("checkurl").checked&&d.push(r);for(var f=0;f<n.length;f++)n[f]&&d.push(k[f].href);1===u?c=y(a+"/flash/add",{"package":b,urls:encodeURIComponent(d.join("\n"))}):2===u?c=window.open(a+'/api/addPackage?name="'+b+'"&links='+encodeURIComponent(JSON.stringify(d)),"","resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no"):3===u&&(c=y(a+"/api/addPackage",{name:JSON.stringify(b),links:JSON.stringify(d),u:B,p:C}));setTimeout(function(){c.close()},1E3);e.close()}function y(c,d){var b=document.createElement("form");b.style.display="none";b.target="_Pyload";b.method="POST";b.action=c;for(var a in d)if(d.hasOwnProperty(a)){var f=document.createElement("input");f.type="text";f.name=a;f.value=d[a];b.appendChild(f)}e.document.body.appendChild(b);f=e.open("","_Pyload","resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no");b.submit();return f}var m=window;var e=window.open("","_blank","width="+screen.availWidth+",height="+screen.availHeight+",scrollbars,resizable,menubar");e.moveTo(0,0);var k=function(){var c=[],d={},b=(m.getSelection?m.getSelection():m.document.getSelection?m.document.getSelection():m.document.selection?m.document.selection.createRange().text:"").toString();if(""!==b){b=b.match(/(?:ht|f)tp(?:s?):\/\/[a-zA-Z0-9-./?=_&%#:]+(?:[< "'\r\n\t]|$)/ig)||[];for(var a=0;a<b.length;a++){var f=b[a].replace(/[< "'\r\n\t]/g,"");d[f]||(d[f]=!0,c.push({href:f,name:""}))}}return c}();k.length||(k=D());var n=Array.apply(null,Array(k.length)).map(Boolean.prototype.valueOf,!1);var p=0;var F=function(){var c=[],d=document.createElement("a");k.forEach(function(b){d.href=b.href;b=d.hostname.match(/[^.]+\.(?:\w{3,}|\w{2,3}\.\w{2})$/);null!==b&&0>c.indexOf(b[0].toLowerCase())&&c.push(b[0].toLowerCase())});return c}();var r=m.document.URL;(function(){var c=document.createElement("link");c.setAttribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css");c.setAttribute("rel","stylesheet");e.document.head.appendChild(c);c=document.createElement("div");var d=document.createElement("div");d.innerHTML="<h4>Package Name:</h4>";var b=document.createElement("div");b.setAttribute("class","input-group");var a=document.createElement("input");a.setAttribute("id","packagename");a.setAttribute("type","text");a.setAttribute("size","70");a.setAttribute("class","form-control form-control-sm");a.setAttribute("value",m.document.title);a.setAttribute("placeholder","Package Name");a.oninput=function(){w()};b.appendChild(a);var f=document.createElement("div");f.setAttribute("class","input-group-append");a=document.createElement("button");a.setAttribute("id","toPyload");a.setAttribute("disabled","");a.setAttribute("class","btn btn-primary btn-sm");a.setAttribute("style","margin-left: 5px; border-radius: .25rem;");a.innerHTML="Send to pyLoad";a.onclick=function(){E()};f.appendChild(a);a=document.createElement("button");a.setAttribute("id","toClipboard");a.setAttribute("disabled","");a.setAttribute("class","btn btn-secondary btn-sm");a.setAttribute("style","margin-left: 5px; border-radius: .25rem;");a.innerHTML="📋";a.setAttribute("title","Copy links to clipboard");a.onclick=function(){for(var g=e.document.getElementById("checkurl").checked?[r]:[],h=0;h<n.length;h++)n[h]&&g.push(k[h].href);h=document.createElement("textarea");h.style.fontSize="12pt";h.style.border="0";h.style.padding="0";h.style.margin="0";h.style.position="absolute";h.style.left="-9999px";h.style.top=(e.pageYOffset||e.document.documentElement.scrollTop)+"px";h.setAttribute("readonly","");h.value=g.join("\n");e.document.body.appendChild(h);h.select();try{var q=e.document.execCommand("copy");e.alert("Copy "+(q?"successful":"unsuccessful"))}catch(t){e.alert("Oops, unable to copy"+t)}e.document.body.removeChild(h)};f.appendChild(a);a=document.createElement("button");a.setAttribute("id","configtoggle");a.setAttribute("class","btn btn-secondary btn-sm");a.setAttribute("style","margin-left: 5px; border-radius: .25rem;");a.innerHTML="⚙";a.onclick=function(){var g=e.document.getElementById("config");g.style.display="block"===g.style.display?"none":"block"};f.appendChild(a);b.appendChild(f);d.appendChild(b);c.appendChild(d);a=document.createElement("fieldset");a.setAttribute("id","config");a.style.display="none";d=(d="undefined"!==typeof e.Storage?e.localStorage.getItem("pyloadServer"):"")||A;a.innerHTML="<h5>Configuration</h5><label for='serveraddr'>pyLoad's address:</label><div class='input-group'><input type='text' class='form-control form-control-sm' id='serveraddr' placeholder='scheme://address:port' value='"+d+"' /><div class='input-group-append'><button id='save-config' class='btn btn-danger btn-sm'>Save</button></div></div>";a.querySelector("#save-config").onclick=function(g){g=e.document.getElementById("serveraddr").value;0<g.length&&(e.localStorage.setItem("pyloadServer",g),e.alert('Saved for domain "'+window.top.location.hostname+'"'))};c.appendChild(a);d=document.createElement("div");d.innerHTML='<hr style="color:lightgrey;"><h4>Page URL:</h4><div class="form-group form-check text-nowrap"><input type="checkbox" class="form-check-input" id="checkurl"><label for="checkurl"><a href="'+r+'">'+r+'</a></label></div><hr style="color:lightgrey;">';b=document.createElement("div");b.innerHTML='<fieldset class="form-inline"><input id="searchInput" type="text" class="form-control form-control-sm mr-2" placeholder="Filter links..." style="width: 60%;" /><select id="selectDomain" class="form-control form-control-sm"><option>Or check domain...</option></select></fieldset>';var G=b.querySelector("#selectDomain");F.forEach(function(g){var h=document.createElement("option");h.text=g;h.onclick=function(){var q=[],t=!1;var l=e.document.getElementById("selectDomain").value;if(""!==l){var H=new RegExp("(?://|\\.)"+l.replace(".","\\.")+"(?:[?/]|$)","i");for(l=0;l<k.length;l++){var z=k[l].href.match(/:\/\/[^/?]+(?:[?/]|$)/g);z&&z[0].match(H)&&(q.push(l),!1===n[l]&&(t=!0))}for(l=0;l<q.length;l++)v(q[l],t);w()}};G.appendChild(h)});a=document.createElement("div");a.setAttribute("id","divLinks");f=document.createElement("div");f.setAttribute("class","container-fluid");f.appendChild(c);f.appendChild(d);f.appendChild(b);f.appendChild(a);e.document.body.appendChild(f);e.document.title="Send to pyLoad";e.document.getElementById("searchInput").oninput=function(){x()};e.document.addEventListener("click",function(g){if(g.target&&"checkbox"===g.target.type){if(0===g.target.id.indexOf("link")){var h=parseInt(g.target.id.replace("link",""),10);v(h,g.target.checked)}else if("checkall"===g.target.id)for(h=p<n.length,g.target.checked=h,g.target.indeterminate=!1,g=0;g<k.length;g++)v(g,h);w()}else"A"===g.target.nodeName&&g.preventDefault()});x()})()})
("http://localhost:9666","username","password",1);