From cbed9ba8cc3c829be0178eda227ebd3321748c4a Mon Sep 17 00:00:00 2001 From: Nandika-A Date: Mon, 8 Jan 2024 14:46:46 +0530 Subject: [PATCH] prevent closing --- manifest.json | 1 + popup.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/manifest.json b/manifest.json index 35d5698..c486141 100644 --- a/manifest.json +++ b/manifest.json @@ -4,6 +4,7 @@ "version": "1.0", "description": "Chrome extension that implements the 20 20 20 rule", "permissions": [ + "tabs", "activeTab", "storage" ], diff --git a/popup.js b/popup.js index 27b2cb3..0b62b67 100644 --- a/popup.js +++ b/popup.js @@ -9,6 +9,7 @@ var startTime; var elapsedTime = 0; var isTimerRunning = false; + function startTimer() { if (!isTimerRunning) { startTime = localStorage.getItem("startTime") || Date.now() + 20 * 60 * 1000; @@ -22,6 +23,21 @@ function startTimer() { } } +// Prevent the extension from closing on window click +window.addEventListener("click", function(event) { + event.preventDefault(); +}); + +// Prevent the extension from closing on tab switch +window.addEventListener("visibilitychange", function(event) { + event.preventDefault(); +}); + +// Keep the extension running even when the window is closed +window.addEventListener("beforeunload", function(event) { + event.preventDefault(); +}); + function updateTimer() { var currentTime = Date.now(); elapsedTime = startTime - currentTime;