-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
64 lines (56 loc) · 2.64 KB
/
background.js
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
"use strict";
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ "def_text_param": ";1.5;1.3;1.1;1;0.9;0.7;1.1;0;0;1;0;0;100;0;0;0;" });
chrome.storage.local.set({ "list_domain": "" });
chrome.storage.local.set({ "interface_param": "1;0;100;100;" });
chrome.storage.local.set({ "font_param": "0;0;0;0;0;0;0;0;;" });
});
function url_tab() {
chrome.storage.local.get(['list_domain', 'interface_param'], function(result) {
chrome.tabs.query({ lastFocusedWindow: true, active: true }, function(tabs) {
try {
let arr = result.interface_param.split(";");
var cd = tabs[0].url.split(/\/+/)[1];
if (tabs[0].url.includes("chrome://") || (tabs[0].url.includes("http://") == false && tabs[0].url.includes("https://") == false)) {
chrome.action.setIcon({ path: { "48": "/icons/icon_red.png" } });
chrome.action.setBadgeText({ text: '' });
return;
}
if (Number(arr[0]) == 1) {
var dom_list = (result.list_domain).replace(/\s+/g, '');
var k = dom_list.indexOf(";" + cd + ";");
if (k !== -1) {
var arr2 = (dom_list.slice(k, dom_list.indexOf("|", k))).split(";");
chrome.tabs.getZoom(function(zoomFactor) {
if (Number(arr2[18]) !== zoomFactor) {
chrome.tabs.setZoom(Number(arr2[18]));
}
});
chrome.action.setIcon({ path: { "48": "/icons/icon_green.png" } });
} else {
chrome.action.setIcon({ path: { "48": "/icons/icon_blue.png" } });
}
}
if (Number(arr[1]) == 1) {
chrome.tabs.getZoom(function(zoomFactor) {
chrome.action.setBadgeText({ text: String(Math.round(zoomFactor * 100)) });
});
}
} catch { return }
});
});
}
function zoomChangeListener(zoomChangeInfo) {
setTimeout(function() { url_tab(); }, 300);
}
chrome.tabs.onActivated.addListener((activeInfo) => {
setTimeout(function() { url_tab(); }, 300);
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
setTimeout(function() { url_tab(); }, 300);
});
chrome.tabs.onRemoved.addListener((removeInfo) => {
setTimeout(function() { url_tab(); }, 300);
});
chrome.tabs.onZoomChange.addListener(zoomChangeListener);
chrome.storage.onChanged.addListener(zoomChangeListener);