From 5b2acdb1c55e2b956945218fb0d768b417ba2136 Mon Sep 17 00:00:00 2001 From: tikitiki2 Date: Fri, 12 Jan 2024 01:57:36 -0500 Subject: [PATCH 1/4] added button set default --- popup.html | 109 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/popup.html b/popup.html index d7b0226..7f4e0fc 100644 --- a/popup.html +++ b/popup.html @@ -1,50 +1,71 @@ - - + +
-
-

SoundFixer

- - -
- -
-
-
- Control individual media elements -
    -
-
-

- Note: if you get silence after touching a control, that means this extension can't do anything on this site - because the site uses cross-domain media. Because Security™ :( -

+
+

SoundFixer

+ + +
+ +
+
+ Control individual media elements +
    +
    +

    + Note: if you get silence after touching a control, that means this extension + can't do anything on this site because the site uses cross-domain media. + Because Security™ :( +

    From ba9c7bd3ad050936b0fc899c4d947395c60ec15d Mon Sep 17 00:00:00 2001 From: tikitiki2 Date: Fri, 12 Jan 2024 01:58:18 -0500 Subject: [PATCH 2/4] created style for set default button --- popup.css | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/popup.css b/popup.css index 6969abc..16f5d89 100644 --- a/popup.css +++ b/popup.css @@ -102,6 +102,19 @@ label input[type=number] { .element-reset:active { background: rgba(69, 69, 69, .3); } +label input[type=number], .element-default { + background: transparent; + color: inherit; + border-radius: 5px; + border: 1px solid #aaa; + padding: .2em .5em; +} +.element-default:focus { + outline: 1px solid; +} +.element-default:active { + background: rgba(69, 69, 69, .3); +} .header-row { display: flex; align-content: space-between; From e8f03f9cf4f48871db015bb7d873d5d228e68db6 Mon Sep 17 00:00:00 2001 From: tikitiki2 Date: Fri, 12 Jan 2024 01:58:53 -0500 Subject: [PATCH 3/4] added storage permissions --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index bc7e5ea..24ba95d 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ }, "permissions": [ "activeTab", - "webNavigation" + "webNavigation","storage" ], "browser_action": { "default_icon": "icon.svg", From df42a009ac732bf5ce941e425cf283ec0b7f2f97 Mon Sep 17 00:00:00 2001 From: tikitiki2 Date: Fri, 12 Jan 2024 01:59:32 -0500 Subject: [PATCH 4/4] added set default functionality --- popup.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/popup.js b/popup.js index 32d2db0..a3008a2 100644 --- a/popup.js +++ b/popup.js @@ -6,7 +6,32 @@ const elementsList = document.getElementById('elements-list') const allElements = document.getElementById('all-elements') const indivElements = document.getElementById('individual-elements') const elementsTpl = document.getElementById('elements-tpl') - +function storageAvailable(type) { + let storage; + try { + storage = window[type]; + const x = "__storage_test__"; + storage.setItem(x, x); + storage.removeItem(x); + return true; + } catch (e) { + return ( + e instanceof DOMException && + + (e.code === 22 || + + e.code === 1014 || + + e.name === "QuotaExceededError" || + + e.name === "NS_ERROR_DOM_QUOTA_REACHED") && + + storage && + storage.length !== 0 + ); + } + } + function applySettings (fid, elid, newSettings) { return browser.tabs.executeScript(tid, { frameId: fid, code: `(function () { const el = document.querySelector('[data-x-soundfixer-id="${elid}"]') @@ -149,20 +174,24 @@ browser.tabs.query({ currentWindow: true, active: true }).then(tabs => { flip.checked = false applySettings(fid, elid, { gain: 1, pan: 0, mono: false, flip: false }) } + elementsList.appendChild(node) elCount += 1 } } if (elCount == 0) { - allElements.innerHTML = 'No audio/video found in the current tab. Note that some websites do not work because of cross-domain security restrictions.' + allElements.innerHTML = 'No audio/video found in the current tab. Note that some websites do not work because of cross-domain security restrictions. ok' indivElements.remove() } else { + const node = document.createElement('div') node.appendChild(document.importNode(elementsTpl.content, true)) node.querySelector('.element-label').textContent = `All media on the page` const gain = node.querySelector('.element-gain') const gainNumberInput = node.querySelector('.element-gain-num') - gain.value = 1 + + + gainNumberInput.value = '' + gain.value function applyGain (value) { for (const [fid, els] of frameMap) { @@ -231,6 +260,7 @@ browser.tabs.query({ currentWindow: true, active: true }).then(tabs => { } }) node.querySelector('.element-reset').onclick = function () { + browser.storage.local.clear() gain.value = 1 gain.parentElement.querySelector('.element-gain-num').value = '' + gain.value pan.value = 0 @@ -251,6 +281,59 @@ browser.tabs.query({ currentWindow: true, active: true }).then(tabs => { } } } + node.querySelector('.element-default').onclick = function (){ + if(storageAvailable("localStorage")){ + + let gainstore=gainNumberInput.value + let panstore=panNumberInput.value + let monostore=mono.checked + let flipstore=flip.checked + browser.storage.local.set({"gain":gainstore , "pan":panstore, "mono":monostore,"flip":flipstore}) + } + else{ + //browser does not support storage very unlikely + // idk what to do here + alert("Your browser does not support local storage. Please use a different browser or enable local storage."); + } + + + } + let defaultgain=1 + let defaultpan=0 + let defaultmono=false + let defaultflip=false + // default setting code here + function onGot(item) { + + if (Object.keys(item).length === 0) { + console.log("Storage is empty"); + gain.value = defaultgain; + pan.value= defaultpan + mono.checked=defaultmono + flip.checked=defaultflip + applyPan(pan.value) + applyGain(gain.value) + } else { + gain.value = parseFloat(item["gain"]); + pan.value=parseFloat(item["pan"]); + mono.checked=item["mono"] + flip.checked=item["flip"] + applyPan(pan.value) + applyGain(gain.value) + } + } + + function onError(error) { + //error setting default value + console.log(`Error: ${error}`) + //clear storage + browser.storage.local.clear() + + } + let getitem= browser.storage.local.get(); + getitem.then(onGot).catch(onError).then( + ()=>console.log("done") + ); allElements.appendChild(node) } })