-
Notifications
You must be signed in to change notification settings - Fork 0
/
adblock-uiscripts-top_open_blacklist_ui.js
240 lines (220 loc) · 10.1 KB
/
adblock-uiscripts-top_open_blacklist_ui.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* This file is part of AdBlock <https://getadblock.com/>,
* Copyright (C) 2013-present Adblock, Inc.
*
* AdBlock is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* AdBlock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AdBlock. If not, see <http://www.gnu.org/licenses/>.
*/
/* For ESLint: List any global identifiers used in this file below */
/* global browser, translate, BlacklistUi, bindEnterClickToDefault, mayOpenDialogUi:true,
setLangAndDirAttributes, rightClickedItem:true, loadWizardResources,
isLangRTL */
// Global lock so we can't open more than once on a tab.
if (typeof window.mayOpenDialogUi === 'undefined') {
window.mayOpenDialogUi = true;
}
// This script is injected each time the white list wizard is selected. Until we switch to ES6
// modules (aka import) we need to protect the code in a namespace so classes aren't declared
// multiple times.
/* eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars */
function topOpenBlacklistUI(options) {
// DragElement makes a given DOM element draggable. It assumes the element is positioned
// absolutely and adjusts the element's `top` and `left` styles directly.
// Inputs:
// - el : DOM element that activates dragging on mousedown (e.g. wizard header)
// - elementToDrag : DOM element that should drag while dragging (e.g. entire wizard)
class DragElement {
constructor(el, elementToDrag) {
this.pos1 = 0;
this.pos2 = 0;
this.pos3 = 0;
this.pos4 = 0;
this.el = elementToDrag;
this.dragging = false;
this.activationElement = el;
if (document.getElementById(`${el.d}header`)) {
document.getElementById(`${el.id}header`).onmousedown = this.dragMouseDown.bind(this);
} else {
this.activationElement.onmousedown = this.dragMouseDown.bind(this);
}
}
dragMouseDown(e) {
const event = e || window.event;
event.preventDefault();
this.pos3 = event.clientX;
this.pos4 = event.clientY;
this.dragging = true;
document.onmouseup = this.closeDragElement.bind(this);
document.onmousemove = this.elementDrag.bind(this);
}
elementDrag(e) {
const event = e || window.event;
event.preventDefault();
// calculate the new cursor position:
this.pos1 = this.pos3 - event.clientX;
this.pos2 = this.pos4 - event.clientY;
this.pos3 = event.clientX;
this.pos4 = event.clientY;
// set the element's new position:
this.el.style.top = `${this.el.offsetTop - this.pos2}px`;
this.el.style.left = `${this.el.offsetLeft - this.pos1}px`;
}
closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
this.dragging = false;
}
}
if (!mayOpenDialogUi) {
return;
}
mayOpenDialogUi = false;
// Get Flash objects out of the way of our UI
browser.runtime.sendMessage({ command: 'sendContentToBack' });
// A empty base <div> is appended to the page's DOM and then a shadow is hosted in it.
// The shadow protects our dialog from outside CSS 'leaking' in.
// Existing page styles are reset in the shadow/base at the top of `adblock-wizard.css`
// using `:host` to select our base and the CCS rule `all:initial;` to perform the reset.
const base = document.createElement('div');
const $base = $(base.attachShadow({ mode: 'open' }));
loadWizardResources($base, () => {
// If they chose 'Block an ad on this page...' ask them to click the ad
if (options.nothingClicked) {
rightClickedItem = null;
}
// If they right clicked in a frame in Chrome, use the frame instead
if (options.info && options.info.frameUrl) {
const frame = $('iframe').filter((i, el) => el.src === options.info.frameUrl);
if (frame.length === 1) {
rightClickedItem = frame.get(0);
}
}
if (rightClickedItem && rightClickedItem.nodeName === 'BODY') {
rightClickedItem = null;
}
// check if we're running on website with a frameset, if so, tell
// the user we can't run on it.
if ($('frameset').length >= 1) {
// eslint-disable-next-line no-alert
alert(translate('wizardcantrunonframesets'));
mayOpenDialogUi = true;
return;
}
const html = `
<div id='hiding-wizard'>
<div class='page' id='page_0'>
<header class="center-and-right">
<h1>${translate('blockanadtitle')}</h1>
<i class="material-icons md-18 close" role="img" aria-label="${translate('close')}">close</i>
</header>
<section>
<p>${translate('clickthead')}</p>
</section>
</div>
<div class='page' id='page_1' style='display:none;'>
<header class="left-center-right">
<i class="material-icons md-18 back" role="img" aria-label="${translate('back')}">chevron_left</i>
<h1>${translate('blockanadtitle')}</h1>
<i class="material-icons md-18 close" role="img" aria-label="${translate('close')}">close</i>
</header>
<section>
<p class="boldText">${translate('isithidden')}</p>
<p class="advanced-user-row" >${translate('blacklisterblockedelement')}</p>
<p class="advanced-user-row" id='selected-data'>
<span id='selected_node_name'></span>
</p>
<p>${translate('sliderexplanation')}</p>
<input id='slider' type='range' min='0' value='0'/>
<p class="warningText non-advanced-user-text">${translate('sliderwarning')}</p>
<div class="buttonRow" ><button class='primary looks-good adblock-default-button'>${translate('buttonlooksgood')}</button></div>
</section>
</div>
<div class='page' id='page_2' style='display:none;'>
<header class="left-center-right">
<i class="material-icons md-18 back" role="img" aria-label="${translate('back')}">chevron_left</i>
<h1>${translate('blockanadtitle')}</h1>
<i class="material-icons md-18 close" role="img" aria-label="${translate('close')}">close</i>
</header>
<section>
<p class="boldText">${translate('blacklisteroptions1')}</p>
<p class="advanced-user-row" >
<input id="txtAdvanceFilter" type="text" disabled="true" />
<span id="editBtnSpan">
<i id="editBtn" class="material-icons md-18" role="img" aria-label="${translate('buttonedit')}">mode_edit</i>
</span>
</p>
<p class="filter-warning-row" >
<span id="warningIconSpan"><i id="warningIcon" class="material-icons md-18 warning-icon" role="img" aria-label="${translate('warning')}">warning</i></span><span id='filter-warning-text' ></span>
</p>
<p class="advanced-user-row advanced-user-row-disarm boldText detail-header" id="add_info">${translate('add_info')}</p>
<p class="advanced-user-row advanced-user-row-disarm detail-header" >${translate('confirm_msg')}</p>
<div id='adblock-details'></div>
<div id='summary'></div>
<p>${translate('blacklisternotsure_part_I')} <span class="non-advanced-user-text">${translate('blacklisternotsure_part_II')}</span></p>
<p id="countRow"><span id="count"></span> ${translate('hiddenelementmessagecount')} <i id="helpIcon" class="material-icons md-18" role="img" aria-label="${translate('learn_more_without_period')}">live_help</i></p>
<div class="buttonRow" ><button class='primary confirm adblock-default-button'>${translate('buttonconfirm')}</button></div>
</section>
</div>
<div class='page' id='page_3' style='display:none;'>
<header class="center-and-right">
<h1>${translate('adblock_premium')}</h1>
<i class="material-icons md-18 close" role="img" aria-label="${translate('close')}">close</i>
</header>
<section>
<span style="display: flex; flex-direction: column;">
<span style="font-size: 18px; font-weight: bold;">${translate('wizard_premium_cta_title')}</span>
<span style="margin-top: 22px;">${translate('wizard_premium_cta_part_I')} ${translate('wizard_premium_cta_part_II')}</span>
</span>
<img aria-hidden='true' src='${browser.runtime.getURL('adblock-wizard_sync_cta.svg')}' style="height: 200px; width: 245px;">
</section>
<hr />
<footer id='blacklist-cta' >
<button id='find_out_more' class='btnClose'>${translate('find_out_more')}</button>
<span id='opt-out-msg' class='btnClose'>${translate('dont_show_me_again')}</span>
</footer>
</div>
</div>
`;
const $dialog = $(html);
// Make any right-to-left translation
if (isLangRTL()) {
$dialog.find('i.back').text('chevron_right');
}
$dialog.find('header').each((i, header) => {
// eslint-disable-next-line no-new
new DragElement(header, $dialog.get(0));
});
$dialog.find('i.close,.btnClose').on('click', () => {
mayOpenDialogUi = true;
(document.body || document.documentElement).removeChild(base);
});
setLangAndDirAttributes($dialog.get(0));
bindEnterClickToDefault($dialog);
$base.append($dialog);
const blacklistUI = new BlacklistUi(rightClickedItem, options.settings.show_advanced_options,
options.isActiveLicense, options.showBlacklistCTA, $dialog,
options.addCustomFilterRandomName);
blacklistUI.cancel(() => {
mayOpenDialogUi = true;
});
blacklistUI.block(() => {
mayOpenDialogUi = true;
});
blacklistUI.show();
});
(document.body || document.documentElement).appendChild(base);
}
// required return value for tabs.executeScript
/* eslint-disable-next-line no-unused-expressions */
'';
//# sourceURL=/uiscripts/top_open_blacklist_ui.js