Benutzer:MichaelSchoenitzer/superwatch.js

aus Wikipedia, der freien Enzyklopädie
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
mw.loader.load("//de.wikipedia.org/w/index.php?title=Benutzer:MichaelSchoenitzer/superwatch.css&action=raw&ctype=text/css", "text/css");

/* 
 * Watch one or multiple sites
 *
 * args:
 *  - titles: []string
 *  - typee: string
 */
function watchall(titles, type) {
    var api = new mw.Api();
    api.watch(titles).done( function() { 
        mw.notify("Added " + titles.length +
                  " " + type + " to watchlist",
                  { title: "Superwatch" } );
    });
}

function watchimages(data) {
    titles=[];
    pages = data.query.pages;
    for ( var j in pages ) {
        images = pages[j].images;
        for ( var i in images ) {
            console.log(images[i].title);
            titles = titles.concat(images[i].title);
        }
    }
    if ( titles.length === 0 ) {
        return;
    }
    watchall(titles, "images");
}

function watchpages(data) {
    titles=[];
    pages = data.query.prefixsearch;
    for ( var i in pages ) {
        pagetitle = pages[i].title;
        titles = titles.concat(pagetitle);
    }
    if ( titles.length === 0 ) {
        return;
    }
    watchall(titles, "subpages");
    
    // get images
    c = 0;
    while ( c <= titles.length ) {
        pack = titles.slice(c,c+20);
        c += 20;
        var api = new mw.Api();
        api.get( {
            action: "query",
            format: "json",
            prop: "images",
            limit: "max", /* tofix */
            titles: pack
        }).done( watchimages );
    }
}

function superwatch() {
    title = mw.config.get("wgPageName");

    watchall([title], "page");

    // get subpages
    var api = new mw.Api();
    api.get( {
        action: "query",
        format: "json",
        list: "prefixsearch",
        pslimit: "max",
        pssearch: title + "/"
    }).done( watchpages );
}


watch=$('#ca-watch')[0];
if ( typeof watch === 'undefined' ) {
    watch=$('#ca-unwatch')[0];
}
$("<li id=\"ca-superwatch\" class=\"icon mw-watchlink\">\
  <span><a href=\"#\">Superwatch</a></span></li>").insertAfter(watch);
$("#ca-superwatch").click(superwatch);


// vim: set expandtab ts=4: