From ddceaeb47118872ab2d3f9c84b024084990a2ca0 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 27 May 2021 05:09:50 +0000 Subject: [PATCH] added context menu option to unblock and reload all blocked images on the page FossilOrigin-Name: 6fba83bab3f619e36738b6d5a4d0f23a98226d8e59a309ecee85077832f16729 --- code/modules/cmenu.js | 29 +++++++++++++++++++++++------ code/modules/imgreload.js | 7 +++++++ code/modules/tamper.js | 25 ++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/code/modules/cmenu.js b/code/modules/cmenu.js index 5ed2720..b5603b9 100644 --- a/code/modules/cmenu.js +++ b/code/modules/cmenu.js @@ -82,12 +82,14 @@ CMenu.prototype = { function hideAll () { hide("k8-imago-separator0"); - hide("k8-imago-black"); + hide("k8-imago-white-all"); + hide("k8-imago-separator1"); hide("k8-imago-white"); + hide("k8-imago-black"); hide("k8-imago-reset"); hide("k8-imago-white-noreload"); hide("k8-imago-reload"); - hide("k8-imago-separator1"); + hide("k8-imago-separator2"); } me.imgEl = null; @@ -98,18 +100,33 @@ CMenu.prototype = { addMenuSeparator("k8-imago-separator0"); - addMenuItem("k8-imago-black", "Blacklist image ("+PREFS.forgetSeconds+" secs)", function () { + addMenuItem("k8-imago-white-all", "Whitelist all images ("+PREFS.forgetSeconds+" secs)", function () { if (!me.imgEl) return; - blockImage(me.imgEl.src); - reloadImage(me.imgEl); + for (let img of me.imgEl.ownerDocument.querySelectorAll("img")) { + let src = img.src; + if (!src) continue; + if (img.getAttribute("k8imago-mark") !== "tan") continue; + if (img.getAttribute("k8imago-reloaded") === "tan") continue; + //conlog("UNBLOCKING: "+src); + unblockImage(src); + reloadImage(img); + } }); + addMenuSeparator("k8-imago-separator1"); + addMenuItem("k8-imago-white", "Whitelist image ("+PREFS.forgetSeconds+" secs)", function () { if (!me.imgEl) return; unblockImage(me.imgEl.src); reloadImage(me.imgEl); }); + addMenuItem("k8-imago-black", "Blacklist image ("+PREFS.forgetSeconds+" secs)", function () { + if (!me.imgEl) return; + blockImage(me.imgEl.src); + reloadImage(me.imgEl); + }); + addMenuItem("k8-imago-reset", "Reset image to default", function () { if (!me.imgEl) return; resetImageStatus(me.imgEl.src); @@ -123,7 +140,7 @@ CMenu.prototype = { addMenuItem("k8-imago-reload", "Reload image", function () reloadImage(me.imgEl)); - addMenuSeparator("k8-imago-separator1"); + addMenuSeparator("k8-imago-separator2"); } else { hideAll(); } diff --git a/code/modules/imgreload.js b/code/modules/imgreload.js index 3aef678..d8a5a71 100644 --- a/code/modules/imgreload.js +++ b/code/modules/imgreload.js @@ -79,6 +79,7 @@ function reloadImage (el) { if (el instanceof Ci.nsIImageLoadingContent) { if (PREFS.debugLog) conlog("forcing reload!"); let src = el.getAttribute("src"); + if (!src) return; reloadUrlList[src] = true; expungeImageCache(el); oneShotTimer(function () { delete reloadUrlList[src]; }, 500); @@ -86,8 +87,14 @@ function reloadImage (el) { for (let img of el.ownerDocument.querySelectorAll("img[src]")) { if (img.getAttribute("src") === src) { if (img instanceof Ci.nsIImageLoadingContent) { + img.setAttribute("k8imago-reloaded", "tan"); try { img.forceReload(); + //img.setAttribute("k8imago-saved-title", (img.getAttribute("title")||"")); + //img.setAttribute("k8imago-saved-alt", (img.getAttribute("alt")||"")); + //img.setAttribute("title", title); + //img.setAttribute("alt", title); + //img.setAttribute("k8imago-mark", "tan"); } catch (e) { if (PREFS.debugLog) logException("reload error", e); } diff --git a/code/modules/tamper.js b/code/modules/tamper.js index 9e7b1f9..e534719 100644 --- a/code/modules/tamper.js +++ b/code/modules/tamper.js @@ -86,17 +86,36 @@ ImgDetectListener.prototype = { let url = srcchan.URI.spec; let dw = getDomWindowForChannel(srcchan); if (dw) { + //Services.console.logStringMessage("==================== <"+url+">"); let title; if (this.imageInfo) { title = this.imageInfo.name+" "+(this.imageInfo.valid ? ""+this.imageInfo.width+"x"+this.imageInfo.height : ""); } else { title = (this.blacklisted ? "" : ""); } - for (let img of dw.document.querySelectorAll("img:not([k8imago-mark])[src=\""+cssEscape(url)+"\"]")) { - img.setAttribute("title", title); - img.setAttribute("k8imago-mark", "tan"); + //for (let img of dw.document.querySelectorAll("img:not([k8imago-mark])[src=\""+cssEscape(url)+"\"]")) { + for (let img of dw.document.querySelectorAll("img")) { + if (img.src == url) { + img.setAttribute("k8imago-saved-title", (img.getAttribute("title")||"")); + img.setAttribute("k8imago-saved-alt", (img.getAttribute("alt")||"")); + img.setAttribute("title", title); + img.setAttribute("alt", title); + img.setAttribute("k8imago-mark", "tan"); + //Services.console.logStringMessage("!!! setting title for <"+url+">"); + } + /* + else { + Services.console.logStringMessage("!!! SKIPPING title for <"+img.src+">"); + } + */ } + //Services.console.logStringMessage("======================================================="); + } + /* + else { + Services.console.logStringMessage("+++***+++ NO DOM WINDOW FOR <"+url+">"); } + */ }, // cancel request -- 2.11.4.GIT