[removed] Invert color on all elements of a page

后端 未结 5 1915
逝去的感伤
逝去的感伤 2020-12-02 05:47

Note: I am keeping an up-to-date version of the bookmarklet in my question which works well and is based on Jacob\'s answer. If you are looking for a bookma

5条回答
  •  天命终不由人
    2020-12-02 05:58

    I cleaned up the comments from one of the answers (by leosok) above, so it will work as a bookmarklet in chrome. Note that this solution is more efficient than the current highest-point here, plus it works even if the html changes after you run the script.

    javascript:(function () { 
        var css = 'html {-webkit-filter: invert(100%);' + '-moz-filter: invert(100%);' + '-o-filter: invert(100%);' + '-ms-filter: invert(100%); }';
        var head = document.getElementsByTagName('head')[0];
        var style = document.createElement('style');
        if (!window.counter) { 
            window.counter = 1;
        } else { 
            window.counter++;
            if (window.counter % 2 == 0) { 
                var css = 'html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'
            } 
        }
        style.type = 'text/css';
        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);
    }());
    

    One line for bookmarklet. create a bookmark, then edit the url to this: javascript:(function () { var css = 'html {-webkit-filter: invert(100%);' + '-moz-filter: invert(100%);' + '-o-filter: invert(100%);' + '-ms-filter: invert(100%); }'; var head = document.getElementsByTagName('head')[0]; var style = document.createElement('style'); if (!window.counter) { window.counter = 1; } else { window.counter++; if (window.counter % 2 == 0) { var css = 'html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }' } } style.type = 'text/css'; if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); }());

提交回复
热议问题