User:Alex 21/script-linecolour.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Alex 21/script-linecolour. |
$(function($) {
if(wgNamespaceNumber !== 0) {
return;
}
var portletlink = mw.util.addPortletLink('p-tb', '#', 'Fix line colours');
$(portletlink).click( function(e) {
e.preventDefault();
var loc = window.location.href; var wpTextbox1 = document.getElementById('wpTextbox1'); var i;
if (loc.indexOf('colour_contrast') > 0) {
var bc = document.getElementById('bc');
var fc = document.getElementById('fc');
var contrastratio = document.getElementById('contrastratio');
var bsSliderInput = document.getElementById('bs-slider-input');
var bvSliderInput = document.getElementById('bv-slider-input');
fc.value = 'FFFFFF'; fc.onchange();
var __white = contrastratio.value;
fc.value = '000000'; fc.onchange();
var __black = contrastratio.value;
if (__white > __black) { fc.value = 'FFFFFF'; fc.onchange(); }
if (__black > __white) { fc.value = '000000'; fc.onchange(); }
var counter = 0; var giveprompt = true;
while (contrastratio.value <= 7) {
if (counter > 100) {
alert('Infinite loop - manual adjustment required!');
giveprompt = false;
break;
}
if (bvSliderInput.value < 100 && bvSliderInput.value > 0) {
bvSliderInput.value = parseInt(bvSliderInput.value)+(fc.value == 'FFFFFF' ? -1 : 1);
bvSliderInput.onchange();
} else {
bsSliderInput.value = parseInt(bsSliderInput.value)+(fc.value == 'FFFFFF' ? 1 : -1);
bsSliderInput.onchange();
}
counter++;
}
if (giveprompt) {
var contrastingColour = bc.value;
if (window.prompt("Copy to clipboard: Ctrl+C, Enter", contrastingColour)) window.close();
}
} else if (loc.indexOf('Category:') >= 0) {
for (i = 3; i < 13; i++) {
window.open("https://en.wikipedia.org/wiki/"+document.getElementsByClassName('mw-content-ltr')[0].getElementsByTagName('li')[i].children[0].title);
}
} else if (loc.indexOf('action=edit') < 0) {
window.location = window.location+"?action=edit";
} else {
var colours = [];
var s = wpTextbox1.value.split("\n");
for (i = 0; i < s.length; i++) {
if (s[i].indexOf('LineColor') > 0) {
var reg = /\|([\s]*)[LineColor]*([\s=]*)\#?([0-9A-Fa-f]{3,6})/g;
var t = reg.exec(s[i]);
if (!t) continue;
var fontColor = t[3];
if (colours.indexOf(fontColor) >= 0) continue;
colours[colours.length] = fontColor;
}
}
window.open("http://snook.ca/technical/colour_contrast/colour.html#fg=FFFFFF,bg="+colours[0]);
document.addEventListener("keypress", function(e) {
if (e.keyCode == 13) {
var thiscolour = colours.shift();
var newcolour = prompt('New colour for '+thiscolour+'?');
if (newcolour) {
/* #FF3344 = #F34 */
var _3code;
if (thiscolour[0] == thiscolour[1] && thiscolour[2] == thiscolour[3] && thiscolour[4] == thiscolour[5])
_3code = thiscolour[0]+thiscolour[2]+thiscolour[4]+'|';
else _3code = '';
var reg2 = new RegExp('\\b'+_3code+thiscolour+'\\b','gi');
wpTextbox1.value = wpTextbox1.value.replace(reg2,newcolour);
}
if (colours.length === 0) {
document.getElementById('wpSummary').value =
"Changed colors per [[WP:COLOR]] and [[Template talk:Infobox television season#Colour]].";
document.getElementById('wpSave').click();
} else {
window.open("http://snook.ca/technical/colour_contrast/colour.html#fg=FFFFFF,bg="+colours[0]);
}
}
});
}
});
});