Jump to content

User:Enterprisey/magic-talk-editnotices.js

From Wikipedia, the free encyclopedia
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.
if( mw.config.get( "wgNamespaceNumber" ) === 5 || mw.config.get( "wgNamespaceNumber" ) === 13 ) {
    mw.loader.using( [ "mediawiki.api.category" ], function () {
        new mw.Api().getCategories( mw.config.get( "wgPageName" ).replace( "_talk:", ":" ) ).then( function ( projectPageCats ) {
            var isTargetCat = function ( categoryObject ) { return categoryObject.title === "Wikipedia_information_pages"; };
            if( projectPageCats.some( isTargetCat ) ) {
                console.log( "Detected that we're on the talk page of a page in Category:Wikipedia information pages." );
                document.querySelectorAll( '.mw-editsection > a, #ca-edit > span > a' )
                    .forEach( function ( editLink ) {
                        editLink.setAttribute( "href", editLink.getAttribute( "href" ) +
                            "&editintro=Template:Wikipedia_information_pages_talk_page_editnotice");
                    } );
            }
        } );
    } );
}