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 02:00, 26 May 2012 (grr). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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');

        // Create selector with list of classes to apply
        var s = document.createElement('SELECT');
        s.options[s.options.length] = new Option('No indicator', 'wlswitch-none');
        s.options[s.options.length] = new Option('Bold (MediaWiki default)', 'wlswitch-bold');
        s.options[s.options.length] = new Option('Green stars', 'wlswitch-stars');
        s.options[s.options.length] = new Option('Stars and bold', 'wlswitch-starsbold');
        s.options[s.options.length] = new Option('Italics', 'wlswitch-italics');
        s.options[s.options.length] = new Option('Subtle underscore', 'wlswitch-underline');
        s.options[s.options.length] = new Option('Color change', 'wlswitch-colorchange');
        s.options[s.options.length] = new Option('Small \'c\' ("changed")', 'wlswitch-small-c');
        s.options[s.options.length] = new Option('Highlight', 'wlswitch-highlight');
        s.options[s.options.length] = new Option('Faded old changes', 'wlswitch-faded');

        var current = $.cookie('wlswitch-selected');
        if(current) $(s).val(current);

        // Event handler to change the classes
        var classlist=[];
        for(var i = 0; i < s.options.length; i++) classlist.push(s.options[i].value);
        var classlist=classlist.join(' ');
        var body = $(document.body);
        var setClass=function(){
            body.removeClass(classlist);
            var v = $(this).val();
            body.addClass(v);
            $.cookie('wlswitch-selected', v, { expires:365 });
        };
        $(s).change(setClass);
        setClass.call(s);

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