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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.