User:DaxServer/test1.js

Source: 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.
//<nowiki>
mw.hook( 'wikipage.content' ).add( function () {
    let articleName = mw.config.get('wgPageName');
	articleName = encodeURIComponent(articleName); // fix bug involving & not getting converted to &amp;
	let pageIsSandbox = articleName.match(/sandbox$/);
    
    $.when(
        /**
         * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
         * @see [[meta:TemplateScript]]
         * @update-token [[File:Pathoschild/templatescript.js]]
         */
        mw.loader.using( [ '//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js' ] ),
        $.ready
    ).then( function () {
    	console.log('Add templatescript');
    	
        pathoschild.TemplateScript.add({
            category: 'Being nice',
            name: 'Welcome',
            template: '{{subst:welcome}} ~~~~',
            position: 'after',
            editSummary: 'Welcome!',
            forNamespaces: 'user talk'
        });
    } );

    // Only on main namespace or sandbox
    // Only initiate in edit or submit mode
    if (
            ! [0, 2].includes(mw.config.get('wgNamespaceNumber'))
        ||  ! pageIsSandbox
        ||  ! ['edit', 'submit'].includes(mw.config.get('wgAction'))
    ) {
        return;
    }

    $.when(
        /**
         * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
         * @see [[meta:TemplateScript]]
         * @update-token [[File:Pathoschild/templatescript.js]]
         */
        mw.loader.using( [ 'mediawiki.util', '//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js' ] ),
        $.ready
    ).then( function () {
        let node = mw.util.addPortletLink('p-tb', '#', 'Book to Sfn', 'ds-book-to-sfn', 'Convert cite book to Sfn');

        $( node ).click(function () {
            alert()
        })
    } );

});
//</nowiki>