Skip to content

Commit

Permalink
Merge pull request #55 from horihiro/bump-0.2.2
Browse files Browse the repository at this point in the history
Bump 0.2.2
  • Loading branch information
horihiro authored Apr 25, 2024
2 parents 8a4a21c + 86e7b95 commit d28840c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions content/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
47 changes: 18 additions & 29 deletions popup/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' });
});
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d28840c

Please sign in to comment.