-1

I'm trying to modify this bookmarklet (from pyLoad, a download manager) so that I can change the title of the download package instead of using the same one every time. I know that's possible to add a pop-up to a bookmarklet but I really don't know how to use it to modify this request.

Here's the code

javascript:function filtreAuto(){var e=[];e["aucun"]="aucun";e["A_Site"]="http://A_site.com/";return e}function bookmarklet(){var e=document.createElement("div");url=filterUrl();e.innerHTML='<h1>URL</h1><input type="checkbox" name="checkboxUrl" id="'+url+'" value="checkbox0"><label for="checkbox0"><a href="'+url+'">'+url+"</a></label><br />";var t=document.createElement("div");var n=document.createElement("h2");n.setAttribute("id","Filtrer les liens par mots clé:");t.appendChild(n);var r=document.createElement("input");r.setAttribute("id","searchInput");r.setAttribute("name","searchInput");r.setAttribute("type","text");r.setAttribute("placeholder","Filtre personnaliser...");t.appendChild(r);t.innerHTML=t.innerHTML+" ou Filtre Auto: ";var i=document.createElement("select");i.setAttribute("id","searchAuto");i.onchange=function(){win.document.getElementById("searchInput").value=""};filtre=filtreAuto();for(var s in filtre){var o=document.createElement("option");o.value=filtre[s];o.text=s;i.appendChild(o)}t.appendChild(i);var u=document.createElement("button");u.onclick=function(){findLinks()};u.innerHTML="search";t.appendChild(u);var a=document.createElement("button");a.setAttribute("id","cocher");a.onclick=function(){linksCheck()};a.innerHTML="Tout cocher";t.appendChild(a);var f=document.createElement("button");f.setAttribute("id","pyLoad");f.onclick=function(){toPyload()};f.innerHTML="Envoi à pyLoad";t.appendChild(f);var l=document.createElement("div");l.setAttribute("id","divList");win.document.body.appendChild(e);win.document.body.appendChild(t);win.document.body.appendChild(l);findLinks()}function linksCheck(){var e=win.document.getElementById("cocher");e.innerHTML=="Tout cocher"?e.innerHTML="Tout décocher":e.innerHTML="Tout cocher";var t=win.document.getElementById("conteneur").firstChild;while(t!=null){if(t.getAttribute("type")=="checkbox"){test=e.innerHTML=="Tout cocher"?false:true;win.document.getElementsByName("checkboxUrl")[0].checked=test;win.document.getElementById(t.getAttribute("id")).checked=test}t=t.nextSibling}return false}function filterUrl(){url=winx.document.URL;if(url.lastIndexOf("youtube")!=-1){g=new RegExp("v=.{11}");idVideo=g.exec(url);urlYoutube="http://www.youtube.com/watch?"+idVideo;url=urlYoutube}return url}function findLinks(){win.document.getElementById("cocher").innerHTML="Tout cocher";var e=win.document.getElementById("searchAuto").value;var t=win.document.getElementById("searchInput").value;title="<h2>Tous les liens "+t+":</h2>";if(!t){if(e=="aucun"){t="";title="<h2>Pas de filtre:</h2>"}else{t=e;title="<h2>Filtre des liens :"+t+"</h2>"}}else{win.document.getElementById("searchAuto").value="aucun"}texte=title+'<div id="conteneur">';for(var n=0;n<list_Links.length;n++){list_Links[n].lastIndexOf(t)!=-1?texte+='<input type="checkbox" name="checkbox'+n+'" id="'+list_Links[n]+'" value="checkbox'+n+'"><label for="checkbox'+n+'"><a href="'+list_Links[n]+'">'+list_Links[n]+"</a></label><br />":""}var r=win.document.getElementById("divList");r.innerHTML=texte+"</div>"}function createListLinks(){list_Links=[];for(var e=winx.document.links.length-1,t;t=winx.document.links[e];e--){if(!t.href.match(/^(javascript:|data:)/)){lien=t.href;list_Links.push(lien)}}return list_Links}function toPyload(){list_Pyload=[];var e=win.document.getElementsByName("checkboxUrl")[0];e.checked?list_Pyload.push(e.id):"";var t=win.document.getElementById("conteneur").firstChild;while(t!=null){if(t.getAttribute("type")=="checkbox"){t.checked?list_Pyload.push(t.getAttribute("id")):""}t=t.nextSibling}if(list_Pyload==""){return false}jLinks=JSON.stringify(list_Pyload);urlx='http://localhost:8000/api/addPackage?name="download"&links='+jLinks;winz=window.open(urlx,"","resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no");setTimeout("winz.close()",50);win.close()}winx=window;win=window.open("","_blank","width=800,height=600,scrollbars,resizable,menubar");list_Links=createListLinks();bookmarklet()

As you can see this is the string that sends the URL to pyLoad

urlx='http://localhost:8000/api/addPackage?name="download"&links=

What I'm trying to do is to add a pop-up action so I can change every time the addPackage name but I don't know how (and if) is it possible to add this request with a Javascript so that I can use it from a browser.

EDIT: I found this

javascript:
(function() { 
    var val= prompt("Enter #",""); 
    if (val) 
        location="http://www.test.com/"+escape(val)+"/html/stuff";
})()

but how to insert a javascript bookmarklet instead of a simple URL?

DylanDog
  • 109
  • 8
  • You could add a prompt box to specify the folder you want to add instead of 'addPackage'. Then simply pass this value into the urlx instead of addPackage. – The Gav Lad Sep 30 '16 at 15:11
  • Sorry for the late reply, but I didn't see the mail notification; may you help me with some simple example? – DylanDog Oct 10 '16 at 18:41

1 Answers1

1

What you found is pretty much what you need from your initial request. You just need to update the if statement to push the input value to the bookmarklet function where it can then alter the URL as required:

(function() { 
    var val= prompt("Enter #",""); 
    if (val) 
        bookmarklet(val);
})()

Then you should update the bookmarklet code to display this value:

urlx = 'http://localhost:8000/api/'+val+'?name="download"&links=' + jLinks;

Note: remember to remove the other call to bookmarklet() in the code.

The Gav Lad
  • 280
  • 3
  • 9