Skip to content

Commit

Permalink
Code formatting change to increase line width to 120.
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed Jun 29, 2024
1 parent 06a1b88 commit d9eda12
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"semi": false
"semi": false,
"printWidth": 120
}
12 changes: 2 additions & 10 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ chrome.webNavigation.onCommitted.addListener(function (details) {
target: target,
})
.catch((error: unknown) => {
console.info(
"OpenBlur Could not inject CSS into tab %d",
details.tabId,
error,
)
console.info("OpenBlur Could not inject CSS into tab %d", details.tabId, error)
})
}
})
Expand All @@ -61,11 +57,7 @@ chrome.runtime.onMessage.addListener(function (request, sender) {
target: target,
})
.catch((error: unknown) => {
console.info(
"OpenBlur Could not remove CSS from tab %d",
target.tabId,
error,
)
console.info("OpenBlur Could not remove CSS from tab %d", target.tabId, error)
})
}
}
Expand Down
48 changes: 9 additions & 39 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ function unhideBody(force?: boolean) {
}
}

function processInputElement(
input: HTMLInputElement | HTMLTextAreaElement,
blurredElements: Set<HTMLElement>,
) {
function processInputElement(input: HTMLInputElement | HTMLTextAreaElement, blurredElements: Set<HTMLElement>) {
let blurTarget: HTMLElement = input
if (
performanceOptimizationMode &&
input.parentElement instanceof HTMLElement
) {
if (performanceOptimizationMode && input.parentElement instanceof HTMLElement) {
// In performance optimization mode, we may blur the parent.
const grandParent = input.parentElement
if (grandParent.style.filter.includes(blurFilter)) {
Expand Down Expand Up @@ -84,10 +78,7 @@ function processNodeWithParent(node: Node) {
let target = node
if (performanceOptimizationMode && target.parentElement) {
// We must consider the parent/grandparent in performance optimization mode.
if (
node.nodeType === Node.TEXT_NODE &&
target.parentElement.parentElement
) {
if (node.nodeType === Node.TEXT_NODE && target.parentElement.parentElement) {
// We must consider the grandparent for text nodes.
target = target.parentElement.parentElement
} else {
Expand All @@ -105,10 +96,7 @@ function processHtmlElement(
) {
if (parent?.style) {
let useGrandParent = false
if (
performanceOptimizationMode &&
parent.parentElement instanceof HTMLElement
) {
if (performanceOptimizationMode && parent.parentElement instanceof HTMLElement) {
// In performance optimization mode, we may blur the parent's parent.
const grandParent = parent.parentElement
if (grandParent.style.filter.includes(blurFilter)) {
Expand Down Expand Up @@ -157,11 +145,7 @@ function processNode(node: Node, blurredElements: Set<HTMLElement>) {
if (node instanceof HTMLElement && tagsNotToBlur.includes(node.tagName)) {
return
}
if (
node.nodeType === Node.TEXT_NODE &&
node.textContent !== null &&
node.textContent.trim().length > 0
) {
if (node.nodeType === Node.TEXT_NODE && node.textContent !== null && node.textContent.trim().length > 0) {
const text = node.textContent
processHtmlElement(node.parentElement, text, blurredElements, doFullScan)
} else if (node.nodeType === Node.ELEMENT_NODE) {
Expand Down Expand Up @@ -308,20 +292,13 @@ const observer = new MutationObserver((mutations) => {
if (performanceLogging) {
const duration = performance.now() - startTime
if (duration > 2) {
console.log(
"OpenBlur MutationObserver took %f ms for mutations",
duration,
mutations,
)
console.log("OpenBlur MutationObserver took %f ms for mutations", duration, mutations)
}
}
})

function inputEventListener(event: Event) {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement
) {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
processInputElement(event.target, new Set<HTMLElement>())
}
}
Expand Down Expand Up @@ -399,10 +376,7 @@ function setCssSelectors(selectors: string[], unblur?: boolean) {
elements.forEach((element) => {
if (element.nodeType === Node.ELEMENT_NODE) {
const elem = element as HTMLElement
elem.style.filter = elem.style.filter.replace(
blurSelectorFilter,
"",
)
elem.style.filter = elem.style.filter.replace(blurSelectorFilter, "")
}
})
} catch (error: unknown) {
Expand Down Expand Up @@ -437,11 +411,7 @@ function setCssSelectors(selectors: string[], unblur?: boolean) {
console.info("OpenBlur could not query CSS selector:", selector)
}
if (count > 0) {
console.debug(
"OpenBlur blurred %d elements with selector %s",
count,
selector,
)
console.debug("OpenBlur blurred %d elements with selector %s", count, selector)
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ function getUniquePath(element: HTMLElement): string {
if (sibling === element) {
return `${getUniquePath(element.parentElement)}/${element.tagName}[${String(siblingIndex)}]`
}
if (
sibling.nodeType === Node.ELEMENT_NODE &&
sibling.tagName === element.tagName
) {
if (sibling.nodeType === Node.ELEMENT_NODE && sibling.tagName === element.tagName) {
siblingIndex++
}
}
Expand Down
28 changes: 12 additions & 16 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ chrome.storage.sync.get(null, (data) => {

// Loop over NUMBER_OF_CSS_SELECTORS elements and listen to each one.
for (let i = 0; i < NUMBER_OF_CSS_SELECTORS; i++) {
const input = document.getElementById(
`css_selector_${String(i)}`,
) as HTMLInputElement
const input = document.getElementById(`css_selector_${String(i)}`) as HTMLInputElement
input.value = cssSelectors[i] || ""
input.addEventListener("change", (event) => {
if (event.target instanceof HTMLInputElement) {
Expand All @@ -26,19 +24,17 @@ chrome.storage.sync.get(null, (data) => {
tab.url,
)
if (tab.id !== undefined) {
chrome.tabs
.sendMessage(tab.id, { cssSelectors })
.catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
chrome.tabs.sendMessage(tab.id, { cssSelectors }).catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
}
}
})
Expand Down
59 changes: 24 additions & 35 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ chrome.storage.sync.get(null, (data) => {

// Loop over NUMBER_OF_LITERALS elements and listen to each one.
for (let i = 0; i < NUMBER_OF_LITERALS; i++) {
const input = document.getElementById(
`item_${String(i)}`,
) as HTMLInputElement
const input = document.getElementById(`item_${String(i)}`) as HTMLInputElement
input.value = literals[i] || ""
input.addEventListener("change", (event) => {
if (event.target instanceof HTMLInputElement) {
Expand All @@ -34,19 +32,17 @@ chrome.storage.sync.get(null, (data) => {
tab.url,
)
if (tab.id !== undefined) {
chrome.tabs
.sendMessage(tab.id, { literals })
.catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
chrome.tabs.sendMessage(tab.id, { literals }).catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
}
}
})
Expand All @@ -68,26 +64,19 @@ checkbox.addEventListener("change", (event) => {
.query({})
.then((tabs) => {
for (const tab of tabs) {
console.debug(
"OpenBlur Sending mode message to tab id %d, title '%s' url %s",
tab.id,
tab.title,
tab.url,
)
console.debug("OpenBlur Sending mode message to tab id %d, title '%s' url %s", tab.id, tab.title, tab.url)
if (tab.id !== undefined) {
chrome.tabs
.sendMessage(tab.id, { mode: mode })
.catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
chrome.tabs.sendMessage(tab.id, { mode: mode }).catch((error: unknown) => {
// We ignore tabs without a proper URL, like chrome://extensions/
if (tab.url) {
console.info(
"OpenBlur Could not send message to tab with title '%s' and url %s. Was OpenBlur just installed?",
tab.title,
tab.url,
error,
)
}
})
}
}
})
Expand Down

0 comments on commit d9eda12

Please sign in to comment.