User:V111P/js/whatLinksHereLinkFilter.js
Appearance
< User:V111P | js
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. |
This user script seems to have a documentation page at User:V111P/js/whatLinksHereLinkFilter. |
// 2014-11-30
if (mw.config.get('wgCanonicalSpecialPageName') == 'Whatlinkshere')
$(function () {
var helpPage = '//en.wikipedia.org/wiki/User:V111P/js/What_Links_Here_link_filter';
var spanId = 'excludePagesLinkingTo_span';
var inputId = 'excludePagesLinkingTo_textInput';
var formId = 'excludePagesLinkingTo_form';
var pageNames = [];
$('#' + spanId).remove();
$('div#mw-content-text form + fieldset')
.append($('<span id="' + spanId + '"/>')
.append(' | Hide pages linking to: ')
.append($('<form id="excludePagesLinkingTo_form" style="display:inline;">'
+ '<input type="text" id="' + inputId + '" size="40"/> '
+ '<input type="submit" value="Go"/> (<a href="'
+ helpPage + '" target="_blank">?</a>)</form>')));
$('#' + formId).submit(function (e) {
e.preventDefault();
pageNames = $('#' + inputId).val().split('|');
request();
});
// add a 5000 link next to the 500 link
var limit500Lnk = $('#mw-content-text > a')
.filter(function() { return $.text([this]) == '500'; });
if (limit500Lnk[0]) {
limit500Lnk.after(' | <a title="' + limit500Lnk.attr('title') + '" href="'
+ limit500Lnk.attr('href').replace(/limit=500/, 'limit=5000') + '">5000</a>');
}
function request(blcontinue) {
$.ajax({
url: '/w/api.php?action=query&list=backlinks&format=json&rawcontinue&bllimit=max&bltitle='
+ encodeURIComponent(pageNames[0]) + (blcontinue ? '&blcontinue=' + blcontinue : ''),
dataType: 'json',
error: function () {
$('div#mw-content-text form > fieldset').append(' Error. ');
},
success: function (result) {
var console = window.console || {log: function () {}, error: function (s) {alert(s);}};
if (!result || !result.query || !result.query.backlinks) {
console.error('What Links Here Script error: No (expected) response received from server');
return;
}
var p = result.query.backlinks;
var titles = [];
for (var i = 0; i < p.length; i++) {
titles.push(p[i].title);
}
var elsToRemove = [];
console.log('using page: %s', pageNames[0]);
console.log('links before removal: %d', $('ul#mw-whatlinkshere-list li').length);
$('ul#mw-whatlinkshere-list li').each(function (i, li) {
var lnk = $(li).find('a').first();
if ($.inArray($(lnk).text(), titles) > -1) {
elsToRemove.push(li);
}
});
console.log('removed: %d', elsToRemove.length);
$(elsToRemove).remove();
console.log('links after removal: %d', $('ul#mw-whatlinkshere-list li').length);
if (result['query-continue']) {
console.log('Continue from: %s', result['query-continue'].backlinks.blcontinue);
request(result['query-continue'].backlinks.blcontinue);
}
else {
pageNames.shift();
if (pageNames.length > 0)
request();
}
}
});
}
});