From b01d57ab631a7c5e39eadd6998382d1eaf0beae5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 4 Aug 2022 10:52:09 -0400 Subject: [PATCH] Fix dark theme issue in DOM inspector Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2196 --- src/js/scriptlets/dom-inspector.js | 103 ++--------------------------- 1 file changed, 5 insertions(+), 98 deletions(-) diff --git a/src/js/scriptlets/dom-inspector.js b/src/js/scriptlets/dom-inspector.js index d8ce5c330..884754393 100644 --- a/src/js/scriptlets/dom-inspector.js +++ b/src/js/scriptlets/dom-inspector.js @@ -41,100 +41,6 @@ if ( document.querySelector('iframe.dom-inspector.' + sessionId) !== null ) { /******************************************************************************/ /******************************************************************************/ -// Modified to avoid installing as a global shim -- so the scriptlet can be -// flushed from memory once no longer in use. - -// Added serializeAsString parameter. - -/*! http://mths.be/cssescape v0.2.1 by @mathias | MIT license */ -const cssEscape = (function(/*root*/) { - - var InvalidCharacterError = function(message) { - this.message = message; - }; - InvalidCharacterError.prototype = new Error(); - InvalidCharacterError.prototype.name = 'InvalidCharacterError'; - - // http://dev.w3.org/csswg/cssom/#serialize-an-identifier - return function(value, serializeAsString) { - var string = String(value); - var length = string.length; - var index = -1; - var codeUnit; - var result = ''; - var firstCodeUnit = string.charCodeAt(0); - while (++index < length) { - codeUnit = string.charCodeAt(index); - // Note: there’s no need to special-case astral symbols, surrogate - // pairs, or lone surrogates. - - // If the character is NULL (U+0000), then throw an - // `InvalidCharacterError` exception and terminate these steps. - if (codeUnit === 0x0000) { - throw new InvalidCharacterError( - 'Invalid character: the input contains U+0000.' - ); - } - - if ( - // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is - // U+007F, […] - (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit === 0x007F || - // If the character is the first character and is in the range [0-9] - // (U+0030 to U+0039), […] - (index === 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) || - // If the character is the second character and is in the range [0-9] - // (U+0030 to U+0039) and the first character is a `-` (U+002D), […] - ( - index === 1 && - codeUnit >= 0x0030 && codeUnit <= 0x0039 && - firstCodeUnit === 0x002D - ) - ) { - // http://dev.w3.org/csswg/cssom/#escape-a-character-as-code-point - result += '\\' + codeUnit.toString(16) + ' '; - continue; - } - - // If the character is not handled by one of the above rules and is - // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or - // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to - // U+005A), or [a-z] (U+0061 to U+007A), […] - if ( - codeUnit >= 0x0080 || - codeUnit === 0x002D || - codeUnit === 0x005F || - codeUnit >= 0x0030 && codeUnit <= 0x0039 || - codeUnit >= 0x0041 && codeUnit <= 0x005A || - codeUnit >= 0x0061 && codeUnit <= 0x007A - ) { - // the character itself - result += string.charAt(index); - continue; - } - - // If "serialize a string": - // If the character is '"' (U+0022) or "\" (U+005C), the escaped - // character. Otherwise, the character itself. - // http://dev.w3.org/csswg/cssom/#serialize-a-string - if ( serializeAsString && codeUnit !== 0x0022 && codeUnit !== 0x005C ) { - // the character itself - result += string.charAt(index); - continue; - } - - // Otherwise, the escaped character. - // http://dev.w3.org/csswg/cssom/#escape-a-character - result += '\\' + string.charAt(index); - - } - return result; - }; -}(self)); - -/******************************************************************************/ -/******************************************************************************/ - let loggerConnectionId; // Highlighter-related @@ -177,19 +83,19 @@ const domLayout = (function() { const selectorFromNode = function(node) { var str, attr, pos, sw, i; var tag = node.localName; - var selector = cssEscape(tag); + var selector = CSS.escape(tag); // Id if ( typeof node.id === 'string' ) { str = node.id.trim(); if ( str !== '' ) { - selector += '#' + cssEscape(str); + selector += '#' + CSS.escape(str); } } // Class var cl = node.classList; if ( cl ) { for ( i = 0; i < cl.length; i++ ) { - selector += '.' + cssEscape(cl[i]); + selector += '.' + CSS.escape(cl[i]); } } // Tag-specific attributes @@ -209,7 +115,7 @@ const domLayout = (function() { sw = ''; } if ( str !== '' ) { - selector += '[' + attr + sw + '="' + cssEscape(str, true) + '"]'; + selector += '[' + attr + sw + '="' + CSS.escape(str, true) + '"]'; } } return selector; @@ -949,6 +855,7 @@ pickerRoot.style.cssText = [ 'border: 0', 'border-radius: 0', 'box-shadow: none', + 'color-scheme: light', 'display: block', 'height: 100%', 'left: 0',