User:Splarka/cmlhider.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:Splarka/cmlhider. |
/* Category Member Link Hider script, version [0.0.1]
Originally from: http://wiki.riteme.site/wiki/User:Splarka/cmlhider.js
On Prefixindex, will prompt for a category name, and hide all links found to pages in that category.
Notes:
* VERY slow, could be optimized probably.
* Limited to categories with 500 members, a query-continue would be needed for longer ones.
* Test version.
*/
if(wgCanonicalSpecialPageName == 'Prefixindex') addOnloadHook(hideCatMemLinksButton)
function hideCatMemLinksButton() {
mw.util.addPortletLink('p-tb','javascript:hideCML()','Hide links','t-cml','Hide links to articles in a specified category');
}
function hideCML() {
var cat = prompt('Enter a category name','Category:NA-Class articles');
if(cat == '' || !cat) return;
var cml = document.getElementById('t-cml');
if(cml) {
var prog = document.createElement('img');
prog.setAttribute('id','cml-prog');
prog.setAttribute('src',stylepath + '/common/images/spinner.gif');
cml.appendChild(prog);
}
var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=hideCMLCB&list=categorymembers&cmnamespace=14&cmlimit=500&cmtitle=' + cat;
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src',url);
scriptElem.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function hideCMLCB(obj) {
var links = (document.getElementById('content')) ? document.getElementById('content').getElementsByTagName('a') : document.getElementById('mw_content').getElementsByTagName('a')
if(!obj['query'] || !obj['query']['categorymembers']) return
for(var i in obj['query']['categorymembers']) {
var pg = obj['query']['categorymembers'][i]['title'];
pg = wgArticlePath.replace(/\$1/,'') + pg.replace(/ /ig,'_');
for(var j=0;j<links.length;j++) {
if(links[j].href.replace(wgServer,'') == pg) {
links[j].style.visibility = 'hidden';
}
}
}
var cml = document.getElementById('t-cml');
if(cml) document.getElementById('cml-prog').style.display = 'none'
}