-
Notifications
You must be signed in to change notification settings - Fork 0
/
nerblock-popup.js
103 lines (95 loc) · 2.88 KB
/
nerblock-popup.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
if (typeof chrome.runtime === "undefined") chrome = browser;
var bgpage = chrome.extension.getBackgroundPage();
chrome.tabs.query(
{ active: true, currentWindow: true },
function callback(tabs) {
var currentTab = tabs[0];
var total = 0;
var keys = Object.keys(bgpage.nerSites);
for (var i = 0; i < keys.length; i++) {
total += bgpage.nerSites[keys[i]].length;
}
$("#total_blocked_count").html(total);
if (typeof bgpage.tabBlocks[currentTab.id] !== "undefined") {
$("#page_blocked_count").html(
bgpage.tabBlocks[currentTab.id].blocks.length
);
}
$("#block_counts").show();
$("#separator0").show();
$("#closeButton").click(closePopOut);
$("#show_blocklist").click(function () {
if (chrome.runtime.openOptionsPage) {
chrome.runtime.openOptionsPage();
} else {
window.open(chrome.runtime.getURL("nerblock-options.html"));
}
closePopOut();
});
if (bgpage.globalPause) {
$("#div_global_unpause_nerblock")
.show()
.click(function () {
bgpage.globalPause = false;
bgpage.reloadAllTabs();
closePopOut();
});
} else {
$("#div_global_pause_nerblock")
.show()
.click(function () {
bgpage.globalPause = true;
bgpage.reloadAllTabs();
closePopOut();
});
if (bgpage.tabPauses[currentTab.id]) {
$("#div_tab_unpause_nerblock")
.show()
.click(function () {
bgpage.tabPauses[currentTab.id] = false;
chrome.tabs.reload({ bypassCache: true });
closePopOut();
});
} else {
$("#div_tab_pause_nerblock")
.show()
.click(function () {
var reloadurl = false;
if (bgpage.tabBlocks[currentTab.id].blocks.length > 0) {
for (
var i = 0;
i < bgpage.tabBlocks[currentTab.id].blocks.length;
i++
) {
if (
bgpage.tabBlocks[currentTab.id].blocks[i].type == "main_frame"
) {
reloadurl = bgpage.tabBlocks[currentTab.id].blocks[i].url;
break;
}
}
}
bgpage.tabPauses[currentTab.id] = true;
if (reloadurl) {
chrome.tabs.update(currentTab.id, { url: reloadurl });
} else {
chrome.tabs.reload({ bypassCache: true });
}
closePopOut();
});
}
}
}
);
function closePopOut() {
var gettingInfo = chrome.runtime.getPlatformInfo(function gotPlatformInfo(
info
) {
var isFirefox = typeof InstallTrigger !== "undefined";
if (isFirefox && info.os == chrome.runtime.PlatformOs.ANDROID) {
chrome.tabs.update({ active: true });
} else {
window.close();
}
});
}