-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
225 additions
and
184 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
const client = typeof browser === "undefined" ? chrome : browser; | ||
|
||
// Set access level to allow content scripts to access session storage | ||
chrome.storage.session.setAccessLevel({ accessLevel: "TRUSTED_AND_UNTRUSTED_CONTEXTS" }); | ||
//client.storage.local.setAccessLevel({ accessLevel: "TRUSTED_AND_UNTRUSTED_CONTEXTS" }); | ||
|
||
// Remove tasks if their tab is closed or updated | ||
// Success and failed tasks don't need to be removed, as they are already finished and will expire | ||
let removeTask = async (tabId) => { | ||
let task = (await chrome.storage.session.get(tabId.toString()))[tabId]; | ||
let task = (await client.storage.local.get(tabId.toString()))[tabId]; | ||
if (task?.status == "success" || task?.status == "failure") return; | ||
chrome.storage.session.remove(tabId.toString()); | ||
client.storage.local.remove(tabId.toString()); | ||
}; | ||
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { | ||
client.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { | ||
if (changeInfo.status == "loading") removeTask(tabId); | ||
}); | ||
chrome.tabs.onRemoved.addListener(async (tabId, removeInfo) => removeTask(tabId)); | ||
client.tabs.onRemoved.addListener(async (tabId, removeInfo) => removeTask(tabId)); | ||
|
||
// Remove all tasks when the browser starts (to ignore tasks from previous sessions) | ||
client.runtime.onStartup.addListener(async () => { | ||
let tasks = await client.storage.local.get(null); | ||
for (let task in tasks) { | ||
client.storage.local.remove(task); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.