User:Parkerdr/linkpad.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Parkerdr/linkpad. |
$(function () {
document.getElementById('p-tb').innerHTML +=
'</div></div><br>'+
'<div id=my class=portlet>'+
'<h5>LinkPad</h5>'+
'<div class=pBody><center><span id="spotadd" onDragEnter="stopit()" onDrop="onend()" onDragOver="stopit()" onDblClick="addMe()" title="to add - drag links here or double click to add the current page">[add]</span> <span onDblClick="cleaner()" onDragEnter="stopit()" onDragOver="stopit()" title="to delete - drag links here, dbl click to clear all">[delete]</span></center><ul id="links">'+
'</ul></div>';
var oldlinks = getCookie("linkpadlinks");
var linktable;
if (oldlinks != null) {
links.innerHTML = oldlinks;
var linktable = links.getElementsByTagName('a')
for (var i=0; i<linktable.length; i++)
linktable[i].ondragend = deleter;
}
linktable = document.getElementById('bodyContent').getElementsByTagName('a');
for (var i=0; i<linktable.length; i++)
linktable[i].onclick = clickIt;
})
function stopit() {
var t = event.dataTransfer.getData("URL");
if (t != null) {
window.event.returnValue = false;
} else
window.event.returnValue = true;
}
function onend() {
var t = event.dataTransfer.getData("URL");
if (t != null) {
adder(t)
}
spotadd.bgcolor = "transparent";
}
function addMe() {
adder(window.location.href);
}
function adder(t) {
var li = document.createElement("LI");
var aa = document.createElement("A");
var i = t.indexOf("/wiki/");
var fr;
if (i > -1)
fr = t.substring(i + 6);
else
fr = t;
aa.href = t;
aa.innerText = fr;
aa.className = "linkpad";
aa.ondragend = deleter;
li.appendChild(aa);
links.appendChild(li);
linksRecord();
}
function deleter() {
var target = event.srcElement;
var li = target.parentElement;
if (li.tagName != "LI")
li = li.parentElement;
li.parentElement.removeChild(li);
linksRecord();
}
function linksRecord() {
var val = links.innerHTML;
var expires = new Date();
expires.setDate(expires.getDate()+7);
setCookie("linkpadlinks", val, expires, "/");
}
function cleaner () {
var expires = new Date();
setCookie("linkpadlinks", "", expires, "/");
links.innerHTML = "";
}
function debugit() {
alert(links.innerHTML);
}
// name - name of the cookie
// * return string containing value
// of specified cookie or null if cookie
// does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex +
prefix.length,
cookieEndIndex))
}
function setCookie (sName, vValue)
{
var argv = setCookie.arguments, argc = setCookie.arguments.length;
var sExpDate = (argc > 2) ? "; expires="+argv[2].toGMTString() : "";
var sPath = (argc > 3) ? "; path="+argv[3] : "";
var sDomain = (argc > 4) ? "; domain="+argv[4] : "";
var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
document.cookie = sName + "=" + escape(vValue,0) + sExpDate + sPath + sDomain + sSecure + ";";
}
function clickIt()
{
var e = window.event.srcElement;
if ((e.tagName == "A") && (window.event.altKey)) {
adder(e.href);
window.event.returnValue = false;
window.status = "Link added to linkpad";
}
}