From 20c405f1a291a170366e9c6db508e2eb0c17f8e8 Mon Sep 17 00:00:00 2001 From: ThomazPom Date: Thu, 28 Dec 2023 17:16:41 +0100 Subject: [PATCH] 1.5.21 : Intronducing a method to load CSS as chunck allowing websites to load faster, fixing a bug which forced CSS to load multiple times and still working on texts colors over images --- background.js | 168 +++++++++++++++++++++++++++----- content_script.js | 8 +- inject_css_override_no_edit.css | 5 + manifest.json | 2 +- 4 files changed, 153 insertions(+), 30 deletions(-) diff --git a/background.js b/background.js index 2fc9684..5b1eae2 100644 --- a/background.js +++ b/background.js @@ -1221,16 +1221,22 @@ window.dark_object = { let B = uDark.max_bright_fg let E = uDark.brightness_peak_editor_fg + let ol=l; // l = Math.sin(Math.PI*l)*(A-B)+B; l = Math.min(2 * l, -2 * l + 2) * (A - B) + B; // Was a good one, but we may boost saturation as folowing lines shows // Still not sure about the best way to do it ^ has implicity while indeed a saturation boost might be nice // l = Math.pow(Math.min(2 * l, -2 * l + 2),E) * (A - B) + B; - + if(l>.60 && h>0.66 && h<0.72) + { + + // FIXME: EXPERIMENTAL: + h+=0.66-0.72; // Avoid blueish colors being purple + } // i dont like how saturation boost gives a blue color to some texts like gitlab's ones. // s=1-Math.pow(1-s,1/E); // Boost saturation proportionnaly as brightness decrease, but we could have a separate setting for saturation boost - - + + // h=h-(l-ol)/4; // Keep the same hue, but we could have a separate setting for hue shift [r, g, b] = uDark.hslToRgb(h, s, l); @@ -1361,8 +1367,14 @@ window.dark_object = { // console.log("Found a background image via property",property,cssRule.selectorText,`'${cssStyle[property]}'`); }, + isInsideSquare(squareTop,squareBottom,squareLeft,squareRight,pointTop,pointLeft) + { + return pointTop>=squareTop && pointTop<=squareBottom && pointLeft>=squareLeft && pointLeft<=squareRight; + + }, restoreTextsOnBackgroundItems() { + let all_tems = [...document.querySelectorAll("*")]; let bgItems = [...document.querySelectorAll([...uDark.backgroundItemsSelectors].join(","))] .filter(imagedItem=>imagedItem.offsetWidth>50 || imagedItem.offsetHeight>50) .map(imagedItem=>{ @@ -1370,24 +1382,106 @@ window.dark_object = { return { item:imagedItem, t1:boundingRect.top+window.scrollY, - t2:boundingRect.left+window.scrollX, - b1:boundingRect.top+window.scrollY+imagedItem.offsetHeight, - b2:boundingRect.left+window.scrollX+imagedItem.offsetWidth, + l1:boundingRect.left+window.scrollX, + t2:boundingRect.top+window.scrollY+imagedItem.offsetHeight, + l2:boundingRect.left+window.scrollX+imagedItem.offsetWidth, } }); - document.querySelectorAll("body *").forEach(textItem=>{ + let bgColorItem = [...document.querySelectorAll("[style*=background],[class]")] + .filter(coloredItem=>coloredItem.offsetWidth>50 || coloredItem.offsetHeight>50) + .filter(x=>getComputedStyle(x).backgroundColor!="rgba(0, 0, 0, 0)" && !getComputedStyle(x).backgroundImage.includes("url(")) + .map(imagedItem=>{ + let boundingRect = imagedItem.getBoundingClientRect(); + return { + item:imagedItem, + t1:boundingRect.top+window.scrollY, + l1:boundingRect.left+window.scrollX, + t2:boundingRect.top+window.scrollY+imagedItem.offsetHeight, + l2:boundingRect.left+window.scrollX+imagedItem.offsetWidth, + } + }); + [...document.querySelectorAll("body *:not(:empty)")].filter(x=>getComputedStyle(x).backgroundColor=="rgba(0, 0, 0, 0)").forEach(textItem=>{ let boundingRect = getBoundingClientRect=textItem.getBoundingClientRect(); boundingRect= { t1:boundingRect.top+window.scrollY, - t2:boundingRect.left+window.scrollX, - b1:boundingRect.top+window.scrollY+textItem.offsetHeight, - b2:boundingRect.left+window.scrollX+textItem.offsetWidth, + l1:boundingRect.left+window.scrollX, + t2:boundingRect.top+window.scrollY+textItem.offsetHeight, + l2:boundingRect.left+window.scrollX+textItem.offsetWidth, } bgItems.forEach(bgItem=>{ - if(boundingRect.t1>bgItem.t1 && boundingRect.t2>bgItem.t2 && boundingRect.b1x.remove()) + if(clone.textContent.trim()) + { + bgColorItem.forEach(bgColorItem=>{ + let zIndexColor = parseInt(getComputedStyle(bgColorItem.item).zIndex)||0; + let zIndexBg = parseInt(getComputedStyle(bgItem.item).zIndex)||0; + if(zIndexBg==zIndexColor) + { + zIndexColor=all_tems.indexOf(bgColorItem.item); + zIndexBg=all_tems.indexOf(bgItem.item); + } + if(zIndexColor { details.datacount++ - // Cant do both, next step would be to truly parse str ; details.writeEnd += decoder.decode(event.data, { stream: true }); diff --git a/content_script.js b/content_script.js index 21f9cf2..ff0b03f 100644 --- a/content_script.js +++ b/content_script.js @@ -13,9 +13,11 @@ function resolveIDKVars(data) { data.chunk = ikd_resolved; myPort.postMessage({resolvedIDKVars:data}); // console.log("In content script, resolved IDK vars: ", data); - setTimeout(()=>{ - window.wrappedJSObject.uDark.refresh_stylesheet(data.details.url); -},0) + if(data.refresh_stylesheet) { + setTimeout(()=>{ + window.wrappedJSObject.uDark.refresh_stylesheet(data.details.url); + },0) + } } ,100); // 100s should be enough, as in fact the page is already almost loaded : // We are here because link tags are already loaded, (so stylesheets are OK) and we are only waiting for all of this to be put in context wich is short diff --git a/inject_css_override_no_edit.css b/inject_css_override_no_edit.css index e69de29..3565e58 100644 --- a/inject_css_override_no_edit.css +++ b/inject_css_override_no_edit.css @@ -0,0 +1,5 @@ + +.ud_overImage { + color: white; + mix-blend-mode: exclusion; + ;} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 0f5d1c5..25ea239 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "UltimaDark", - "version": "1.5.20", + "version": "1.5.21", "description": "The extension uses agressive techniques to get a dark mode everywhere on internet\nThis is still highly experimental so it can also ruin your internet experience", "homepage_url": "https://github.com/ThomazPom/Moz-Ext-UltimaDark", "icons": {