aboutsummaryrefslogtreecommitdiffstats
path: root/popup.js
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-05-20 00:50:25 -0700
committerPinapelz <yukais@pinapelz.com>2025-05-20 00:50:25 -0700
commit3c239a83f6cba3eb7a602b7b2e3b83d90c8def51 (patch)
tree68fd22cc582749f02fe657f6bafd72707466549e /popup.js
parent85eacdbb3e6518a92ebc521af0c8a62e72deedd6 (diff)
implement per-video auto save
Diffstat (limited to 'popup.js')
-rw-r--r--popup.js28
1 files changed, 23 insertions, 5 deletions
diff --git a/popup.js b/popup.js
index 649720a..60c2cfe 100644
--- a/popup.js
+++ b/popup.js
@@ -1,7 +1,10 @@
+// Dynamically detect the browser API
+const browserAPI = typeof browser !== 'undefined' ? browser : chrome;
+
document.getElementById('activate').addEventListener('click', () => {
- browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
+ browserAPI.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0].url.includes('youtube.com/watch')) {
- browser.scripting.executeScript({
+ browserAPI.scripting.executeScript({
target: { tabId: tabs[0].id },
files: ['content-script.js']
});
@@ -11,10 +14,25 @@ document.getElementById('activate').addEventListener('click', () => {
document.getElementById('offset').addEventListener('input', () => {
const offset = parseInt(document.getElementById('offset').value, 10);
- browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
- browser.tabs.sendMessage(tabs[0].id, { type: 'SET_OFFSET', offset: offset });
+ console.log(offset)
+ browserAPI.tabs.query({ active: true, currentWindow: true }, (tabs) => {
+ browserAPI.tabs.sendMessage(tabs[0].id, { type: 'SET_OFFSET', offset: offset });
localStorage.setItem('offset', offset);
});
});
-localStorage.getItem('offset') !== null ? document.getElementById('offset').value = localStorage.getItem('offset') : document.getElementById('offset').value = 5; \ No newline at end of file
+document.getElementById('autosave').addEventListener('input', () => {
+ const autosaveStatus = document.getElementById('autosave').checked;
+ browserAPI.tabs.query({ active: true, currentWindow: true }, (tabs) => {
+ browserAPI.tabs.sendMessage(tabs[0].id, { type: 'SET_AUTOSAVE', autosave: autosaveStatus });
+ localStorage.setItem('autosave', autosaveStatus);
+ });
+});
+
+localStorage.getItem('offset') !== null
+ ? document.getElementById('offset').value = localStorage.getItem('offset')
+ : document.getElementById('offset').value = 5;
+
+ localStorage.getItem('autosave') !== null
+ ? document.getElementById('autosave').checked = (localStorage.getItem('autosave') === 'true')
+ : document.getElementById('autosave').checked = true;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage