User:D8087/vector.js

//-- // 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';        }); });