User:Scaledish/Scripts/404.js

mw.loader.using(['mediawiki.util'], function () {

// Add button to the "More" tab

mw.util.addPortletLink(

'p-cactions', // Portlet ID for "More" tab

'#', // Href (dummy)

'Check for 404s', // Link text

'ca-check-404', // Link ID

'Check all citations for 404s' // Tooltip

);

// Click handler for the button

$('#ca-check-404').on('click', function (e) {

e.preventDefault();

$('.mw-parser-output a.external').each(function (_, link) {

const href = link.href;

// Skip web.archive.org links

if (href.includes('web.archive.org')) return;

// Special handling for facebook.com

if (href.includes('facebook.com')) {

$(link).css({

'outline': '1px dashed gray',

}).attr('title', 'Facebook must be checked manually.');

return;

}

const citationURL = '/api/rest_v1/data/citation/mediawiki/' + encodeURIComponent(href);

$.ajax({

url: citationURL,

method: 'GET',

success: function () {

// Valid citation, do nothing

},

error: function (xhr) {

if (xhr.status === 404) {

$(link).css({

'outline': '1px dashed red',

}).attr('title', 'Unresolvable citation: not recognized by MediaWiki citation API');

}

}

});

});

});

});