User:Dialectric/vector.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. |
![]() | The accompanying .css page for this skin is at User:Dialectric/vector.css. |
//------------------------------------------------------
// recolor test
// task: to override inline styles for some table elements to better fit dark theme
// status: testing only - do not use
//------------------------------------------------------
/*
function fixLightColorBackground(anElement) {
var c = anElement.style.backgroundColor ;
var c = c.substring(1); // strip #
var rgb = parseInt(c, 16); // convert rrggbb to decimal
var r = (rgb >> 16) & 0xff; // extract red
var g = (rgb >> 8) & 0xff; // extract green
var b = (rgb >> 0) & 0xff; // extract blue
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
if (luma < 40) {
// pick a different colour
anElement.style.backgroundColor = '#272822';
anElement.style.color = '#F8F8F2';
}
if (luma > 44) {
// pick a different colour
anElement.style.border = '#4px solid #FFF';
}
};
function ready(callback){
// in case the document is already rendered
if (document.readyState!='loading') callback();
// modern browsers
else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback);
// IE <= 8
else document.attachEvent('onreadystatechange', function(){
if (document.readyState=='complete') callback();
});
}
ready(function(){
// do something
var target = document.querySelectorAll('table');
Array.prototype.forEach.call(target, function(element){
fixLightColorBackground(element);
});
var target = document.querySelectorAll('th');
Array.prototype.forEach.call(target, function(element){
fixLightColorBackground(element);
});
var target = document.querySelectorAll('h2');
Array.prototype.forEach.call(target, function(element){
fixLightColorBackground(element);
});
var target = document.querySelectorAll('tr');
Array.prototype.forEach.call(target, function(element){
//element.removeAttribute('style');
//element.style.border = '2px solid #F00';
});
});
*/