Skip to content

Commit

Permalink
Change the nudges to only trigger after 30s activity time on a page a…
Browse files Browse the repository at this point in the history
…nd change copy
  • Loading branch information
blackforestboi committed Jun 10, 2024
1 parent 06ef3d8 commit 306e12c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,13 +1654,23 @@ export async function main(

// Function to track when to show the nudges
let tabOpenedTime = Date.now()
let activeTabTime = 0
let lastActiveTime = Date.now()

document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
tabOpenedTime = Date.now() // Resume timing from last active moment
} else {
lastActiveTime = Date.now()
activeTabTime += lastActiveTime - tabOpenedTime // Update active time
}
})

async function checkScrollPosition() {
const scrollPosition = window.scrollY
const pageHeight = document.documentElement.scrollHeight
const elapsedTime = Date.now() - tabOpenedTime

if (scrollPosition > 0.3 * pageHeight && elapsedTime > 10000) {
if (scrollPosition > 0.3 * pageHeight && activeTabTime > 30000) {
const shouldShow = await updateNudgesCounter(
'bookmarksCount',
browser,
Expand Down
2 changes: 1 addition & 1 deletion src/util/nudges-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function renderNudgeTooltip(
<NudgeBottomNote>
<PrimaryAction
onClick={snoozeNudge}
label={'Remind me again'}
label={'Remind me later'}
type={'secondary'}
size={'small'}
padding={'2px 6px'}
Expand Down

0 comments on commit 306e12c

Please sign in to comment.