<commit_before>// web extensions polyfill for ff/chrome
window.browser = (function () {
    return window.browser || window.chrome;
})();

browser.runtime.sendMessage({message: "isEnabled"}, function(response) {
    invert(response.response);
});

browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    invert(request.response);
});

function invert(status) {
    let css = null;
    let bg = null;

    if (status === "enabled") {
        css = 'html {filter: invert(90%) hue-rotate(180deg);} ' +
            'img, canvas, embed, object, video, [style*="url"] {filter: hue-rotate(180deg) invert();}';
        bg = '#000000';

    } else {
        css ='html, img, canvas, embed, object, video, [style*="url"] {filter: none; } ';
        bg = 'initial';
    }

    // set the background immediately
    document.documentElement.style.backgroundColor = bg;

    let head = document.getElementsByTagName('head')[0];
    let style = document.createElement('style');

    style.type = 'text/css';
    if (style.styleSheet){
        style.styleSheet.cssText = css;
    } else {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);

    confirmInvert()
}

function confirmInvert() {
    // white text probably means we already had a dark background, so undo the inversion
    let textColor = window.getComputedStyle(document.body).color.match(/\d+/g);

    if ((textColor[0] > 200) && (textColor[1] > 200) && (textColor[2] > 200)) {

        let css ='html, img, canvas, embed, object, video, [style*="url"] {filter: none; } ';

        document.documentElement.style.backgroundColor = 'initial';

        let head = document.getElementsByTagName('head')[0];
        let style = document.createElement('style');

        style.type = 'text/css';
        if (style.styleSheet){
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);
    }
}
<commit_msg>continue working on images and perf<commit_after>// web extensions polyfill for ff/chrome
window.browser = (function () {
    return window.browser || window.chrome;
})();

browser.runtime.sendMessage({message: "isEnabled"}, function(response) {
    invert(response.response);
});

browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    invert(request.response);
});

function invert(status) {
    let css = null;
    let bg = null;
    let imgcss = null;
    let style = null;

    if (status === "enabled") {
        css = 'html {filter: invert(90%) hue-rotate(180deg);}';
        imgcss = 'img, iframe, canvas, embed, object, video, [style*="url"] {filter: invert(90%) hue-rotate(180deg); }';
        bg = '#000000';

    } else {
        css ='html, img, canvas, embed, object, video, [style*="url"] {filter: none; } ';
        bg = 'initial';
    }

    // set the background immediately
    document.documentElement.style.backgroundColor = bg;

    // update
    if (style) {
        style.sheet.cssRules[0].style.cssText = css;
    } else {
        style = document.createElement('style');
        style.appendChild(document.createTextNode(''));
        document.documentElement.appendChild(style);
        style.sheet.insertRule(css, style.sheet.cssRules.length);
        style.sheet.insertRule(imgcss, style.sheet.cssRules.length);
    }

    confirmInvert()
}

function confirmInvert() {
    // white text probably means we already had a dark background, so undo the inversion
    let textColor = window.getComputedStyle(document.body).color.match(/\d+/g);

    if ((textColor[0] > 200) && (textColor[1] > 200) && (textColor[2] > 200)) {
        let css ='html, img, canvas, embed, object, video, [style*="url"] {filter: none; } ';

        document.documentElement.style.backgroundColor = 'initial';

        style = document.createElement('style');
        style.appendChild(document.createTextNode(''));
        document.documentElement.appendChild(style);
        style.sheet.insertRule(css, style.sheet.cssRules.length);
    }
}

{'fraction_non_alphanumeric': 0.1523065657798389, 'fraction_numerical': 0.013912618989504515, 'mean_word_length': 3.156186612576065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7519187', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1199, 'n_words': 273}