Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/*
libTBWL.js
* Project: Toolbar Watchlist, Version: 0.1.1beta, Date: 2007-08-27
* Copyright (C) 2007 [[de:User:Revolus]] (revolus@web.de)
* http://www.gnu.org/copyleft/gpl.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE.
* See the GNU General Public License for more details.
Licence:
You may redistribute this script either under the terms of the GNU GPL
or GNU FDL with no invariant sections. But either way, you have to
accept the non-warranty clause as stated in the GNU GPL.
Vars:
vTBWL_Addons
Funcs:
TBWL_LinkTitle
TBWL_UserTitle
TBWL_CommentTitle
TBWL_Cookie
TBWL_CreateElement
TBWL_StructureToHMTL
TBWL_CallArrayFunctions
TBWL_Initialize
TBWL_RegisterAddon
*/
var vTBWL_Addons = [];
var TBWL_LinkTitle = function(ns, title) {
return title;
};
var TBWL_UserTitle = function(name) {
return name;
};
var TBWL_WikiEncodeURI = function(str) {
var elm = /([\x23|\x24|\x26|\x2B|\x2C|\x2F|\x3A|\x3B|\x3D|\x3F|\x40])/g;
var callback = function(a, b) {
var res = b.charCodeAt(0).toString(16).toUpperCase();
if(res.length<2) res = "0"+res;
return "%"+res;
};
return encodeURI(str).replace(elm, callback).replace(/\x22/g, "%22").replace(/\\/g, "%5C");
};
var TBWL_WikiEncodeAnchor = function(str) {
var elm = /([\x23|\x24|\x26|\x2B|\x2C|\x2F|\x3B|\x3D|\x3F|\x40])/g;
var callback = function(a, b) {
var res = b.charCodeAt(0).toString(16).toUpperCase();
if(res.length<2) res = "0"+res;
return "%"+res;
};
return encodeURI(str).replace(elm, callback).replace(/\x22/g, "%22").replace(/\\/g, "%5C");
};
var TBWL_CommentTitle = function(depth, res, str, ns, title) {
var doLink = function(text) {
if(!text) return;
var pattern = /^([^\x23\x7c]*)\x23?([^\x7c]*)\x7c?(.*)$/;
var callback = function(a, Link, Abs, Text) {
if(Abs === "") {
if(Text === "") Text = Link; // Text
res.push(depth, ["WPLink", "", "", Link, Text, "", "", ""],
depth+1, ["SetAttribute", "title", Link]); // Link|Text
}
else {
if(Text === "") Text = Link+"#"+Abs; // Link#Abs
res.push(depth, ["WPLink", "", "", Link, Text, "", "", Abs],
depth+1, ["SetAttribute", "title", Link+"#"+Abs]); // Link#Abs|Text
};
};
text.replace(pattern, callback);
};
var doText = function(text) {
if(!text) return;
var pattern = /(.*?)\[\[(.*?)\]\]/g;
var callback = function(a, Text, Link) {
res.push(depth, ["Text", Text, ""]);
doLink(Link);
};
(text+"[[]]").replace(pattern, callback);
};
var doSection = function(text) {
if(!text) return;
var pattern = /\[\[\.*?|(.*?)\]\]|\[\[(.*?)\]\]/g;
text = text.replace(pattern, "\1");
res.push(
depth, ["Node", "span", "TBWL_SectionLink"],
depth+1, ["Text", " /* ", ""],
depth+1, ["WPLink", "", "", title, text, "", "", text],
depth+2, ["SetAttribute", "title", title+"#"+text],
depth+1, ["Text", " */ ", ""]);
};
var pattern = /(.*?)\/\* ?(.*?) ?\*\//g;
var callback = function(a, Text, Section) {
doText(Text);
doSection(Section);
};
(str+"/**/").replace(pattern, callback);
};
var TBWL_GetAjaxObject = function() {
var res;
if((typeof(XMLHttpRequest) == "function") && (res = new XMLHttpRequest())) return res;
if(typeof(ActiveXObject) == "function") {
var MsAjax = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for(var i=0; i<MsAjax.length; i++) {
try { if(res = new ActiveXObject(MsAjax[i])) return res; }
catch(e) {};
};
};
return false;
};
var TBWL_Cookie = {
"Read": (function(name) {
var arr = document.cookie.split(';');
for(var i=0; i<arr.length; i++) {
var b = true;
var c;
var aName = [];
var aText = arr[i].split('');
var cName = name.split('');
while((c = aText.shift()) === ' ') {};
do {
aName.push(c)
if(c !== cName.shift()) { b = false; break; };
} while('=' !== (c = aText.shift()));
if(b && (cName.length==0))
return aText.join("");
};
return false;
}),
"Write": (function(name, value, expires) {
var expires = new Date((new Date()).getTime() + expires).toGMTString();
document.cookie = name +"="+ value +"; expires="+ expires +";";
}),
"Delete": (function(name) {
document.cookie = name+ "=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
})
};
var TBWL_CreateElement = {
"generic": (function(/* func, [...] */) {
var a = [];
for(var i=1; i<arguments.length; i++) a.push(arguments[i]);
var res = TBWL_CreateElement[arguments[0]].apply(this, a);
if(typeof(res) == "object") this.appendChild(res);
return res;
}),
"Node": (function(tag, className) {
var res = document.createElement(tag);
res.className = className;
res.app = TBWL_CreateElement.generic;
return res;
}),
"Text": (function(text, className) {
var res = TBWL_CreateElement.Node("span", className);
res.appendChild((typeof(text) == "string") ?document.createTextNode(text) :text);
return res;
}),
"Space": (function() {
this.appendChild(document.createTextNode(" "));
}),
"Link": (function(text, href, className) {
var res = TBWL_CreateElement.Node("a", "");
res.appendChild((typeof(text) == "string") ?document.createTextNode(text) :text);
res.setAttribute("href", href);
return TBWL_CreateElement.Text(res, className);
}),
"WPLink": (function(server, ns, title, text, data, className, anchor) {
if(server == "") var server = "/w/";
if(ns != "") var title = ns +':'+ title;
var href = "/w/index.php?title=" +TBWL_WikiEncodeURI(title.replace(/ /g, "_"));
if(data != "") href += "&"+data;
if(anchor != "") href += "#" + TBWL_WikiEncodeAnchor(anchor.replace(/ /g, "_")).replace(/%/g, ".");
return TBWL_CreateElement.Link(text, href, className);
}),
"AddClass": (function(className) {
if(className != "") {
var s = this.getAttribute("class");
return(this.className = (s == "" ?"" :s+" ") + className);
};
return className;
}),
"SetAttribute": (function(name, value) {
return this.setAttribute(name, value);
}),
"AddNode": (function(obj) {
if(!obj) { return obj; }
return this.appendChild((typeof(obj)=="string") ?document.createTextNode(obj) :obj);
})
};
var TBWL_StructureToHMTL = function(container, arr) {
if(!arr) return false;
var index = 0;
var e;
var iter = function(container) {
var depth = arr[index];
while(true) {
if(typeof(e = arr[index+1]) == "undefined") return;
var i = arr[index+2];
var elem = e && container && TBWL_CreateElement.generic.apply(container, e);
index += 2;
switch(i - depth) {
case 1: iter(elem);
case 0: continue;
default: return;
};
};
};
iter(container);
return container;
};
var TBWL_CallArrayFunctions = function(/* funcs, [...] */) {
var funcs = arguments[0];
var a = [];
for(var i=1; i<arguments.length; i++) a.push(arguments[i]);
for(var i=0; i<funcs.length; i++) {
var func = (typeof(funcs[i]) == "string") ?eval(funcs[i]) :funcs[i];
func.apply(this, a);
}
};
var TBWL_RegisterAddon = function(friendlyName, scriptName) {
// TODO: Stub
};
var TBWL_Initialize = function() {
TBWL_CallArrayFunctions(vTBWL_Addons);
};
$(function() {
TBWL_Initialize();
});
TBWL_RegisterAddon("library", "libTBWL");