User:YuviPanda/lost.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. |
Documentation for this user script can be added at User:YuviPanda/lost. |
$( function() {
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
return;
}
mw.loader.using( 'mediawiki.ui', function() {
var cats = $( "#mw-normal-catlinks ul a").map( function( i, a ) { return $(a).text() });
var cat = cats[ Math.floor( Math.random() * cats.length ) ];
$( "<a id='random-related' class='mw-ui-button mw-ui-primary'>MEOW RANDOM!</a>").click( function () {
window.location.href = "/wiki/Special:RandomInCategory/" + cat;
}).appendTo( "#siteSub" );
var newLinks = $.map( $( "#mw-content-text a[href^='/wiki/']" ), function( node ) {
return $(node).attr('href');
});
newLinks = $.grep( newLinks, function( str ) {
return str.indexOf( ":" ) === -1;
});
var plainLink = newLinks[ Math.floor( Math.random() * newLinks.length ) ];
$( "<a id='random-links' class='mw-ui-button mw-ui-primary'>LINKY RANDOM!</a>").click( function () {
window.location.href = plainLink;
localStorage.randomOldLinks = JSON.stringify(newLinks);
}).appendTo( "#siteSub" );
var oldLinks = typeof localStorage.randomOldLinks === 'undefined' ? [] : JSON.parse( localStorage.randomOldLinks );
var intersectLinks = oldLinks.filter(function ( s ) { return newLinks.indexOf( s ) !== -1 } );
if ( intersectLinks.length ) {
var intersectLink = intersectLinks[ Math.floor( Math.random() * intersectLinks.length ) ];
$( "<a id='random-inter-links' class='mw-ui-button mw-ui-primary'>CLOSER RANDOM!</a>").click( function () {
window.location.href = intersectLink;
localStorage.randomOldLinks = JSON.stringify(newLinks);
}).appendTo( "#siteSub" );
}
} );
});