-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (32 loc) · 1013 Bytes
/
Copy pathbackground.js
File metadata and controls
32 lines (32 loc) · 1013 Bytes
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
const URL = /^https:\/\/codeforces.com\/*/;
chrome.tabs.onActivated.addListener((tab) => {
chrome.tabs.get(tab.tabId, (currentTab) => {
if (URL.test(currentTab.url)) {
chrome.scripting.executeScript({
target: { tabId: tab.tabId },
files: ["./content-scripts/content-script.js"],
});
chrome.scripting.insertCSS({
target: { tabId: tab.tabId },
files: ["./content-scripts/content-css.css"],
});
}
});
});
function getValueFromStorage(key, cb) {
chrome.storage.sync.get([key],(result)=>{
if (cb&&result) cb(JSON.parse(result[key]));
});
}
function setValueToStorage(key, value) {
chrome.storage.sync.set({ [key]: JSON.stringify(value)});
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse)=>{
if(request.type==="GET_DATA"){
getValueFromStorage(request.key,sendResponse);
}else if(request.type==="SET_DATA"){
setValueToStorage(request.key,request.value);
}
return true;
}
);