Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
73 lines (67 loc) · 1.96 KB
/
Copy pathbackground.js
File metadata and controls
73 lines (67 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
try {
importScripts('/global.js');
} catch (e) {
console.error(e);
}
chrome.runtime.onInstalled.addListener(() => {
setIconAccordingToStateInStorage();
});
chrome.action.onClicked.addListener(tab => {
setIconAccordingToStateInStorage(true);
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['scripts/toggleStateOnIconClick.js'],
});
});
chrome.contextMenus.create({
id: 'bioinze_feedback',
title: 'Feedback 💬 ',
contexts: ['action'],
});
chrome.contextMenus.create({
id: 'bioinze_feature_wishlist',
title: 'Feature wishlist 🗒 ',
contexts: ['action'],
});
chrome.contextMenus.create({
id: 'bioinze_buy_coffee',
title: 'Buy us a coffee ☕️ ',
contexts: ['action'],
});
chrome.contextMenus.onClicked.addListener(info => {
switch (info.menuItemId) {
case 'bioinze_feedback':
chrome.tabs.create({ url: 'https://0zitr0ubvu5.typeform.com/to/DLyGSj12' });
break;
case 'bioinze_feature_wishlist':
chrome.tabs.create({ url: 'https://bionize.nolt.io/' });
break;
case 'bioinze_buy_coffee':
chrome.tabs.create({ url: 'https://www.buymeacoffee.com/squareone' });
break;
}
});
/**
*
* @param {boolean} isInverted Pass `true` if updating user toggled state but storage hasn't been updated yet
*/
function setIconAccordingToStateInStorage(isInverted) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
// NOTE: This will only toggle the state for the currently active tab in the currently active browser window
// If the user has multiple windows with the current tab
const tab = tabs[0];
const storageKey = getStorageKey(tab.url);
chrome.storage.sync.get([storageKey], result => {
const isTurnedOn = result[storageKey];
chrome.action.setIcon({
path: `assets/${
(isInverted ? !isTurnedOn : isTurnedOn) ? 'state_active' : 'state_inactive'
}.png`,
tabId: tab.id,
});
});
});
}
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
setIconAccordingToStateInStorage();
});