-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.html
145 lines (124 loc) · 4.71 KB
/
popup.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="jquery-ui/css/smoothness/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<style type="text/css" media="screen">
body {
font-size: 75%;
font-family: Helvetica, Arial, sans-serif;
min-width: 170px;
background: #ffffff;
color: #000000;
}
a { text-decoration: none }
a:hover { color: #eeeeff }
#filtersList {
border: 1px dotted gray;
padding: 1px;
font-size: 75%;
display: none;
}
.ui-button {
padding: 3px;
}
.spacer {
height: 7px;
width: 5px;
display: block;
}
</style>
<script type="text/javascript" src="i18n.js"></script>
<script type="text/javascript" charset="utf-8">
function dbg(msg) {
document.getElementById("debugmsg").innerHTML = msg;
}
function init() {
// Fill in i18n strings
loadI18nStrings();
// Ask content script whether clickhide is active. If so, show cancel button.
// If that isn't the case, ask background.html whether it has cached filters. If so,
// ask the user whether she wants those filters.
// Otherwise, we are in default state.
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(tab) {
chrome.extension.sendRequest({reqtype: "get-cached-filters"}, function(response2) {
if(response2.active) {
clickHideActiveStuff();
} else
clickHideInactiveStuff();
});
});
});
chrome.extension.sendRequest({reqtype: "get-domain-enabled-state"}, function(response) {
document.getElementById("enabled").checked = response.enabled;
document.getElementById("enabledCheckboxAndLabel").style.display = "block";
});
chrome.extension.sendRequest({reqtype: "refresh-page-icon"});
}
function addFilters() {
filters = [];
// background.html saved the filters for us
chrome.extension.sendRequest({reqtype: "apply-cached-filters", filters: filters});
clickHideInactiveStuff();
// Tell content script to nuke that element
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(tab) {
chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"});
chrome.tabs.sendRequest(tab.id, {reqtype: "remove-ads-again"});
});
});
document.getElementById("mustReloadMsg").style.display = "block";
}
function toggleEnabled() {
// Rely on background.html to divine what domain is in the current tab
var checked = document.getElementById("enabled").checked;
chrome.extension.sendRequest({reqtype: "set-domain-enabled-state", enabled: checked});
}
function activateClickHide() {
clickHideActiveStuff();
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(tab) {
chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"});
// Close the popup after a few seconds, so user doesn't have to
setTimeout(window.close, 5000);
});
});
}
function cancelClickHide() {
// Tell background.html to toss its clickhide filters
chrome.extension.sendRequest({reqtype: "cache-filters", filters: null});
clickHideInactiveStuff();
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(tab) {
chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"})
});
});
}
function clickHideActiveStuff() {
document.getElementById("enabledCheckboxAndLabel").style.display = "none";
document.getElementById("clickHideInactiveStuff").style.display = "none";
document.getElementById("clickHideActiveStuff").style.display = "inherit";
}
function clickHideInactiveStuff() {
document.getElementById("enabledCheckboxAndLabel").style.display = "block";
document.getElementById("clickHideActiveStuff").style.display = "none";
document.getElementById("clickHideInactiveStuff").style.display = "inherit";
}
</script>
</head>
<body id="main" onload="init()">
<div id="enabledCheckboxAndLabel" style="display:none"><input id="enabled" type="checkbox" checked onClick="toggleEnabled()"><label for="enabled"><span class="i18n_enabled_for_site"></span></label></div>
<div id="mustReloadMsg" style="display:none"><span class="i18n_new_filters_added"></span></div>
<div id="clickHideInactiveStuff" style="display: none">
<div class="spacer"></div>
<button id="clickHideButton" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onClick="activateClickHide()"><span class="i18n_easy_create_filter"></span></button>
</div>
<div id="clickHideActiveStuff" style="display: none">
<div id="clickHideMsg"><span class="i18n_clickhide_instructions"></span></div>
<div class="spacer"></div>
<button id="cancelButton" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onClick="cancelClickHide()"><span class="i18n_cancel"></span></button>
</div>
</div>
</body>
</html>