User:Pcoombe (WMF)/cnDeluxe.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
var GBplus = ['GB', 'BM', 'IO', 'VG', 'KY', 'FK', 'GI', 'MS', 'PN', 'SH', 'TC']; // United Kingdom plus its overseas territories
var FRplus = ['FR', 'GF', 'PF', 'TF', 'GP', 'MQ', 'YT', 'NC', 'RE', 'PM', 'WF']; // France plus its overseas territories
var FRchapters = ['CH', 'DE', 'FR', 'GB']; // Chapters doing their own fundraising in 2011
var bannedCountries = ['IR','CU','SY']; // Countries the WMF cannot accept payments from
var swissLangs = ['en', 'de', 'fr', 'it']; // Bored of selecting these by hand
var notEN = bannedCountries.concat(FRchapters, GBplus, FRplus, ['US']); // All countries to NOT include in an 'EN' test
var projectsBox = document.getElementById('projects[]');
var countriesBox = document.getElementById('geo_countries[]');
var languagesBox = document.getElementById('project_languages[]');
function parseParams(url) {
// helper function to get querystring parameters, returns an object
var ret={};
if (url.indexOf('?')===-1) { return ret; }
var s=url.split('?').slice(1).join();
var t=s.split('&');
for (var i=0; i<t.length; ++i) {
var z=t[i].split('=');
z.push(null);
ret[z[0]]=z[1];
}
return ret;
}
function cnDeluxeLoader() {
// handle my styles
importStylesheet( 'User:Pcoombe (WMF)/cnDeluxe.css' );
// get querystring parameters for later
var params = parseParams(window.location.href);
// add a more descriptive title for all these pages
document.title = 'CN: ' + $('h2').html();
// now where are we?
if (wgCanonicalSpecialPageName === 'CentralNotice') {
cnDeluxeSelectTools();
if (params.method === 'listNoticeDetail') {
// Individual campaign page
$('h2').append(' (<a href="//meta.wikimedia.org/wiki/Special:CentralNoticeLogs?log_type=campaignSettings&campaign=' + params.notice + '¢ralnoticesubmit=Apply+filters">logs</a>)');
}
} else if (wgCanonicalSpecialPageName === 'NoticeTemplate') {
if (params.template) {
$('h2').append(' (<a href="//en.wikipedia.org/?banner=' + params.template + '">test</a>)' );
}
}
}
function cnDeluxeSelectTools() {
var countryLinks = '<div class="select-hint">Select: '
countryLinks += '<a onclick="selectAll(countriesBox, true); multiSelect(countriesBox, bannedCountries, false); listCampaignDetails(); return false;" href="#">All except sanctioned (IR, CU, SY)</a>, '
countryLinks += '<a onclick="selectAll(countriesBox, true); multiSelect(countriesBox, notEN, false); listCampaignDetails(); return false;" href="#">EN</a>, '
countryLinks += '<a onclick="selectAll(countriesBox, false); multiSelect(countriesBox, GBplus, true); listCampaignDetails(); return false;" href="#">GBplus</a>, '
countryLinks += '<a onclick="selectAll(countriesBox, false); multiSelect(countriesBox, FRplus, true); listCampaignDetails(); return false;" href="#">FRplus</a>'
countryLinks += '</div>'
$("#geoMultiSelector select").after(countryLinks);
$('select#project_languages\\[\\] + div.select-hint').append(', <a onclick="selectAll(languagesBox, false); multiSelect(languagesBox, swissLangs, true); listCampaignDetails(); return false;" href="#">WMCH</a>')
}
function selectAll(selectBox, checked) {
for (var i = 0; i < selectBox.options.length; i++) {
selectBox.options[i].selected = checked;
}
}
function multiSelect(selectBox, list, checked) {
for (var i = 0; i < selectBox.options.length; i++) {
var c = selectBox.options[i].value;
if (list.toString().indexOf(c)!==-1) {
selectBox.options[i].selected = checked;
}
}
}
$(document).ready(function() {
cnDeluxeLoader();
})