Jump to content

User:Anomie/watchlist-change-style-selector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anomie (talk | contribs) at 01:27, 26 May 2012 (Try at a watchlist style selector). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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('wgPageName') == 'Special:Watchlist') mw.loader.using('jQuery.cookie', function($){
    $(document).ready(function(){
        var x = $('#mw-watchlist-resetbutton');
        if(!x) return;

        // Needed until [[bugzilla:36788]] gets fixed
        $('strong.mw-watched').parent('li').addClass('mw-watched');
        $('strong.mw-watched').parent('table.mw-enhanced-rc').addClass('mw-watched');

        // List of classes that can be applied
        var classes = {
            'wlswitch-00-none' : 'No indicator',
            'wlswitch-01-bold' : 'Bold (MediaWiki default)',
            'wlswitch-02-stars' : 'Green stars',
            'wlswitch-03-boldstars' : 'Green stars and Bold',
            'wlswitch-04-italics' : 'Italics',
            'wlswitch-05-C' : 'Small "c" ("changed")',
            'wlswitch-06-underline' : 'Subtle underscore',
            'wlswitch-07-colorchange' : 'Color change',
            'wlswitch-08-enhancedcolors' : 'Enhanced link colors',
            'wlswitch-09-faded' : 'Faded old changes',
            'wlswitch-10-highlight' : 'Highlight',
        };

        // Insert our selector after the "reset" button
        var classlist=[];
        for(var k in classes) classlist.push(k);
        classlist.sort();
        var classstring=classlist.join(' ');
        var body = $(document.body);
        var setClass=function(){
            body.removeClass(classstring);
            var v = $(this).val();
            body.addClass(v);
            $.cookie('wlswitch-selected', v, { expires:365 });
        };

        var current = $.cookie('wlswitch-selected');
        var s = document.createElement('SELECT');
        for(var i = 0; i < classlist.length; i++) {
            var k = classlist[i];
            s.options[i] = new Option(classes[k], k);
            if(k == current) s.selectedIndex = i;
        }
        $(s).change(setClass);
        setClass.call(this);

        x.after($('<p>Watchlist change style: </p>').append(s));
    });
});