This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
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
9 changed files
with
93 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
export const renderBadge = (text, tabId) => { | ||
browser.browserAction.setBadgeText({text, tabId}) | ||
export const renderBadge = async (text, tabId) => { | ||
try { | ||
return browser.browserAction.setBadgeText({text, tabId}) | ||
} catch (error) { | ||
console.log(error) | ||
return false | ||
} | ||
} | ||
|
||
export const queryPermission = async (permission) => { | ||
try { | ||
return browser.permissions.contains({permissions: [permission]}) | ||
} catch (error) { | ||
console.log(error) | ||
return false | ||
} | ||
} | ||
|
||
export const requestPermission = async (permission) => { | ||
try { | ||
return browser.permissions.request({permissions: [permission]}) | ||
} catch (error) { | ||
console.log(error) | ||
return false | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import OptionsSync from 'webext-options-sync' | ||
|
||
export default new OptionsSync({ | ||
defaults: { | ||
enableContent: true | ||
} | ||
}) |
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,3 +1,30 @@ | ||
import OptionsSync from 'webext-options-sync'; | ||
import optionsStorage from './libs/storage' | ||
import { requestPermission } from './libs/browser' | ||
|
||
new OptionsSync().syncForm('#options-form'); | ||
optionsStorage.syncForm('#options-form') | ||
|
||
for (const inputElement of document.querySelectorAll('#options-form [name]')) { | ||
inputElement.addEventListener('change', () => { | ||
// `webext-options-sync` debounces syncing to 100ms, so send updates sometime after that | ||
setTimeout(() => { | ||
browser.runtime.sendMessage('update') | ||
}, 200) | ||
}) | ||
|
||
if (inputElement.dataset.requestPermission) { | ||
inputElement.parentElement.addEventListener('click', async event => { | ||
if (event.target !== inputElement) { | ||
return | ||
} | ||
|
||
if (inputElement.checked) { | ||
inputElement.checked = await requestPermission(inputElement.dataset.requestPermission) | ||
|
||
// Programatically changing input value does not trigger input events, so save options manually | ||
optionsStorage.set({ | ||
[inputElement.name]: inputElement.checked | ||
}) | ||
} | ||
}) | ||
} | ||
} |
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