Bruger:Masz/monobook.js

Fra Wikipedia, den frie encyklopædi
// BEGIN PATROLLINK
function linkPatrol() {
     if (document.getElementById("n-patrol")) return;
     var li_current = document.getElementById("n-recentchanges");
     if (!li_current) return;
     var li_next = li_current.nextSibling;
     var ul_node = li_current.parentNode;
     var li = document.createElement("li");
     li.setAttribute("id", "n-patrol");
     li.setAttribute("title", "Se ikke-patruljerede ændringer");
     li.appendChild(document.createElement("a"));
     li.firstChild.setAttribute("href","/w/index.php?title=Speciel:Seneste_%C3%A6ndringer&hidepatrolled=1");
     li.firstChild.appendChild(document.createTextNode("Patruljér"));
     ul_node.insertBefore(li, li_next);
}
$(linkPatrol);

/**
 * Autoreturn after marking changes as patrolled
 *
 *  Description: If the current page is the final page in the patrol loop, then autoreturn to
 *               recent changes, and filter it for more unpatrolled changes
 *               Only Monobook of the skins are supported, and only Firefox of the various browsers are tested.
 *  Maintainers: [[User:Jeblad]]
 */

// the actual action to take
function mpAutoreturnTimer () {
    history.go(-2);
    //document.location = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Special:RecentChanges&hidepatrolled=0';
}

// test for correct page, and then prepare for autoreturn to recent changes
if (/\b(action=markpatrolled)\b/.test(document.location) && /\b(rcid)\b/.test(document.location)) {
    try {
        // we have patrolled a contribution, we wait for a few seconds and then leap back
        //setTimeout("mpAutoreturnTimer()", 100);
        history.go(-2);
    } catch (e) {
        // just go away without notice
    }
}

( function ( mw, $ ) {
	var ns = mw.config.get( 'wgNamespaceNumber' ),
		title = mw.config.get( 'wgTitle' );

	if ( ns < 0 ) {
		return;
	}

	mw.loader.using( [ 'mediawiki.Title', 'mediawiki.api' ], function () {
		$( function () {
			var $catalk = $( '#ca-talk' );
			if ( !$catalk.length || $catalk.hasClass( 'new' ) ) {
				return;
			}

			new mw.Api().get( {
				action: 'query',
				titles: new mw.Title( title, ns | 1 ).getPrefixedText(),
				prop: 'revisions',
				rvprop: 'content',
				indexpageids: 1
			} ).done( function ( r ) {
				var p, s, o;

				if ( !r || !r.query || !r.query.pages || !r.query.pageids || !r.query.pageids[0] ) {
					return;
				}
				p = r.query.pages[r.query.pageids[0]];
				if ( !p || !p.revisions || !p.revisions[0] || !p.revisions[0]['*'] ) {
					return;
				}

				s = p.revisions[0]['*'].replace( /<!--[\s\S]*?-->/g, '' );
				if ( /^#REDIRECT:? *\[\[/i.test( s ) ) {
					$catalk.addClass( 'redirect' );
					return;
				}

				do {
					o = s;
					s = s.replace( /{{{([^{}]|{[^{]|}[^}])*?}}}/g, '' );
					s = s.replace( /{{([^{}]|{[^{]|}[^}])*?}}/g, '' );

				} while ( o !== s );

				if ( /^\s*$/.test( s ) ) {
					$catalk.addClass( 'empty' );
					return;
				}
			} );
		} );
	} );
}( mediaWiki, jQuery ) );