User:Zhuyifei1999/common.js: Difference between revisions

From WikiIndex
Jump to navigation Jump to search
(Export to site)
(New)
Line 1: Line 1:
/**
* Add a toolbox link to enable/disable my scripts
*
* @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
* @rev: 1
*/
var enableMyScripts = $.cookie( 'enable-my-scripts' ) !== 'false';
$(document).ready( function () {
        var $portlet, label = {
                'true': 'Disable my scripts',
                'false': 'Enable my scripts'
                },
                cookieOptions = {
                        expires: 1,
                        path: '/'
                };
        if ( $('#ca-toggle-js').length ) {
                return;
        }
        $portlet = $( mw.util.addPortletLink(
                'p-tb',
                '#',
                label[ enableMyScripts ],
                '#ca-toggle-js',
                'Turn my scripts on or off and reload the page'
        ) );
        $portlet.click( function (e) {
                e.preventDefault(); // prevent '#' from appearing in URL bar
                $.cookie( 'enable-my-scripts', !enableMyScripts, cookieOptions );
                document.location.reload( false ); // Reloads the document (from the cache)
        } );
} );
if (enableMyScripts) {
/* Begin user scripts */


// Your scripts here
/* End user scripts */
} else {
        mw.log( 'Note: Your scripts are disabled.' );
}

Revision as of 10:22, 3 July 2013

/**
 * Add a toolbox link to enable/disable my scripts
 *
 * @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
 * @rev: 1
 */
var enableMyScripts = $.cookie( 'enable-my-scripts' ) !== 'false';
$(document).ready( function () {
        var $portlet, label = {
                'true': 'Disable my scripts',
                'false': 'Enable my scripts'
                },
                cookieOptions = {
                        expires: 1,
                        path: '/'
                };
        if ( $('#ca-toggle-js').length ) {
                return;
        }
        $portlet = $( mw.util.addPortletLink(
                'p-tb',
                '#',
                label[ enableMyScripts ],
                '#ca-toggle-js',
                'Turn my scripts on or off and reload the page'
        ) );
        $portlet.click( function (e) {
                e.preventDefault(); // prevent '#' from appearing in URL bar
                $.cookie( 'enable-my-scripts', !enableMyScripts, cookieOptions );
                document.location.reload( false ); // Reloads the document (from the cache)
        } );
} );
if (enableMyScripts) {
/* Begin user scripts */

// Your scripts here

/* End user scripts */
} else {
        mw.log( 'Note: Your scripts are disabled.' );
}