diff --git a/README.md b/README.md index df07eb9..8a06075 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ If you can try a development version, the following steps are needed. # Change logs +## [0.2.2](https://github.com/horihiro/TextBlurrer-ChromeExtension/releases/tag/0.2.2) + + - Bug fixes + - Improve performance ([#52](https://github.com/horihiro/TextBlurrer-ChromeExtension/issues/52) + - Fix adding exclusion URL patterns list + ## [0.2.1](https://github.com/horihiro/TextBlurrer-ChromeExtension/releases/tag/0.2.1) - Bug fixes diff --git a/content/js/main.js b/content/js/main.js index a821b92..f009e14 100644 --- a/content/js/main.js +++ b/content/js/main.js @@ -40,7 +40,7 @@ await send2popup({ method: 'getUrlResponse', isTop: window.top === window, - numOfChildren: window.frames.length, + numOfChildren: Array.from(document.querySelectorAll('iframe,frame')).filter(f => /^https?:\/\//.test(f.src)).length, url: location.href }); } @@ -88,7 +88,11 @@ : '' } - const BLOCK_ELEMENT_NAMES = ['ADDRESS', 'BLOCKQUOTE', 'DIV', 'DL', 'FIELDSET', 'FORM', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR', 'NOSCRIPT', 'SCRIPT', 'PL', 'P', 'PRE', 'TABLE', 'UL']; + const BLOCK_ELEMENT_NAMES = [ + 'ADDRESS', 'ARTICLE', 'ASIDE', 'BLOCKQUOTE', 'CANVAS', 'DD', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', + 'FIGURE', 'FOOTER', 'FORM', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HEADER', 'HR', 'LI', 'MAIN', 'NAV', 'NOSCRIPT', + 'OL', 'P', 'PRE', 'SCRIPT', 'SECTION', 'TABLE', 'TFOOT', 'UL', 'VIDEO' + ]; const blockContents = (node) => { return Array.from(node.childNodes).reduce((lines, child) => { if (SKIP_NODE_NAMES.includes(child.nodeName)) return lines; @@ -622,7 +626,7 @@ if (node.nodeName === 'TITLE') { blurTabTitleCore(pattern, node); return true; - } else if (node.nodeName === "#text" && node.parentNode.nodeName === "TITLE") { + } else if (node.nodeName === "#text" && node.parentNode && node.parentNode.nodeName === "TITLE") { blurTabTitleCore(pattern, node.parentNode); return true; } diff --git a/manifest.json b/manifest.json index 896ce46..2ecb415 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "manifest_version": 3, "name": "Text Blurrer", - "version": "0.2.1", - "version_name": "0.2.1", + "version": "0.2.2", + "version_name": "0.2.2", "description": "Blurring sensitive specified text/keyword.", "permissions": [ "storage", diff --git a/popup/js/main.js b/popup/js/main.js index 7d74462..5ea14a7 100644 --- a/popup/js/main.js +++ b/popup/js/main.js @@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', async (e) => { } if (e.key === 'F' && e.altKey && e.shiftKey) { const textarea = document.querySelector('#tab-exclusion:checked~#tab-panel-exclusion textarea') - || document.querySelector('#tab-keywords:checked~#tab-panel-keywords textarea'); + || document.querySelector('#tab-keywords:checked~#tab-panel-keywords textarea'); textarea.focus(); textarea.value = textarea.value.split(/\n/).filter(l => l.trim() !== '').join('\n'); e.preventDefault(); @@ -55,36 +55,23 @@ document.addEventListener('DOMContentLoaded', async (e) => { window.location.reload(); }); + const onMessageListener = async (message, sender, sendResponse) => { + if (message.method !== 'getUrlResponse') return; + + const escapedUrl = escapeRegExp(message.url); + const currentValue = exclusionInput.value.split(/\n/); + if (currentValue.includes(escapedUrl) || currentValue.filter(l => !!l).some(v => new RegExp(v).test(message.url))) return; + + exclusionInput.value = `${exclusionInput.value.trimEnd()} +^${escapedUrl}$`; + await renderBackground({ target: exclusionInput }); + applyButton.disabled = false; + exclusionInput.focus(); + }; + chrome.runtime.onMessage.addListener(onMessageListener); + addUrlsInCurrentTab.addEventListener('click', async (e) => { if (!statusCheckbox.checked) return; - const urlInfo = { - returnFromTop: false, - numOfChildren: 0, - escapedUrls: [] - }; - const onMessageListener = async (message, sender, sendResponse) => { - if (message.method !== 'getUrlResponse') return; - - urlInfo.returnFromTop ||= message.isTop; - urlInfo.numOfChildren += message.numOfChildren; - urlInfo.escapedUrls.push(`^${escapeRegExp(message.url)}$`); - - if (!urlInfo.returnFromTop || urlInfo.numOfChildren + 1 != urlInfo.escapedUrls.length) return; - - chrome.runtime.onMessage.removeListener(onMessageListener); - - if (!urlInfo.escapedUrls.reduce((added, escapedUrl) => { - const currentValue = exclusionInput.value.split(/\n/); - if (currentValue.includes(escapedUrl)) return added || false; - exclusionInput.value = exclusionInput.value.trimEnd() + '\n' + escapedUrl; - return true; - }, false)) return; - - await renderBackground({ target: exclusionInput }); - applyButton.disabled = false; - exclusionInput.focus(); - }; - chrome.runtime.onMessage.addListener(onMessageListener); const tabs = await chrome.tabs.query({ active: true, currentWindow: true }); await chrome.tabs.sendMessage(tabs[0].id, { method: 'getUrl' }); }); @@ -248,6 +235,7 @@ textarea#${e.target.id} { exclusionInput.disabled = !e.target.checked; validationResults[patternInput.id] = await validateLines(patternInput, !regexpCheckbox.checked); validationResults[exclusionInput.id] = await validateLines(exclusionInput, !regexpCheckbox.checked); + addUrlsInCurrentTab.style.cursor = e.target.checked ? '' : 'auto'; applyButton.disabled = !e.target.checked || !validationResults[patternInput.id].every(r => r.isValid) || !validationResults[exclusionInput.id].every(r => r.isValid); @@ -347,6 +335,7 @@ textarea#${e.target.id} { patternInput.disabled = exclusionInput.disabled = applyButton.disabled = !statusCheckbox.checked; + addUrlsInCurrentTab.style.cursor = statusCheckbox.checked ? '' : 'auto'; patternInput.focus(); if (statusCheckbox.checked) {