MediaWiki:WantedPagesFilter/code.js

//adds simple filter to special:wantedpages $(function {   var mwc = mw.config.get(['wgContentLanguage', 'wgFormattedNamespaces', 'wgCanonicalSpecialPageName']);    var r = /(.*?):/;    var activeFilter = [];    var filterText = {        en: 'Filter',        ru: 'Фильтр',    };    if (mwc.wgCanonicalSpecialPageName !== 'Wantedpages') return;

function onChange (e) { $('.special li').css('display', 'list-item'); activeFilter = []; $.each(e.target.selectedOptions, function {           var $this = this;            $('.special li[data-ns="' + $this.value + '"]').css('display', 'none');            activeFilter.push($this.value || '');        });//each selected option window.sessionStorage.wpFilter = JSON.stringify(activeFilter); }//onChange filterText = filterText[$.getUrlVar('uselang')] || filterText[mwc.wgContentLanguage] || filterText.en; //add ns data $('.special .new, .special .newcategory').each(function {       var $this = $(this);        var ns = r.exec($this.text) || '';        if (ns instanceof Array) ns = ns[1];        if (Object.values(mwc.wgFormattedNamespaces).indexOf(ns) > -1) {            $this.closest('li').attr('data-ns', ns);        }    }); var $wpfilter = $(' ', {       class: 'wp-filter',        style: 'float:right;'    }); var $label = $(' ', {       class: 'wp-label',        text: filterText,        style: 'padding-right: 5px; vertical-align: top;'    }); var $list = $(' ', {       class: 'wp-list',        multiple: 1,        style: 'height: 200px;'    }); $wpfilter.append($label).append($list); $list.append($(' ', { value: 'all', text: 'all' }));   //fill ns list $.each(mwc.wgFormattedNamespaces, function(k, v) {       $list.append($(' ', {            value: v,            text: v || 'Main'        }));    });//each ns    $('.mw-spcontent').prepend($wpfilter); //set initial state if (window.sessionStorage.wpFilter) { activeFilter = JSON.parse(window.sessionStorage.wpFilter); } else { activeFilter.push('all'); }   var fakee = {target: {selectedOptions: []}}; $.each(activeFilter, function(i, v) {       var item = $list.find('[value="' + v + '"]').get(0);        if (item) item.selected = 'selected';        fakee.target.selectedOptions.push(item);    }); onChange(fakee); $list.on('change', onChange);//on change });