MediaWiki:Group-bureaucrat.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
var menuBaris = JSON.parse(localStorage.menuBar); | var menuBaris = JSON.parse(localStorage.menuBar); | ||
menuCategories.forEach(function(elemento, indice, array) { | menuCategories.forEach(function(elemento, indice, array) { | ||
shuffle(menuBaris[indice]); | |||
for(var i = 1; i < 4; i++) { | for(var i = 1; i < 4; i++) { | ||
var thisli = $( elemento+ " .body ul li a" ).eq(i); | var thisli = $( elemento+ " .body ul li a" ).eq(i); | ||
Line 24: | Line 25: | ||
jQuery.getJSON('https://wiki.pokeheroes.com/api.php?action=query&list=categorymembers&cmtitle=Category:'+e+'&cmdir=desc&cmsort=timestamp&format=json&cmlimit=12', function(data) { | jQuery.getJSON('https://wiki.pokeheroes.com/api.php?action=query&list=categorymembers&cmtitle=Category:'+e+'&cmdir=desc&cmsort=timestamp&format=json&cmlimit=12', function(data) { | ||
menuBaris[i] = data['query']['categorymembers']; | menuBaris[i] = data['query']['categorymembers']; | ||
shuffle(menuBaris[i]); | |||
for(var ix = 1; ix < 4; ix++) { | for(var ix = 1; ix < 4; ix++) { | ||
var thisli = $( menuCategories[i]+ " .body ul li a" ).eq(ix); | var thisli = $( menuCategories[i]+ " .body ul li a" ).eq(ix); |
Revision as of 23:38, 19 July 2020
mw.loader.using( [ 'mediawiki.util' ] ).done( function () { var menuCategories = ['#p-Event_Pok\\.C3\\.A9mon', '#p-Pages', '#p-Pok\\.C3\\.A9mon', '#p-Events', '#p-Help']; function shuffle(a) { for (var i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; }; if(typeof localStorage.menuBar !== "undefined") { var menuBaris = JSON.parse(localStorage.menuBar); menuCategories.forEach(function(elemento, indice, array) { shuffle(menuBaris[indice]); for(var i = 1; i < 4; i++) { var thisli = $( elemento+ " .body ul li a" ).eq(i); thisli.text(menuBaris[indice][(i-1)]['title']); thisli.attr("href", menuBaris[indice][(i-1)]['title']); } }) } else { var catNames = ["Event%20Pok%C3%A9mon", "Page", "Pok%C3%A9mon", "Events", "Help"]; var menuBaris = []; catNames.forEach(function(e, i, a) { jQuery.getJSON('https://wiki.pokeheroes.com/api.php?action=query&list=categorymembers&cmtitle=Category:'+e+'&cmdir=desc&cmsort=timestamp&format=json&cmlimit=12', function(data) { menuBaris[i] = data['query']['categorymembers']; shuffle(menuBaris[i]); for(var ix = 1; ix < 4; ix++) { var thisli = $( menuCategories[i]+ " .body ul li a" ).eq(ix); thisli.text(menuBaris[i][(ix-1)]['title']); thisli.attr("href", menuBaris[i][(ix-1)]['title']); } localStorage.setItem("menuBar", JSON.stringify(menuBaris)); }); }); } });