-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbackground.js
More file actions
28 lines (25 loc) · 1.08 KB
/
background.js
File metadata and controls
28 lines (25 loc) · 1.08 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
var isEnabled = true;
chrome.storage.sync.get(/* String or Array */["ar5iv_enabled"], function(result){
isEnabled = result.ar5iv_enabled;
});
const setIcon = function(){
chrome.action.setIcon({path: isEnabled ? "icon128.png" : "icon_nope128.png"});
}
const storeSetting = function(){
chrome.storage.sync.set({ar5iv_enabled: isEnabled}, function(){});
}
// When the extension icon is clicked, switch back to pdf / ar5iv
var switch_view = function(tab) {
if (!isEnabled) { // arxiv -> ar5iv
chrome.declarativeNetRequest.updateEnabledRulesets({enableRulesetIds: ["arxiv_to_ar5iv"], disableRulesetIds: ["ar5iv_to_arxiv"]}, function() {});
} else { // ar5iv -> arxiv
chrome.declarativeNetRequest.updateEnabledRulesets({enableRulesetIds: ["ar5iv_to_arxiv"], disableRulesetIds: ["arxiv_to_ar5iv"]});
}
isEnabled ^= true;
setIcon();
storeSetting();
if (tab.url.match(/^https:\/\/(www\.)?(ar5iv\.labs\.)?ar(x|5)iv\.org\/((pdf)|(html))/)) {
chrome.tabs.reload(tab.id);
}
}
chrome.action.onClicked.addListener(tab => switch_view(tab));