-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadblock-uiscripts-top_open_whitelist_completion_ui.js
154 lines (134 loc) · 6 KB
/
adblock-uiscripts-top_open_whitelist_completion_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
/*
* 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, bindEnterClickToDefault, mayOpenDialogUi:true, i18nJoin,
processReplacementChildrenInContent, setLangAndDirAttributes, loadWizardResources */
// 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 completed. Until we switch to ES6
// modules (aka import) we need to protect the code in a namespace so classes aren't declared
// multiple times.
// topOpenWhitelistUI displays the whitelist wizard completion page if it's not already open.
// See README for details.
/* eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars */
function topOpenWhitelistCompletionUI(options) {
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 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, () => {
// 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="wizard">
<header >
<img aria-hidden="true" src="${browser.runtime.getURL('/icons/icon24.png')}">
<h1 >${translate('whitelistertitle2')}</h1>
</header>
<section>
<div class='messageWithLink' i18n_replacement_el='settings-link'>
${i18nJoin('successfully_whitelisted', 'future_show_ads', 'change_behavior_settings')}
<a id='settings-link' class='link' href='#'></a>
</div>
</section>
<section >
<div>${translate('adblock_wont_run_on_pages_matching')}</div>
<div dir="ltr" id="adblock-rule"></div>
</section>
<section class='body-button'>
<button class='cancel'>${translate('done')}</button>
</section>
<footer id='whitelist-cta' style='display:none;'>
<div id='dismissed-msg' class='messageWithLink' i18n_replacement_el='premium-link' style='display:none;'>
${i18nJoin('wont_show_again', 'check_out_premium')}
<a id='premium-link' class='link' href='#'></a>
</div>
<div id='premium-cta'>
<div id='cta-msg'>${i18nJoin('whitelisted_a_site', 'never_lose_settings')}</div>
<div id='cta-buttons'>
<button class='learn-more'>${translate('learn_more_without_period')}</button>
<button class='close material-icons'>close</button>
</div>
</div>
</footer>
</div>
`;
const $dialog = $(html);
const $adblockRule = $dialog.find('#adblock-rule');
const $doneBtn = $dialog.find('button.cancel');
const $learnMoreBtn = $dialog.find('button.learn-more');
const $closeBtn = $dialog.find('button.close');
const $settingsLink = $dialog.find('#settings-link');
const $premiumLink = $dialog.find('#premium-link');
const $dismissedMsg = $dialog.find('#dismissed-msg');
const $premiumCTA = $dialog.find('#premium-cta');
$adblockRule.text(options.rule || '');
$doneBtn.on('click', () => {
mayOpenDialogUi = true;
(document.body || document.documentElement).removeChild(base);
});
$learnMoreBtn.on('click', () => {
browser.runtime.sendMessage({ command: 'openPremiumPayURL' });
browser.runtime.sendMessage({ command: 'recordGeneralMessage', msg: 'whitelist_cta_clicked' });
});
$closeBtn.on('click', () => {
browser.runtime.sendMessage({ command: 'setWhitelistCTAStatus', isEnabled: false });
browser.runtime.sendMessage({ command: 'recordGeneralMessage', msg: 'whitelist_cta_closed' });
$premiumCTA.hide();
$dismissedMsg.show();
});
$settingsLink.on('click', () => {
browser.runtime.sendMessage({ command: 'openTab', urlToOpen: browser.runtime.getURL('options.html#customize') });
});
$premiumLink.on('click', () => {
browser.runtime.sendMessage({ command: 'openTab', urlToOpen: browser.runtime.getURL('options.html#mab') });
});
$dialog.find('.messageWithLink').each(function replaceLinks() {
processReplacementChildrenInContent($(this));
});
setLangAndDirAttributes($dialog.get(0));
bindEnterClickToDefault($dialog);
// Check whether to show CTA
if (!options.isActiveLicense && options.showWhitelistCTA) {
$dialog.find('#whitelist-cta').show();
browser.runtime.sendMessage({ command: 'recordGeneralMessage', msg: 'whitelist_cta_seen' });
}
// Show page
$base.append($dialog);
});
(document.body || document.documentElement).appendChild(base);
}
// required return value for tabs.executeScript
/* eslint-disable-next-line no-unused-expressions */
'';
//# sourceURL=/uiscripts/top_open_whitelist_ui.js