Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript( 'User:Ankit18gupta/Editwizard.js' ); // Backlink: [[User:Ankit18gupta/Editwizard.js]]
mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3ABellezzasolo%2FScripts%2Fadminhighlighter.js&action=raw&ctype=text/javascript'); // [[User:Bellezzasolo/Scripts/adminhighlighter.js]] 
importScript('User:Ale_jrb/Scripts/csdhelper.js');  //[[User:Ale_jrb/Scripts]]
/* Adds a toolbox link to do a copyvio check on the given page. */
importScript('User:SD0001/StubSorter.js'); // [[User:SD0001/StubSorter.js]]
importScript( 'User:Qwertyytrewqqwerty/DisamAssist.js' ); // Backlink: [[User:Qwertyytrewqqwerty/DisamAssist.js]]
importScript( 'User:MPGuy2824/MoveToDraft.js' ); // Backlink: [[User:MPGuy2824/MoveToDraft]]
mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3AWrit+Keeper%2FScripts%2FdeletionFinder.js&action=raw&ctype=text/javascript'); // [[User:Writ Keeper/Scripts/deletionFinder.js]]

importScript( 'User:MusikAnimal/responseHelper.js' ); // Backlink: [[User:MusikAnimal/responseHelper.js]]

importScript('User:Anomie/useridentifier.js'); // User Identifier - Adds a little button to the username when viewing the userpage, showing edit count, groups, registering date. Linkback: [[User:Anomie/useridentifier.js]]
importScript('User:Dr_pda/prosesize.js'); //Linkback: [[User:Dr_pda/prosesize.js]]
importScript('User:Lupin/recent2.js'); // Linkback: [[User:Lupin/recent2.js]]
importScript('User:Ryan Vesey/sidebar.js'); // Puts a link in the sidebar to NewPagesFeed. Linkback: [[User:Ryan Vesey/sidebar.js]]
importScript('User:Splarka/sysopdectector.js'); //List usergroups on User:USERNAME or User talk:USERNAME. Linkback: [[User:Splarka/sysopdectector.js]]
importScript('User:TheJosh/Scripts/NewPagePatrol.js'); // Linkback: [[User:TheJosh/Scripts/NewPagePatrol.js]]

importScript('user:js/watchlist.js'); // [[user:js/watchlist]]. Linkback: [[user:js/watchlist.js]]
mw.loader.load('https://meta.wikimedia.org/w/index.php?title=User:Zhaofeng_Li/Reflinks.js&action=raw&ctype=text/javascript'); // Add [[WP:Reflinks]] launcher in the toolbox on left
//CSD Deleter and Decliner
importScript('User:Ale_jrb/Scripts/csdhelper.js'); // Linkback: [[User:Ale_jrb/Scripts/csdhelper.js]]

importScript('User:SD0001/StubSorter.js'); // [[User:SD0001/StubSorter.js]]
importScript('User:Evad37/rater.js'); // [[User:Evad37/rater]]

importScript('User:Lourdes/AfDstarted.js'); // Linkback: [[User:Lourdes/AfDstarted.js]]
importScript('User:SD0001/userRightsManager.js');
importScript( 'User:Enterprisey/undo-last-edit.js' ); // Backlink: [[User:Enterprisey/undo-last-edit.js]]
importScript( 'User:Enterprisey/reply-link.js' ); // Backlink: [[User:Enterprisey/reply-link.js]]
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]
window.popupFixDabs=true;
importScript('User:Lourdes/PageCuration.js'); // Linkback: [[User:Lourdes/PageCuration.js]]
importScript( 'User:Novem Linguae/Scripts/ReviewStatus.js' ); // Backlink: [[User:Novem Linguae/Scripts/ReviewStatus.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');
                    }
                }
            });
        });
    });
});