Benutzer:Magnus Manske/beacon.js
Zur Navigation springen
Zur Suche springen
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
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
/**
* Only returns true when the external script has been loaded in to the DOM.
* @license: CC-SA 3.0
* @author Remy Sharp / leftlogic.com
*/
function waitingForScript(url, obj) {
// doesn't work in Opera
var callback = arguments.callee.caller;
var args = arguments.callee.caller.arguments;
var s, ok, timer, doc = document;
// if the object/function doesn't exist and we've not tried to load it
// then pull it in and fire the calling function once complete
if ((typeof window[obj] == 'undefined') && !window['loading' + obj]) {
window['loading' + obj] = true;
if (!doc.getElementById('_' + obj)) {
s = doc.createElement('script');
s.src = url;
s.id = '_' + obj;
doc.body.appendChild(s);
}
timer = setInterval(function () {
ok = false;
try {
ok = (typeof window[obj] != 'undefined');
} catch (e) {}
if (ok) {
clearInterval(timer);
callback.apply(this);
}
}, 10);
// we're loading in the script now, so we're currently waiting
return true;
} else if (typeof window[obj] == 'undefined') {
// object not defined yet, so we're still waiting
return true;
} else {
// it's already loaded
return false;
}
}
function run_beacon_script () {
if ( wgAction != 'view' ) return ;
if (waitingForScript(wgServer+'/skins-1.5/common/jquery.min.js', 'jQuery')) return;
jQuery(document).ready ( function () {
var key = "http://toolserver.org/~apper/pd/person/pnd/" ;
var apper_redir = "http://toolserver.org/~apper/pd/person/pnd-redirect/de/" ;
jQuery("a").each ( function () {
var url = jQuery(this).attr('href') ;
if (url === undefined) return ;
if ( url.substr ( 0 , key.length ) != key ) return ;
var pnd = url.substr ( key.length ) ;
var seen = 0 ;
jQuery(this).parents('li').each ( function () {
if ( seen == 1 ) return ;
seen = 1 ;
var obj = jQuery(this) ;
jQuery.getJSON ( "http://beacon.findbuch.de/seealso/pnd-aks?format=seealso&id="+pnd+"&callback=?" , function ( data ) {
var base_url = data[0] ;
var names = data[1] ;
var unknown = data[2] ;
var urls = data[3] ;
if ( names.length == 0 ) return ;
var html = "<div class='pnd_aks_box'><span style='background:#EEEEEE'><a href='#' class='pnd_aks_toggle'>Details anzeigen/verbergen</a></span><ul>" ;
jQuery.each ( names , function ( k , v ) {
if ( urls[k].substr ( 0 , apper_redir.length ) == apper_redir ) return ; // Apper redirect to wikipedia
html += "<li><a rel='nofollow' class='external text' href=\"" + urls[k] + "\">" + v + "</a></li>" ;
} ) ;
obj.append ( html + "</ul></div>" ) ;
obj.find(".pnd_aks_toggle").click ( function () {
jQuery(this).parents("div:eq(0)").find('ul').toggle();
return false
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
}
addOnloadHook ( run_beacon_script ) ;