2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Main Popup Page
|
2020-06-30 18:41:58 +02:00
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
* (Origin: Decentraleyes)
|
2020-02-27 13:45:29 +01:00
|
|
|
*
|
|
|
|
* @author Thomas Rientjes
|
|
|
|
* @since 2016-08-09
|
2020-06-30 18:41:58 +02:00
|
|
|
*
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-02-26
|
|
|
|
*
|
2020-02-27 13:45:29 +01:00
|
|
|
* @license MPL 2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Popup
|
|
|
|
*/
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
var popup = {};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Private Methods
|
|
|
|
*/
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._renderContents = function () {
|
|
|
|
helpers.insertI18nContentIntoDocument(document);
|
|
|
|
helpers.insertI18nTitlesIntoDocument(document);
|
|
|
|
|
2020-06-03 16:32:02 +02:00
|
|
|
if (!helpers.insertI18nContentIntoDocument(document)) {
|
|
|
|
popup._renderLocaleNotice();
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._renderNonContextualContents();
|
|
|
|
|
|
|
|
popup._determineTargetTab()
|
2020-10-17 07:09:30 +02:00
|
|
|
.then(popup._determineDomainAllowlistStatus)
|
2020-05-25 22:35:16 +02:00
|
|
|
.then(popup._determineStatusManipulateDOM)
|
2021-08-13 06:15:10 +02:00
|
|
|
.then(popup._determineStatusGoogleFonts)
|
2020-02-27 13:45:29 +01:00
|
|
|
.then(popup._determineResourceInjections)
|
|
|
|
.then(popup._renderContextualContents);
|
2020-06-04 06:54:49 +02:00
|
|
|
|
2020-08-11 07:09:07 +02:00
|
|
|
if (BrowserType.CHROMIUM) {
|
2020-06-04 06:54:49 +02:00
|
|
|
document.getElementById('div-manipulateDOM').hidden = true;
|
2022-07-27 18:22:49 +02:00
|
|
|
document.getElementById('div-google-fonts').hidden = true;
|
2020-06-04 06:54:49 +02:00
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
popup._renderNonContextualContents = function () {
|
2021-02-17 07:01:08 +01:00
|
|
|
let versionLabelElement, nameLabelElement, counterElement, testingUtilityLinkElement,
|
|
|
|
optionsButtonElement, donationButtonElement, infoButtonLabel;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
versionLabelElement = document.getElementById('version-label');
|
2020-06-07 17:40:44 +02:00
|
|
|
nameLabelElement = document.getElementById('name-label');
|
2020-02-27 13:45:29 +01:00
|
|
|
counterElement = document.getElementById('injection-counter');
|
|
|
|
testingUtilityLinkElement = document.getElementById('testing-utility-link');
|
|
|
|
optionsButtonElement = document.getElementById('options-button');
|
2020-05-16 17:40:46 +02:00
|
|
|
donationButtonElement = document.getElementById('donate-button');
|
2020-05-27 06:22:58 +02:00
|
|
|
infoButtonLabel = document.getElementById('manipulateDOM-indicator');
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
versionLabelElement.innerText = popup._version;
|
2020-06-07 17:40:44 +02:00
|
|
|
nameLabelElement.innerText = popup._name;
|
2020-02-27 13:45:29 +01:00
|
|
|
counterElement.innerText = helpers.formatNumber(popup._amountInjected);
|
|
|
|
|
|
|
|
testingUtilityLinkElement.addEventListener('mouseup', popup._onTestingUtilityLinkClicked);
|
|
|
|
optionsButtonElement.addEventListener('mouseup', popup._onOptionsButtonClicked);
|
2021-04-02 07:21:33 +02:00
|
|
|
donationButtonElement.addEventListener('mouseup', popup._onDonationButtonClicked);
|
|
|
|
infoButtonLabel.addEventListener('mouseup', popup._onInfoButtonClicked);
|
2020-08-11 07:09:07 +02:00
|
|
|
|
|
|
|
if (popup._statisticsStatus) {
|
|
|
|
document.getElementById('statistics-button').style.display = 'block';
|
2021-04-02 07:21:33 +02:00
|
|
|
document.getElementById('statistics-button').addEventListener('mouseup', popup._onStatisticsButtonClicked);
|
2020-08-11 07:09:07 +02:00
|
|
|
}
|
2021-02-21 19:50:41 +01:00
|
|
|
|
|
|
|
if (popup._loggingStatus) {
|
|
|
|
document.getElementById('logging-button').style.display = 'block';
|
2021-04-02 07:21:33 +02:00
|
|
|
document.getElementById('logging-button').addEventListener('mouseup', popup._onLoggingButtonClicked);
|
2021-02-21 19:50:41 +01:00
|
|
|
}
|
2021-02-21 19:56:13 +01:00
|
|
|
|
|
|
|
if (!popup.hideDonationButton) {
|
|
|
|
document.getElementById('donate-button').style.display = 'flex';
|
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
popup._renderContextualContents = function () {
|
|
|
|
if (popup._domain !== null) {
|
2020-10-17 07:09:30 +02:00
|
|
|
popup._renderDomainAllowlistPanel();
|
2021-02-07 08:05:06 +01:00
|
|
|
document.getElementById('testing-utility-link').style.display = 'block';
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:40:10 +02:00
|
|
|
if (Object.keys(popup._resourceInjections).length > 0) {
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._renderInjectionPanel(popup._resourceInjections);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
popup._renderDomainAllowlistPanel = function () {
|
2021-02-17 07:01:08 +01:00
|
|
|
let websiteContextElement, protectionToggleElement, domainIndicatorElement,
|
2022-07-04 06:37:46 +02:00
|
|
|
manipulateDOMToggleElement, googleFontsToggleElement;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
websiteContextElement = document.getElementById('website-context');
|
2021-08-13 06:15:10 +02:00
|
|
|
websiteContextElement.setAttribute('class', 'panel');
|
|
|
|
|
2020-03-14 10:28:51 +01:00
|
|
|
protectionToggleElement = document.getElementById('protection-toggle-switch');
|
2020-02-27 13:45:29 +01:00
|
|
|
domainIndicatorElement = document.getElementById('domain-indicator');
|
|
|
|
|
|
|
|
protectionToggleElement.setAttribute('dir', popup._scriptDirection);
|
|
|
|
domainIndicatorElement.innerText = popup._domain;
|
2020-05-25 22:35:16 +02:00
|
|
|
manipulateDOMToggleElement = document.getElementById('manipulateDOM-toggle-switch');
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
googleFontsToggleElement = document.getElementById('google-fonts-toggle-switch');
|
|
|
|
|
2022-01-30 09:33:21 +01:00
|
|
|
if (popup._blockGoogleFonts === false) {
|
|
|
|
document.getElementById('div-google-fonts').hidden = true;
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
if (popup._domainIsAllowlisted === true) {
|
2020-05-26 20:37:26 +02:00
|
|
|
manipulateDOMToggleElement.disabled = true;
|
2021-08-13 06:15:10 +02:00
|
|
|
googleFontsToggleElement.disabled = true;
|
|
|
|
protectionToggleElement.checked = false;
|
2020-05-26 20:37:26 +02:00
|
|
|
protectionToggleElement.addEventListener('click', popup._enableProtection);
|
2021-08-13 06:15:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
googleFontsToggleElement.disabled = false;
|
|
|
|
|
|
|
|
if (popup._domainGoogleFonts) {
|
2021-08-15 18:19:07 +02:00
|
|
|
googleFontsToggleElement.checked = false;
|
2021-08-13 06:15:10 +02:00
|
|
|
googleFontsToggleElement.addEventListener('click', popup._disableGoogleFonts);
|
2020-02-27 13:45:29 +01:00
|
|
|
} else {
|
2021-08-15 18:19:07 +02:00
|
|
|
googleFontsToggleElement.checked = true;
|
2021-08-13 06:15:10 +02:00
|
|
|
googleFontsToggleElement.addEventListener('click', popup._enableGoogleFonts);
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
manipulateDOMToggleElement.disabled = false;
|
|
|
|
|
|
|
|
protectionToggleElement.checked = true;
|
|
|
|
protectionToggleElement.addEventListener('click', popup._disableProtection);
|
|
|
|
|
|
|
|
if (popup.negateHtmlFilterList && !popup._domainManipulateDOM) {
|
|
|
|
manipulateDOMToggleElement.checked = true;
|
|
|
|
manipulateDOMToggleElement.addEventListener('click', popup._enableManipulateDOM);
|
|
|
|
} else if (!popup.negateHtmlFilterList && !popup._domainManipulateDOM) {
|
|
|
|
manipulateDOMToggleElement.checked = false;
|
|
|
|
manipulateDOMToggleElement.addEventListener('click', popup._enableManipulateDOM);
|
|
|
|
} else if (popup.negateHtmlFilterList && popup._domainManipulateDOM) {
|
|
|
|
manipulateDOMToggleElement.checked = false;
|
|
|
|
manipulateDOMToggleElement.addEventListener('click', popup._disableManipulateDOM);
|
|
|
|
} else if (!popup.negateHtmlFilterList && popup._domainManipulateDOM) {
|
|
|
|
manipulateDOMToggleElement.checked = true;
|
|
|
|
manipulateDOMToggleElement.addEventListener('click', popup._disableManipulateDOM);
|
|
|
|
}
|
2022-07-04 06:37:46 +02:00
|
|
|
|
|
|
|
websiteContextElement.style.display = 'block';
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
popup._renderInjectionPanel = function (groupedInjections) {
|
|
|
|
let websiteContextElement, injectionOverviewElement;
|
|
|
|
|
|
|
|
websiteContextElement = document.getElementById('website-context');
|
|
|
|
injectionOverviewElement = popup._createInjectionOverviewElement(groupedInjections);
|
2020-07-03 08:40:10 +02:00
|
|
|
injectionOverviewElement.setAttribute('class', 'panel-overflow');
|
2020-02-27 13:45:29 +01:00
|
|
|
websiteContextElement.append(injectionOverviewElement);
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._enableProtection = function () {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'allowlist:remove-domain',
|
|
|
|
'value': popup._domain,
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
2020-05-26 06:44:02 +02:00
|
|
|
popup._onToggled();
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._disableProtection = function () {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'allowlist:add-domain',
|
|
|
|
'value': popup._domain,
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
2020-05-26 06:44:02 +02:00
|
|
|
popup._onToggled();
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-25 22:35:16 +02:00
|
|
|
popup._enableManipulateDOM = function () {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'manipulateDOM:add-domain',
|
|
|
|
'value': popup._domain,
|
2020-05-25 22:35:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
2020-05-26 06:44:02 +02:00
|
|
|
popup._onToggled();
|
2020-05-25 22:35:16 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._disableManipulateDOM = function () {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'manipulateDOM:remove-domain',
|
|
|
|
'value': popup._domain,
|
2020-05-25 22:35:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
2020-05-26 06:44:02 +02:00
|
|
|
popup._onToggled();
|
2020-05-25 22:35:16 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
popup._enableGoogleFonts = function () {
|
|
|
|
let message = {
|
|
|
|
'topic': 'google-fonts:add-domain',
|
|
|
|
'value': popup._domain,
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
|
|
|
popup._onToggled();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._disableGoogleFonts = function () {
|
|
|
|
let message = {
|
|
|
|
'topic': 'google-fonts:remove-domain',
|
|
|
|
'value': popup._domain,
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function () {
|
|
|
|
popup._onToggled();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
popup._determineDomainAllowlistStatus = function () {
|
2020-02-27 13:45:29 +01:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'domain:fetch-is-allowlisted',
|
|
|
|
'value': popup._domain,
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
2021-01-17 09:52:49 +01:00
|
|
|
if (popup._domain === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
chrome.runtime.sendMessage(message, function (response) {
|
2020-10-17 07:09:30 +02:00
|
|
|
popup._domainIsAllowlisted = response.value;
|
2020-02-27 13:45:29 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-25 22:35:16 +02:00
|
|
|
popup._determineStatusManipulateDOM = function () {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'domain:fetch-is-manipulateDOM',
|
|
|
|
'value': popup._domain,
|
2020-05-25 22:35:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function (response) {
|
|
|
|
popup._domainManipulateDOM = response.value;
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
popup._determineStatusGoogleFonts = function () {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
let message = {
|
|
|
|
'topic': 'domain:fetch-is-google-fonts',
|
|
|
|
'value': popup._domain,
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function (response) {
|
|
|
|
popup._domainGoogleFonts = response.value;
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._determineResourceInjections = function () {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
let message = {
|
2021-02-17 07:01:08 +01:00
|
|
|
'topic': 'tab:fetch-injections',
|
|
|
|
'value': popup._targetTab.id,
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message, function (response) {
|
|
|
|
let groupedInjections = popup._groupResourceInjections(response.value);
|
|
|
|
popup._resourceInjections = groupedInjections;
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._determineTargetTab = function () {
|
|
|
|
return new Promise((resolve) => {
|
2021-03-21 08:07:30 +01:00
|
|
|
helpers.determineActiveTab().then((activeTab) => {
|
|
|
|
popup._targetTab = activeTab;
|
|
|
|
popup._domain = helpers.extractDomainFromUrl(activeTab.url, true);
|
2020-02-27 13:45:29 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
popup._getData = function () {
|
2020-02-27 13:45:29 +01:00
|
|
|
return new Promise((resolve) => {
|
2021-03-21 08:07:30 +01:00
|
|
|
let message = {
|
|
|
|
'topic': 'popup:get-data'
|
|
|
|
};
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
chrome.runtime.sendMessage(message, function (items) {
|
|
|
|
popup._amountInjected = items.data.amountInjected;
|
|
|
|
popup._statisticsStatus = items.data.internalStatistics;
|
|
|
|
popup.negateHtmlFilterList = items.data.negateHtmlFilterList;
|
|
|
|
popup._loggingStatus = items.data.loggingStatus;
|
|
|
|
popup.hideDonationButton = items.data.hideDonationButton;
|
2021-08-13 06:15:10 +02:00
|
|
|
popup._blockGoogleFonts = items.data.blockGoogleFonts;
|
2020-06-25 07:54:17 +02:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-11 07:09:07 +02:00
|
|
|
popup._groupResourceInjections = function (injections) {
|
2020-02-27 13:45:29 +01:00
|
|
|
let groupedInjections = {};
|
|
|
|
|
|
|
|
for (let index in injections) {
|
2021-02-17 07:01:08 +01:00
|
|
|
let {source} = injections[index];
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
groupedInjections[source] = groupedInjections[source] || [];
|
|
|
|
groupedInjections[source].push(injections[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return groupedInjections;
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._createInjectionOverviewElement = function (groupedInjections) {
|
|
|
|
let injectionOverviewElement = document.createElement('ul');
|
|
|
|
injectionOverviewElement.setAttribute('class', 'list');
|
|
|
|
|
|
|
|
for (let source in groupedInjections) {
|
|
|
|
let injectionGroupHeaderElement, injectionGroupElement, cdn;
|
|
|
|
|
|
|
|
cdn = groupedInjections[source];
|
|
|
|
|
2020-07-03 08:40:10 +02:00
|
|
|
injectionGroupHeaderElement = popup._createInjectionGroupHeaderElement(source, cdn);
|
|
|
|
injectionGroupElement = popup._createInjectionGroupElement(source, cdn);
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-07-03 08:40:10 +02:00
|
|
|
injectionOverviewElement.appendChild(injectionGroupHeaderElement);
|
|
|
|
injectionOverviewElement.appendChild(injectionGroupElement);
|
2020-05-30 10:04:48 +02:00
|
|
|
}
|
2020-07-03 08:40:10 +02:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
return injectionOverviewElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._createInjectionGroupHeaderElement = function (source, cdn) {
|
|
|
|
let injectionGroupHeaderElement, badgeElement, badgeTextNode, cdnNameTextNode;
|
|
|
|
|
|
|
|
injectionGroupHeaderElement = document.createElement('li');
|
|
|
|
injectionGroupHeaderElement.setAttribute('class', 'list-item');
|
|
|
|
|
|
|
|
badgeElement = document.createElement('span');
|
|
|
|
badgeElement.setAttribute('class', 'badge');
|
|
|
|
|
|
|
|
badgeTextNode = document.createTextNode(cdn.length);
|
|
|
|
badgeElement.appendChild(badgeTextNode);
|
|
|
|
|
|
|
|
cdnNameTextNode = document.createTextNode(helpers.determineCdnName(source));
|
|
|
|
|
|
|
|
injectionGroupHeaderElement.appendChild(badgeElement);
|
|
|
|
injectionGroupHeaderElement.appendChild(cdnNameTextNode);
|
|
|
|
|
|
|
|
return injectionGroupHeaderElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
popup._createInjectionGroupElement = function (source, cdn) {
|
2021-02-17 07:01:08 +01:00
|
|
|
let injectionGroupElement, bundle, filtered;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-03-24 08:03:08 +01:00
|
|
|
// Filter duplicates
|
2021-02-17 07:01:08 +01:00
|
|
|
bundle = [];
|
2020-03-24 08:03:08 +01:00
|
|
|
for (let injection of cdn) {
|
|
|
|
bundle.push(injection);
|
|
|
|
}
|
2021-02-17 07:01:08 +01:00
|
|
|
filtered = popup._filterDuplicates(bundle, 'bundle');
|
2020-03-24 08:03:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
injectionGroupElement = document.createElement('ul');
|
|
|
|
injectionGroupElement.setAttribute('class', 'sublist');
|
|
|
|
|
2020-03-24 08:03:08 +01:00
|
|
|
for (let injection of filtered) {
|
2020-07-03 08:40:10 +02:00
|
|
|
let injectionElement = popup._createInjectionElement(injection);
|
|
|
|
injectionGroupElement.appendChild(injectionElement);
|
2020-05-26 20:37:26 +02:00
|
|
|
}
|
2020-05-30 10:04:48 +02:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
return injectionGroupElement;
|
|
|
|
};
|
|
|
|
|
2020-06-21 07:35:52 +02:00
|
|
|
popup._createInjectionElement = function (injection) {
|
2020-02-27 13:45:29 +01:00
|
|
|
let injectionElement, filename, name, nameTextNode, noteElement, noteTextNode;
|
|
|
|
|
2020-05-29 08:19:07 +02:00
|
|
|
injectionElement = document.createElement('li');
|
|
|
|
injectionElement.setAttribute('class', 'sublist-item');
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
filename = helpers.extractFilenameFromPath(injection.path);
|
2020-03-24 08:03:08 +01:00
|
|
|
|
|
|
|
// If bundle empty, use filename
|
2020-08-11 07:09:07 +02:00
|
|
|
if (injection.bundle === '') {
|
2020-11-05 07:07:29 +01:00
|
|
|
name = targets.determineResourceName(filename);
|
2020-03-24 08:03:08 +01:00
|
|
|
} else {
|
2021-03-03 23:09:34 +01:00
|
|
|
name = `${injection.bundle}`;
|
2020-03-24 08:03:08 +01:00
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
nameTextNode = document.createTextNode(`- ${name}`);
|
|
|
|
injectionElement.appendChild(nameTextNode);
|
|
|
|
|
2020-07-30 07:56:48 +02:00
|
|
|
if (injection.versionRequested !== null) {
|
2022-02-27 05:51:25 +01:00
|
|
|
let versionNode;
|
|
|
|
|
2020-03-25 08:52:40 +01:00
|
|
|
noteElement = document.createElement('span');
|
|
|
|
noteElement.setAttribute('class', 'side-note');
|
2022-02-27 05:51:25 +01:00
|
|
|
versionNode = popup._createVersionNode(injection.versionRequested, injection.versionDelivered);
|
2020-07-30 07:56:48 +02:00
|
|
|
|
2020-04-05 08:55:04 +02:00
|
|
|
noteTextNode = document.createTextNode(versionNode);
|
2020-03-25 08:52:40 +01:00
|
|
|
noteElement.appendChild(noteTextNode);
|
|
|
|
injectionElement.appendChild(noteElement);
|
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
return injectionElement;
|
|
|
|
};
|
|
|
|
|
2022-02-27 05:51:25 +01:00
|
|
|
popup._createVersionNode = function (versionRequested, versionDelivered) {
|
|
|
|
let version = '';
|
|
|
|
|
|
|
|
if (versionRequested === undefined || versionDelivered === undefined) {
|
2022-07-28 06:12:35 +02:00
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (versionRequested === versionDelivered && versionDelivered !== 'latest') {
|
2022-02-27 05:51:25 +01:00
|
|
|
version = `v${versionRequested}`;
|
|
|
|
} else if (versionRequested === versionDelivered) {
|
|
|
|
version = `v${versionRequested}`;
|
|
|
|
} else if (versionRequested === 'beta') {
|
|
|
|
version = `(${versionRequested} » v${versionDelivered})`;
|
|
|
|
} else if (versionRequested !== 'latest') {
|
|
|
|
version = `(v${versionRequested} » v${versionDelivered})`;
|
|
|
|
} else if (versionRequested === 'latest') {
|
|
|
|
version = `v${versionDelivered}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
};
|
|
|
|
|
2020-08-11 07:09:07 +02:00
|
|
|
popup._filterDuplicates = function (array, key) {
|
2020-05-26 20:37:26 +02:00
|
|
|
/**
|
|
|
|
* Function to remove duplicates from an array, depending on 'key'.
|
|
|
|
* Ignore empty values of the 'key'
|
|
|
|
*
|
|
|
|
*/
|
2021-08-02 06:27:02 +02:00
|
|
|
return array
|
2020-08-11 07:09:07 +02:00
|
|
|
.map((e) => e[key])
|
2021-02-17 07:01:08 +01:00
|
|
|
.map(function (value, index, newArray) {
|
|
|
|
return value !== '' ? newArray.indexOf(value) === index && index : index;
|
|
|
|
})
|
2020-08-11 07:09:07 +02:00
|
|
|
.filter((e) => array[e])
|
|
|
|
.map((e) => array[e]);
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
2020-06-03 16:32:02 +02:00
|
|
|
popup._renderLocaleNotice = function () {
|
|
|
|
let localeNoticeElement, nameTextNode;
|
|
|
|
|
|
|
|
localeNoticeElement = document.getElementById('popup-incomplete-translation');
|
|
|
|
localeNoticeElement.setAttribute('class', 'notice notice-default');
|
2021-04-02 07:21:33 +02:00
|
|
|
localeNoticeElement.addEventListener('mouseup', popup._onIncompleteTranslation);
|
2020-06-03 16:32:02 +02:00
|
|
|
|
2020-06-14 21:45:51 +02:00
|
|
|
nameTextNode = document.createTextNode('Translation is incomplete. You want to help on Weblate?');
|
2020-06-03 16:32:02 +02:00
|
|
|
|
|
|
|
localeNoticeElement.appendChild(nameTextNode);
|
|
|
|
};
|
2020-05-26 20:37:26 +02:00
|
|
|
|
2020-08-11 07:09:07 +02:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Event Handlers
|
|
|
|
*/
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._onDocumentLoaded = function () {
|
|
|
|
let manifest, language;
|
|
|
|
|
|
|
|
manifest = chrome.runtime.getManifest();
|
|
|
|
language = navigator.language;
|
|
|
|
|
2020-06-07 17:40:44 +02:00
|
|
|
popup._name = manifest.name;
|
2021-01-16 07:56:50 +01:00
|
|
|
popup._version = manifest.version;
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._scriptDirection = helpers.determineScriptDirection(language);
|
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
popup._getData().then(popup._renderContents);
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onTestingUtilityLinkClicked = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2020-02-27 13:45:29 +01:00
|
|
|
chrome.tabs.create({
|
2021-02-21 19:40:52 +01:00
|
|
|
'url': Links.LOCALCDN_TEST_WEBSITE,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-02-21 19:40:52 +01:00
|
|
|
}, function (tab) {
|
|
|
|
popup._injectDomain(tab.id);
|
2020-02-27 13:45:29 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onDonationButtonClicked = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2021-04-02 07:21:33 +02:00
|
|
|
chrome.tabs.create({
|
|
|
|
'url': Links.DONATE,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-04-02 07:21:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
if (ev.button === 0) {
|
2021-04-02 07:21:33 +02:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onInfoButtonClicked = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2021-04-02 07:21:33 +02:00
|
|
|
chrome.tabs.create({
|
|
|
|
'url': Links.FAQ_HTML_FILTER,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-04-02 07:21:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
if (ev.button === 0) {
|
2021-04-02 07:21:33 +02:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onIncompleteTranslation = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2021-04-02 07:21:33 +02:00
|
|
|
chrome.tabs.create({
|
|
|
|
'url': Links.WEBLATE,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-04-02 07:21:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
if (ev.button === 0) {
|
2021-04-02 07:21:33 +02:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onStatisticsButtonClicked = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2021-04-02 07:21:33 +02:00
|
|
|
chrome.tabs.create({
|
|
|
|
'url': Links.STATISTICS,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-04-02 07:21:33 +02:00
|
|
|
});
|
|
|
|
}
|
2021-09-11 19:44:04 +02:00
|
|
|
if (ev.button === 0) {
|
2021-04-02 07:21:33 +02:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-21 19:40:52 +01:00
|
|
|
popup._injectDomain = function (tabId) {
|
|
|
|
let message = {
|
2021-03-21 08:07:30 +01:00
|
|
|
'topic': 'tab:inject',
|
2021-02-21 19:40:52 +01:00
|
|
|
'value': tabId,
|
|
|
|
'url': popup._targetTab.url
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(message);
|
2021-08-02 06:27:02 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
popup._close();
|
|
|
|
}, 200);
|
2021-02-21 19:40:52 +01:00
|
|
|
};
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
popup._onOptionsButtonClicked = function () {
|
|
|
|
chrome.runtime.openOptionsPage();
|
|
|
|
return window.close();
|
|
|
|
};
|
|
|
|
|
2020-05-26 06:44:02 +02:00
|
|
|
popup._onToggled = function () {
|
2020-08-11 07:09:07 +02:00
|
|
|
let bypassCache = typeof browser === 'undefined';
|
2020-05-25 22:35:16 +02:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
chrome.tabs.reload(popup._targetTab.id, {bypassCache});
|
2020-05-29 08:18:05 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
popup._close();
|
2020-05-29 18:05:46 +02:00
|
|
|
}, 200);
|
2020-05-25 22:35:16 +02:00
|
|
|
};
|
|
|
|
|
2020-05-26 20:37:26 +02:00
|
|
|
popup._close = function () {
|
|
|
|
chrome.runtime.getPlatformInfo(function (information) {
|
|
|
|
if (information.os === chrome.runtime.PlatformOs.ANDROID) {
|
2021-03-21 08:07:30 +01:00
|
|
|
chrome.tabs.getCurrent(function (activeTab) {
|
|
|
|
if (activeTab) {
|
|
|
|
chrome.tabs.remove(activeTab.id);
|
|
|
|
} else {
|
|
|
|
window.close();
|
|
|
|
}
|
2020-05-26 20:37:26 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
});
|
2020-03-24 08:03:08 +01:00
|
|
|
};
|
|
|
|
|
2021-09-11 19:44:04 +02:00
|
|
|
popup._onLoggingButtonClicked = function (ev) {
|
|
|
|
if (ev.button === 0 || ev.button === 1) {
|
2021-02-21 19:50:41 +01:00
|
|
|
chrome.tabs.create({
|
2021-04-02 07:21:33 +02:00
|
|
|
'url': Links.LOGGING,
|
2021-09-11 19:44:04 +02:00
|
|
|
'active': ev.button === 0,
|
2021-02-21 19:50:41 +01:00
|
|
|
});
|
|
|
|
}
|
2021-09-11 19:44:04 +02:00
|
|
|
if (ev.button === 0) {
|
2021-02-21 19:50:41 +01:00
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
};
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Initializations
|
|
|
|
*/
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-07-03 08:40:10 +02:00
|
|
|
popup.negateHtmlFilterList = false;
|
2020-08-11 07:09:07 +02:00
|
|
|
popup._statisticsStatus = false;
|
2021-02-21 19:50:41 +01:00
|
|
|
popup._loggingStatus = false;
|
2021-08-13 06:15:10 +02:00
|
|
|
popup._blockGoogleFonts = true;
|
2020-07-03 08:40:10 +02:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', popup._onDocumentLoaded);
|