-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadblock-options-support.js
169 lines (154 loc) · 6.34 KB
/
adblock-options-support.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
/*
* 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, selected, browser, determineUserLanguage, initializeProxies, send */
$(async () => {
await initializeProxies();
const resetCheckmark = function () {
$('#checkmark-circle-checkmark').removeClass('checkmark').removeClass('draw');
$('#checkmark-circle').removeClass('checkmark-circle').addClass('do-not-display');
$('#checkmark-circle').css('display', ''); // remove the "display: none;" style property that was set during fadeOut()
};
const observer = new MutationObserver(((mutations) => {
for (const mutation of mutations) {
if ($('#support').is(':visible') && mutation.attributeName === 'style') {
resetCheckmark();
$('#btnCopyDebugData').removeClass('green').addClass('red');
$('#copiedDebugData').addClass('do-not-display');
$('#copyDebugData').show();
}
}
}));
const target = document.querySelector('#support');
observer.observe(target, {
attributes: true,
});
if (!determineUserLanguage().startsWith('en')) {
$('.english-only').removeClass('do-not-display');
}
// Show debug info
let debugInfo = null;
const showDebugInfo = function () {
$('#debugInfo').text(debugInfo).fadeIn();
document.getElementById('debugInfo').select();
document.execCommand('copy');
$('#btnCopyDebugData').addClass('green').removeClass('red');
$('#checkmark-circle-checkmark').addClass('checkmark').addClass('draw');
$('#checkmark-circle').addClass('checkmark-circle').removeClass('do-not-display');
$('#copyDebugData').hide();
$('#copiedDebugData').removeClass('do-not-display');
setTimeout(() => {
$('#checkmark-circle').fadeOut(400, () => {
resetCheckmark();
});
}, 2500);
};
selected('#btnCopyDebugData', async () => {
// Get debug info
const theDebugInfo = await send('getDebugInfo');
const content = [];
if (theDebugInfo.subscriptions) {
content.push('=== Filter Lists ===');
for (const sub in theDebugInfo.subscriptions) {
content.push(`Id:${sub}`);
content.push(` Download Status: ${theDebugInfo.subscriptions[sub].downloadStatus}`);
content.push(` Last Download: ${theDebugInfo.subscriptions[sub].lastDownload}`);
content.push(` Last Success: ${theDebugInfo.subscriptions[sub].lastSuccess}`);
}
}
content.push('');
if (theDebugInfo.exclude_filters) {
content.push('=== Exclude Filters ===');
content.push(JSON.stringify(theDebugInfo.exclude_filters));
}
// Custom & Excluded filters might not always be in the object
if (theDebugInfo.customFilters) {
content.push('=== Custom Filters ===');
content.push(theDebugInfo.customFilters);
content.push('');
}
content.push('=== Settings ===');
for (const setting in theDebugInfo.settings) {
content.push(`${setting} : ${theDebugInfo.settings[setting]}`);
}
content.push('');
content.push('=== Other Info ===');
content.push(JSON.stringify(theDebugInfo.otherInfo, null, '\t'));
content.push('');
content.push('=== IPM Info ===');
content.push(JSON.stringify(theDebugInfo.ipmInfo, null, '\t'));
// Put it together to put into the textbox
debugInfo = content.join('\n');
if (
browser.runtime.getManifest().optional_permissions
&& browser.runtime.getManifest().optional_permissions.includes('management')
) {
browser.permissions.request({
permissions: ['management'],
}).then((granted) => {
// The callback argument will be true if the user granted the permissions.
if (granted) {
// since the management.getAll function is not available when the page is loaded
// the function is not wrapped by the polyfil Promise wrapper
// so we create, and load a temporary iFrame after the permission is granted
// so the polyfil will correctly wrap the now available API
const iframe = document.createElement('iframe');
iframe.onload = () => {
const proxy = iframe.contentWindow.browser;
proxy.management.getAll().then((result) => {
const extInfo = [];
extInfo.push('==== Extension and App Information ====');
for (let i = 0; i < result.length; i++) {
extInfo.push(`Number ${i + 1}`);
extInfo.push(` name: ${result[i].name}`);
extInfo.push(` id: ${result[i].id}`);
extInfo.push(` version: ${result[i].version}`);
extInfo.push(` enabled: ${result[i].enabled}`);
extInfo.push(` type: ${result[i].type}`);
extInfo.push('');
}
debugInfo = `${debugInfo} \n\n${extInfo.join(' \n')}`;
showDebugInfo();
browser.permissions.remove({ permissions: ['management'] });
document.body.removeChild(iframe);
});
};
iframe.src = browser.runtime.getURL('proxy.html');
iframe.style.visibility = 'hidden';
document.body.appendChild(iframe);
} else {
debugInfo += '\n\n==== User Denied Extension and App Permissions ====';
showDebugInfo();
}
});
} else {
debugInfo += '\n\n==== No Extension and App Information ====';
showDebugInfo();
}
});
// Show the changelog
selected('#whatsnew_link', () => {
fetch(browser.runtime.getURL('CHANGELOG.txt'))
.then(response => response.text())
.then((text) => {
$('#changes').text(text).fadeIn();
$('body, html').animate({
scrollTop: $('#changes').offset().top,
}, 1000);
});
});
});