Skip to content

Commit

Permalink
move the betafeatures check to global.ts so that its more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Jun 10, 2024
1 parent c6a6ada commit 06ef3d8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
50 changes: 33 additions & 17 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,25 +1546,41 @@ export async function main(
},
})
}
const imageElements = document.getElementsByTagName('img')

const disabledServices = [
'https://www.facebook.com/',
'https://www.instagram.com/',
'https://www.pinterest.com/',
]
const betaFeatureSetting = await syncSettings.betaFeatures.get(
'imageOverlay',
)

if (
imageElements.length > 0 &&
!disabledServices.some((url) => fullPageUrl.includes(url))
) {
inPageUI.loadOnDemandInPageUI({
component: 'img-action-buttons',
options: {
imageElements,
contentScriptsBG,
},
})
let imageInjectionEnabled = null
if (betaFeatureSetting != null) {
imageInjectionEnabled = betaFeatureSetting
}

if (imageInjectionEnabled == null) {
await syncSettings.betaFeatures.set('imageOverlay', false)
}

if (imageInjectionEnabled) {
const imageElements = document.getElementsByTagName('img')

const disabledServices = [
'https://www.facebook.com/',
'https://www.instagram.com/',
'https://www.pinterest.com/',
]

if (
imageElements.length > 0 &&
!disabledServices.some((url) => fullPageUrl.includes(url))
) {
inPageUI.loadOnDemandInPageUI({
component: 'img-action-buttons',
options: {
imageElements,
contentScriptsBG,
},
})
}
}

// Function to track when the subscription has been updated by going to our website (which the user arrives through a redirect)
Expand Down
16 changes: 0 additions & 16 deletions src/search-injection/img-action-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,6 @@ export const handleRenderImgActionButtons = async (
imageElements: HTMLCollectionOf<HTMLImageElement>,
contentScriptsBG: ContentScriptsInterface<'caller'>,
) => {
const betaFeatureSetting = await syncSettings.betaFeatures.get(
'imageOverlay',
)
let imageInjectionEnabled = null
if (betaFeatureSetting != null) {
imageInjectionEnabled = betaFeatureSetting
}

if (imageInjectionEnabled == null) {
await syncSettings.betaFeatures.set('imageOverlay', false)
}

if (!imageInjectionEnabled) {
return
}

let shouldShow = true
if (imageElements.length === 0) {
return
Expand Down

0 comments on commit 06ef3d8

Please sign in to comment.