Skip to content

Commit

Permalink
Merge pull request #1 from yannouchou/master
Browse files Browse the repository at this point in the history
Bootstrap theme + show link names
  • Loading branch information
GammaC0de committed Apr 1, 2019
2 parents 318af76 + b8bf12e commit b8f843b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 73 deletions.
149 changes: 78 additions & 71 deletions pyload_bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ javascript:
var parentWin, bookmarkletWin, list_Links, list_Domains, list_Checked, numChecked, url;

function getPageLinks() {
var list_Links = [];
for (var e = parentWin.document.links.length - 1, t; t = parentWin.document.links[e]; e--) {
var results = [];
var unique_links = {};
for (var e = 0; e < parentWin.document.links.length; e++) {
t = parentWin.document.links[e];
if (!t.href.match(/^(?:mailto:|javascript:|data:)/)) {
if (list_Links.indexOf(t.href) < 0) {
list_Links.push(t.href);
}
if(!unique_links[t.href]) {
unique_links[t.href] = true;
results.push({href:t.href,name:t.text});
}
}
}
return list_Links;
return results;
}

function getPageDomains() {
var list_Domains = [""];
var list_Domains = [];
for (var e = parentWin.document.links.length - 1, t; t = parentWin.document.links[e]; e--) {
if (!t.href.match(/^(?:mailto:|javascript:|data:)/)) {
var d = t.hostname.match(/[^.]+\.(?:\w{3,}|\w{2,3}\.\w{2})$/);
Expand All @@ -33,58 +36,63 @@ javascript:
var title;
if (!t) {
t = "";
title = "<h2> Links: </h2>";
title = "<h4>Links:</h4>";
} else {
title = "<h2> Filtered links: &quot;" + t + "&quot;</h2>";
title = "<h4>Filtered links: &quot;" + t + "&quot;</h4>";
}
var html = title + '<div id="container"><input type="checkbox" id="checkall"><label for="checkall">All</label><br>';
t = t.toLocaleLowerCase();
var html = title + '<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 n = 0; n < list_Links.length; n++) {
if (list_Links[n].indexOf(t) !== -1) {
html += '<div style="display: inline-block; margin: 0;margin-left: 1em;white-space: nowrap;"><input type="checkbox"' + (list_Checked[n] ? ' checked' : '') + ' id="link' + n + '"><label for="link' + n + '"><a href="' + list_Links[n] + '">' + list_Links[n] + "</a></label></div><br>";
if (list_Links[n].href.toLocaleLowerCase().indexOf(t) !== -1 || list_Links[n].name.toLocaleLowerCase().indexOf(t) !== -1) {
html += '<div class="form-check"><input class="form-check-input" type="checkbox"' + (list_Checked[n] ? ' checked' : '') + ' id="link' + n + '"><label class="form-check-label small" for="link' + n + '"><span class="badge badge-warning">' + list_Links[n].name + '</span>&nbsp;<a href="' + list_Links[n].href + '">' + list_Links[n].href + "</a></label></div>";
}
}
html += "</div></div>";
var r = bookmarkletWin.document.getElementById("divLinks");
r.innerHTML = html + "</div>";
r.innerHTML = html;
}

function bookmarklet() {
var pnd = document.createElement("div");
var z = document.createElement("div");
z.innerHTML = 'Package Name: ';
z.setAttribute("style", "margin:18px 0;white-space:nowrap");
z.innerHTML = '<h4>Package Name:</h4>';
var i = document.createElement("div");
i.setAttribute("class","input-group");
var pnt = document.createElement("input");
pnt.style.display = "inline-block";
pnt.setAttribute("id", "packagename");
pnt.setAttribute("type", "text");
pnt.setAttribute("size", "70");
pnt.setAttribute("class", "form-control form-control-sm");
pnt.setAttribute("value", parentWin.document.title);
pnt.setAttribute("placeholder", "Package Name");
pnt.oninput = function () {
updateButtons();
};
z.appendChild(pnt);
i.appendChild(pnt);
var group = document.createElement("div");
group.setAttribute("class","input-group-append");
var f = document.createElement("button");
f.setAttribute("id", "toPyload");
f.setAttribute("style", "display:inline-block;margin-left: 5px");
f.setAttribute("disabled", "");
f.setAttribute("class", "btn btn-primary btn-sm");
f.innerHTML = "Send to pyLoad";
f.onclick = function () {
toPyload();
};
z.appendChild(f);
group.appendChild(f);
f = document.createElement("button");
f.setAttribute("id", "toClipboard");
f.setAttribute("style", "display:inline-block;margin-left: 5px");
f.setAttribute("disabled", "");
f.setAttribute("class", "btn btn-secondary btn-sm");
f.innerHTML = "&#128203;";
f.setAttribute("title", "Copy links to clipboard");
f.onclick = function () {
toClipboard();
};
z.appendChild(f);
group.appendChild(f);
f = document.createElement("button");
f.setAttribute("id", "configtoggle");
f.setAttribute("style", "display:inline-block;margin-left: 5px");
f.setAttribute("class", "btn btn-secondary btn-sm");
f.innerHTML = "&#9881;";
f.onclick = function () {
var c = bookmarkletWin.document.getElementById("config");
Expand All @@ -94,55 +102,54 @@ javascript:
c.style.display = "block";
}
};
z.appendChild(f);
group.appendChild(f);
i.appendChild(group);
z.appendChild(i);
pnd.appendChild(z);
f = document.createElement("fieldset");
f.setAttribute("id", "config");
f.style.display = "none";
var serveraddr = typeof(bookmarkletWin.Storage) !== "undefined" ? bookmarkletWin.localStorage.getItem("pyloadServer") : "";
serveraddr = serveraddr || defaultAddress;
f.innerHTML = "<legend style='font-weight:bold;'>Configuration</legend>pyLoad's address:<input type='text' id='serveraddr' size='30' style='margin-left: 5px' placeholder='scheme:https://address:port' value='" + serveraddr + "'>";
z = document.createElement("button");
z.innerHTML = "Save";
z.style.cssFloat = "right";
z.onclick = function (ev) {
f.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:https://address:port' value='" + serveraddr + "' /><div class='input-group-append'><button id='save-config' class='btn btn-danger btn-sm'>Save</button></div></div>";
f.querySelector('#save-config').onclick = function (ev) {
var serveraddr = bookmarkletWin.document.getElementById("serveraddr").value;
if (serveraddr.length > 0) {
bookmarkletWin.localStorage.setItem("pyloadServer", serveraddr);
bookmarkletWin.alert('Saved for domain "' + window.top.location.hostname + '"');
}
};
f.append(z);
pnd.appendChild(f);
var e = document.createElement("div");
e.innerHTML = '<br><hr style="color:lightgrey;"><h2>Page URL:</h2><div style="display: inline-block; margin: 0;white-space: nowrap;"><input type="checkbox" id="checkurl"><label for="checkurl"><a href="' + url + '">' + url + '</a></label></div><br><br><hr style="color:lightgrey;">';
e.innerHTML = '<hr style="color:lightgrey;"><h4>Page URL:</h4><div class="form-group form-check"><input type="checkbox" class="form-check-input" id="checkurl"><label for="checkurl"><a href="' + url + '">' + url + '</a></label></div><hr style="color:lightgrey;">';
var t = document.createElement("div");
var n = document.createElement("h2");
n.setAttribute("id", "Filter links by keyword:");
t.appendChild(n);
var r = document.createElement("input");
r.setAttribute("id", "searchInput");
r.setAttribute("type", "text");
r.setAttribute("placeholder", "Filter..");
t.appendChild(r);
t.innerHTML = t.innerHTML + " or Check domain: ";
var i = document.createElement("select");
i.setAttribute("id", "selectDomain");
t.innerHTML = '<fieldset class="form-inline"><input id="searchInput" type="text" class="form-control form-control-sm mr-2" placeholder="Filter..." style="width: 60%;" /><select id="selectDomain" class="form-control form-control-sm"><option>Or check domain...</option></select></fieldset>';
var selectDomain = t.querySelector('#selectDomain');
list_Domains.forEach(function (s) {
var o = document.createElement("option");
o.text = s;
o.onclick = function () {
domainCheck();
};
i.appendChild(o)
selectDomain.appendChild(o)
});
t.appendChild(i);
var l = document.createElement("div");
l.setAttribute("id", "divLinks");
bookmarkletWin.document.body.appendChild(pnd);
bookmarkletWin.document.body.appendChild(e);
bookmarkletWin.document.body.appendChild(t);
bookmarkletWin.document.body.appendChild(l);
var style=document.createElement("link");
style.setAttribute("href","https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css");
style.setAttribute("rel","stylesheet");
var viewport=document.createElement("meta");
viewport.setAttribute("name","viewport");
viewport.setAttribute("content","width=device-width, initial-scale=1");
bookmarkletWin.document.head.appendChild(style);
bookmarkletWin.document.head.appendChild(viewport);
var container = document.createElement("div");
container.setAttribute("class","container");
container.appendChild(pnd);
container.appendChild(e);
container.appendChild(t);
container.appendChild(l);
bookmarkletWin.document.body.appendChild(container);
bookmarkletWin.document.title = "Send to pyLoad";
bookmarkletWin.document.getElementById("searchInput").oninput = function () {
buildLinksDiv();
Expand Down Expand Up @@ -181,7 +188,7 @@ javascript:
if (d !== "") {
var r = new RegExp("(?:https://|\\.)" + d.replace(".", "\\.") + "(?:[?/]|$)", "i");
for (n = 0; n < list_Links.length; n++) {
var l = list_Links[n].match(/:\/\/[^/?]+(?:[?/]|$)/g);
var l = list_Links[n].href.match(/:\/\/[^/?]+(?:[?/]|$)/g);
if (l && l[0].match(r)) {
list_DomainLinkIds.push(n);
if (list_Checked[n] === false)
Expand Down Expand Up @@ -226,30 +233,30 @@ javascript:
}
for (var n = 0; n < list_Checked.length; n++) {
if (list_Checked[n]) {
list_PyLoad.push(list_Links[n]);
list_PyLoad.push(list_Links[n].href);
}
}
if (sendMethod === 1) {
winz = doPost(ps+"/flash/add",{name: pn, urls: list_PyLoad.join("\n")});
} else if (sendMethod === 2) {
winz=window.open(ps+'/api/addPackage?name="'+pn+'"&links='+JSON.stringify(list_PyLoad),
winz=window.open(ps+'/api/addPackage?name="'+pn+'"&links='+encodeURIComponent(JSON.stringify(list_PyLoad)),
"","resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no");
} else if (sendMethod === 3) {
var postParameters = {name: pn, links: JSON.stringify(list_PyLoad)};
winz = doPost(ps+"/api/addPackage",
{name: JSON.stringify(pn), links: JSON.stringify(list_PyLoad),u: username, p: password});
}
setTimeout(function () {
winz.close();
winz.close();
}, 1000);
bookmarkletWin.close();
bookmarkletWin.close();
}

function toClipboard() {
var list_PyLoad = bookmarkletWin.document.getElementById("checkurl").checked ? [url] : [];
for (var n = 0; n < list_Checked.length; n++) {
if (list_Checked[n]) {
list_PyLoad.push(list_Links[n]);
list_PyLoad.push(list_Links[n].href);
}
}
var t = document.createElement('textarea');
Expand All @@ -274,25 +281,25 @@ javascript:
}

function doPost(url, postParameters) {
var winz, i;
var formElement = document.createElement("form");
formElement.style.display = "none";
formElement.target = "_Pyload";
formElement.method = "POST";
formElement.action = url;
for (var n in postParameters) {
if (postParameters.hasOwnProperty(n)) {
i = document.createElement("input");
i.type = "text";
i.name = n;
i.value = postParameters[n];
formElement.appendChild(i);
}
var winz, i;
var formElement = document.createElement("form");
formElement.style.display = "none";
formElement.target = "_Pyload";
formElement.method = "POST";
formElement.action = url;
for (var n in postParameters) {
if (postParameters.hasOwnProperty(n)) {
i = document.createElement("input");
i.type = "text";
i.name = n;
i.value = postParameters[n];
formElement.appendChild(i);
}
bookmarkletWin.document.body.appendChild(formElement);
winz = bookmarkletWin.open("", "_Pyload", "resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no");
formElement.submit();
return winz;
}
bookmarkletWin.document.body.appendChild(formElement);
winz = bookmarkletWin.open("", "_Pyload", "resizable=no, location=no, width=100, height=100, menubar=no, status=no, scrollbars=no, menubar=no");
formElement.submit();
return winz;
}
parentWin = window;
bookmarkletWin = window.open("", "_blank", "width=800,height=600,scrollbars,resizable,menubar");
Expand Down
Loading

0 comments on commit b8f843b

Please sign in to comment.