Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Synzvato/decentraleyes
  • gkrishnaks/decentraleyes
  • ExE-Boss/decentraleyes
  • whtsky/decentraleyes
  • grtgarrett/decentraleyes
  • An_dz/decentraleyes
  • Alaska/decentraleyes
  • finn/decentraleyes
  • klippy/decentraleyes
9 results
Show changes
Showing
with 239 additions and 642 deletions
/**
* Messenger
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2018-05-28
* @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';
/**
* Messenger
*/
var messenger = {};
/**
* Private Methods
*/
messenger._handleMessageReceived = function (message, sender, sendResponse) {
let topic, value;
topic = message.topic;
value = message.value;
if (topic === 'tab:fetch-injections') {
sendResponse({'value': stateManager.tabs[value].injections});
return MessageResponse.SYNCHRONOUS;
}
if (topic === 'domain:fetch-is-whitelisted') {
let whitelistRecord = requestAnalyzer.whitelistedDomains[value];
sendResponse({'value': Boolean(whitelistRecord)});
return MessageResponse.SYNCHRONOUS;
}
if (topic === 'whitelist:add-domain') {
stateManager.addDomainToWhitelist(value).then(function () {
sendResponse({'value': true});
});
return MessageResponse.ASYNCHRONOUS;
}
if (topic === 'whitelist:remove-domain') {
stateManager.removeDomainFromWhitelist(value).then(function () {
sendResponse({'value': true});
});
return MessageResponse.ASYNCHRONOUS;
}
};
/**
* Event Handlers
*/
chrome.runtime.onMessage.addListener(messenger._handleMessageReceived);
/**
* Request Analyzer
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2016-04-11
* @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';
/**
* Request Analyzer
*/
var requestAnalyzer = {};
/**
* Public Methods
*/
requestAnalyzer.isValidCandidate = function (requestDetails, tabDetails) {
let initiatorDomain, isWhitelisted;
initiatorDomain = helpers.extractDomainFromUrl(tabDetails.url, true);
if (initiatorDomain === null) {
initiatorDomain = Address.EXAMPLE;
}
isWhitelisted = requestAnalyzer.whitelistedDomains[initiatorDomain];
if (isWhitelisted) {
return false;
}
// Only requests of type GET can be valid candidates.
return requestDetails.method === WebRequest.GET;
};
requestAnalyzer.getLocalTarget = function (requestDetails) {
let destinationUrl, destinationHost, destinationPath, hostMappings, basePath, resourceMappings;
destinationUrl = new URL(requestDetails.url);
destinationHost = destinationUrl.host;
destinationPath = destinationUrl.pathname;
// Use the proper mappings for the targeted host.
hostMappings = mappings[destinationHost];
// Resource mapping files are never locally available.
if (Resource.MAPPING_EXPRESSION.test(destinationPath)) {
return false;
}
basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath);
resourceMappings = hostMappings[basePath];
if (!resourceMappings) {
return false;
}
// Return either the local target's path or false.
return requestAnalyzer._findLocalTarget(resourceMappings, basePath, destinationHost, destinationPath);
};
/**
* Private Methods
*/
requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
for (let basePath of Object.keys(hostMappings)) {
if (channelPath.startsWith(basePath)) {
return basePath;
}
}
return false;
};
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath) {
let resourcePath, versionNumber, resourcePattern;
resourcePath = channelPath.replace(basePath, '');
versionNumber = resourcePath.match(Resource.VERSION_EXPRESSION);
resourcePattern = resourcePath.replace(versionNumber, Resource.VERSION_PLACEHOLDER);
for (let resourceMold of Object.keys(resourceMappings)) {
if (resourcePattern.startsWith(resourceMold)) {
let targetPath, hostShorthands, version;
targetPath = resourceMappings[resourceMold].path;
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
hostShorthands = shorthands[channelHost];
if (hostShorthands && hostShorthands[targetPath]) {
let shorthand = hostShorthands[targetPath];
targetPath = shorthand.path;
version = shorthand.version;
} else {
version = versionNumber && versionNumber[0] || targetPath.match(Resource.VERSION_EXPRESSION);
}
// Prepare and return a local target.
return {
'source': channelHost,
'version': version,
'path': targetPath
};
}
}
return false;
};
requestAnalyzer._applyWhitelistedDomains = function () {
chrome.storage.local.get(Setting.WHITELISTED_DOMAINS, function (items) {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
});
};
/**
* Initializations
*/
requestAnalyzer.whitelistedDomains = {};
requestAnalyzer._applyWhitelistedDomains();
/**
* Event Handlers
*/
chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains);
/**
* Request Sanitizer
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2018-01-10
* @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';
/**
* Request Sanitizer
*/
var requestSanitizer = {};
/**
* Public Methods
*/
requestSanitizer.enable = function () {
let onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
onBeforeSendHeaders.addListener(requestSanitizer._stripMetadata, {
'urls': stateManager.validHosts
}, [WebRequest.BLOCKING, WebRequest.HEADERS]);
};
requestSanitizer.disable = function () {
let onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
onBeforeSendHeaders.removeListener(requestSanitizer._stripMetadata, {
'urls': stateManager.validHosts
}, [WebRequest.BLOCKING, WebRequest.HEADERS]);
};
/**
* Private Methods
*/
requestSanitizer._stripMetadata = function (requestDetails) {
let sensitiveHeaders = [Header.COOKIE, Header.ORIGIN, Header.REFERER];
for (let i = 0; i < requestDetails.requestHeaders.length; ++i) {
if (sensitiveHeaders.indexOf(requestDetails.requestHeaders[i].name) > -1) {
requestDetails.requestHeaders.splice(i--, 1);
}
}
return {
[WebRequest.HEADERS]: requestDetails.requestHeaders
};
};
/**
* Initializations
*/
chrome.storage.local.get({[Setting.STRIP_METADATA]: true}, function (options) {
if (options === null || options.stripMetadata !== false) {
requestSanitizer.enable();
}
});
/**
* State Manager
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2017-03-10
* @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';
/**
* State Manager
*/
var stateManager = {};
/**
* Public Methods
*/
stateManager.registerInjection = function (tabIdentifier, injection) {
let injectionIdentifier, registeredTab, injectionCount;
injectionIdentifier = injection.source + injection.path + injection.version;
registeredTab = stateManager.tabs[tabIdentifier];
registeredTab.injections[injectionIdentifier] = injection;
injectionCount = Object.keys(registeredTab.injections).length || 0;
if (injectionCount > 0) {
chrome.browserAction.setTitle({
'tabId': tabIdentifier,
'title': `Decentraleyes (${injectionCount})`
});
if (stateManager.showIconBadge === true) {
wrappers.setBadgeText({
'tabId': tabIdentifier,
'text': injectionCount.toString()
});
}
}
if (isNaN(interceptor.amountInjected)) {
chrome.storage.local.get(Setting.AMOUNT_INJECTED, function (items) {
interceptor.amountInjected = items.amountInjected;
chrome.storage.local.set({
[Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected
});
});
} else {
chrome.storage.local.set({
[Setting.AMOUNT_INJECTED]: ++interceptor.amountInjected
});
}
};
stateManager.addDomainToWhitelist = function (domain) {
return new Promise((resolve) => {
let whitelistedDomains = requestAnalyzer.whitelistedDomains;
whitelistedDomains[domain] = true;
chrome.storage.local.set({whitelistedDomains}, resolve);
});
};
stateManager.removeDomainFromWhitelist = function (domain) {
return new Promise((resolve) => {
let whitelistedDomains = requestAnalyzer.whitelistedDomains;
delete whitelistedDomains[domain];
chrome.storage.local.set({whitelistedDomains}, resolve);
});
};
/**
* Private Methods
*/
stateManager._createTab = function (tab) {
let tabIdentifier, requestFilters;
tabIdentifier = tab.id;
stateManager.tabs[tabIdentifier] = {
'injections': {}
};
requestFilters = {
'tabId': tabIdentifier,
'urls': stateManager.validHosts
};
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
let tab = stateManager.tabs[tabIdentifier].details || {};
return interceptor.handleRequest(requestDetails, tabIdentifier, tab);
}, requestFilters, [WebRequest.BLOCKING]);
};
stateManager._removeTab = function (tabIdentifier) {
delete stateManager.tabs[tabIdentifier];
};
stateManager._updateTab = function (details) {
let tabDomain, domainIsWhitelisted, tabIdentifier, frameIdentifier;
tabDomain = helpers.extractDomainFromUrl(details.url);
domainIsWhitelisted = stateManager._domainIsWhitelisted(tabDomain);
frameIdentifier = details.frameId;
tabIdentifier = details.tabId;
if (frameIdentifier !== 0 || tabIdentifier === -1) {
return;
}
if (domainIsWhitelisted) {
stateManager._setIconDisabled(tabIdentifier);
} else {
stateManager._setIconDefault(tabIdentifier);
}
chrome.browserAction.setTitle({
'tabId': tabIdentifier,
'title': 'Decentraleyes'
});
if (stateManager.showIconBadge === true) {
stateManager._clearBadgeText(tabIdentifier);
}
if (stateManager.tabs[tabIdentifier]) {
stateManager.tabs[tabIdentifier].injections = {};
}
};
stateManager._handleStorageChanged = function (changes) {
if (Setting.SHOW_ICON_BADGE in changes) {
stateManager.showIconBadge = changes.showIconBadge.newValue;
if (changes.showIconBadge.newValue !== true) {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._removeIconBadgeFromTab);
});
}
}
if (Setting.STRIP_METADATA in changes) {
requestSanitizer.disable();
if (changes.stripMetadata.newValue !== false) {
requestSanitizer.enable();
}
}
};
stateManager._clearBadgeText = function (tabIdentifier) {
wrappers.setBadgeText({
'tabId': tabIdentifier,
'text': ''
});
};
stateManager._removeIconBadgeFromTab = function (tab) {
stateManager._clearBadgeText(tab.id);
};
stateManager._domainIsWhitelisted = function (domain) {
if (domain !== null) {
let whitelistRecord, isWhitelisted;
whitelistRecord = requestAnalyzer.whitelistedDomains[domain];
isWhitelisted = Boolean(whitelistRecord);
return isWhitelisted;
}
return false;
};
stateManager._setIconDefault = function (tabIdentifier) {
wrappers.setIcon({
'path': stateManager.defaultIconPath,
'tabId': tabIdentifier
});
};
stateManager._setIconDisabled = function (tabIdentifier) {
wrappers.setIcon({
'path': stateManager.disabledIconPath,
'tabId': tabIdentifier
});
};
/**
* Initializations
*/
stateManager.requests = {};
stateManager.tabs = {};
stateManager.defaultIconPath = {
'18': chrome.runtime.getURL('icons/action/icon18-default.png'),
'19': chrome.runtime.getURL('icons/action/icon19-default.png'),
'32': chrome.runtime.getURL('icons/action/icon32-default.png'),
'36': chrome.runtime.getURL('icons/action/icon36-default.png'),
'38': chrome.runtime.getURL('icons/action/icon38-default.png'),
'64': chrome.runtime.getURL('icons/action/icon64-default.png')
};
stateManager.disabledIconPath = {
'18': chrome.runtime.getURL('icons/action/icon18-disabled.png'),
'19': chrome.runtime.getURL('icons/action/icon19-disabled.png'),
'32': chrome.runtime.getURL('icons/action/icon32-disabled.png'),
'36': chrome.runtime.getURL('icons/action/icon36-disabled.png'),
'38': chrome.runtime.getURL('icons/action/icon38-disabled.png'),
'64': chrome.runtime.getURL('icons/action/icon64-disabled.png')
};
stateManager.validHosts = [];
for (let mapping in mappings) {
let supportedHost = Address.ANY_PROTOCOL + mapping + Address.ANY_PATH;
stateManager.validHosts.push(supportedHost);
}
chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab);
});
chrome.storage.local.get(Setting.SHOW_ICON_BADGE, function (items) {
if (items.showIconBadge === undefined) {
items.showIconBadge = true;
}
stateManager.showIconBadge = items.showIconBadge;
});
/**
* Event Handlers
*/
chrome.tabs.onCreated.addListener(stateManager._createTab);
chrome.tabs.onRemoved.addListener(stateManager._removeTab);
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
if (requestDetails.tabId !== -1) {
stateManager.tabs[requestDetails.tabId].details = {
'url': requestDetails.url
};
}
}, {'types': [WebRequestType.MAIN_FRAME], 'urls': [Address.ANY]});
chrome.webNavigation.onCommitted.addListener(stateManager._updateTab, {
'url': [{'urlContains': ':'}]
});
chrome.webRequest.onErrorOccurred.addListener(function (requestDetails) {
if (stateManager.requests[requestDetails.requestId]) {
delete stateManager.requests[requestDetails.requestId];
}
}, {'urls': [Address.ANY]});
chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
let knownRequest = stateManager.requests[requestDetails.requestId];
if (knownRequest) {
stateManager.registerInjection(knownRequest.tabIdentifier, knownRequest.targetDetails);
delete stateManager.requests[requestDetails.requestId];
}
}, {'urls': [Address.ANY]});
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
"project_identifier": "decentraleyes"
"preserve_hierarchy": true
"files":
-
"source": "/_locales/en_US/messages.json"
"translation": "/_locales/%locale_with_underscore%/messages.json"
"languages_mapping":
"locale_with_underscore":
"ar": "ar"
"bg": "bg"
"cs": "cs"
"da": "da"
"de": "de"
"el": "el"
"eo": "eo"
"es-ES": "es"
"et": "et"
"fi": "fi"
"fr": "fr"
"he": "he"
"hu": "hu"
"id": "id"
"is": "is"
"it": "it"
"ja": "ja"
"ko": "ko"
"lb": "lb"
"nl": "nl"
"pl": "pl"
"ro": "ro"
"ru": "ru"
"sr": "sr"
"sv-SE": "sv"
"tl": "tl"
"tr": "tr"
#
# API Configuration
#
"project_id" : "153483"
"base_url" : "https://api.crowdin.com"
#
# Directory Configuration
#
"preserve_hierarchy" : true
#
# File Configuration
#
files: [{
"source" : "/_locales/en_US/messages.json",
"translation" : "/_locales/%locale_with_underscore%/messages.json",
"export_only_approved" : true,
"languages_mapping" : {
"locale_with_underscore" : {
"ar" : "ar",
"bg" : "bg",
"bn" : "bn",
"ca" : "ca",
"cs" : "cs",
"da" : "da",
"de" : "de",
"el" : "el",
"eo" : "eo",
"es-ES" : "es",
"et" : "et",
"fi" : "fi",
"fr" : "fr",
"he" : "he",
"hr" : "hr",
"hu" : "hu",
"id" : "id",
"is" : "is",
"it" : "it",
"ja" : "ja",
"ko" : "ko",
"lb" : "lb",
"nb" : "nb",
"nl" : "nl",
"pa-IN" : "pa",
"pl" : "pl",
"ro" : "ro",
"ru" : "ru",
"si-LK" : "si",
"sq" : "sq",
"sr" : "sr",
"sv-SE" : "sv",
"tl" : "tl",
"tr" : "tr",
"uk" : "uk",
"vi" : "vi"
}
}
}]
import globals from 'globals';
import js from '@eslint/js';
import noUnsanitized from 'eslint-plugin-no-unsanitized';
export const baseConfiguration = {
'languageOptions': {
'ecmaVersion': 2023
},
'rules': {
'array-bracket-newline': 'error',
'array-bracket-spacing': 'error',
'arrow-parens': 'error',
'arrow-spacing': 'error',
'block-spacing': 'error',
'brace-style': 'error',
'camelcase': 'error',
'comma-dangle': ['error', 'never'],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': 'error',
'consistent-this': 'error',
'curly': 'error',
'eol-last': 'error',
'eqeqeq': 'error',
'func-call-spacing': 'error',
'function-paren-newline': 'error',
'generator-star-spacing': 'error',
'indent': ['error', 4],
'key-spacing': 'error',
'keyword-spacing': 'error',
'linebreak-style': ['error', 'unix'],
'new-cap': 'error',
'new-parens': 'error',
'no-array-constructor': 'error',
'no-bitwise': 'error',
'no-confusing-arrow': 'error',
'no-continue': 'error',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-implicit-coercion': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-loop-func': 'error',
'no-multi-spaces': 'error',
'no-multi-str': 'error',
'no-multiple-empty-lines': [
'error', {
'max': 1,
'maxEOF': 1,
'maxBOF': 0
}
],
'max-len': [
'error', {
'code': 120
}
],
'no-negated-condition': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-object': 'error',
'no-new-wrappers': 'error',
'no-octal-escape': 'error',
'no-proto': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-script-url': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow-restricted-names': 'error',
'no-tabs': 'error',
'no-ternary': 'error',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-unmodified-loop-condition': 'error',
'no-unused-expressions': 'error',
'no-use-before-define': 'error',
'no-useless-call': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-void': 'error',
'no-warning-comments': 'warn',
'no-whitespace-before-property': 'error',
'no-with': 'error',
'object-curly-spacing': 'error',
'object-shorthand': ['error', 'consistent-as-needed'],
'operator-assignment': 'error',
'operator-linebreak': 'error',
'prefer-numeric-literals': 'error',
'prefer-promise-reject-errors': 'error',
'quote-props': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'quotes': ['error', 'single'],
'rest-spread-spacing': 'error',
'require-await': 'error',
'semi': 'error',
'semi-spacing': 'error',
'semi-style': 'error',
'space-before-blocks': 'error',
'space-before-function-paren': 'error',
'space-in-parens': 'error',
'space-infix-ops': 'error',
'space-unary-ops': [
2, {
'words': false,
'nonwords': false,
'overrides': {
'!': true
}
}
],
'spaced-comment': 'error',
'strict': ['error', 'global'],
'switch-colon-spacing': 'error',
'symbol-description': 'error',
'template-curly-spacing': 'error',
'template-tag-spacing': 'error',
'unicode-bom': 'error',
'vars-on-top': 'error',
'wrap-regex': 'error',
'yield-star-spacing': 'error',
'yoda': 'error'
}
};
export default [
js.configs.recommended,
baseConfiguration,
{
'ignores': [
'_locales',
'images',
'pages/shared/resources',
'resources'
]
},
{
'plugins': {
'no-unsanitized': noUnsanitized
},
'languageOptions': {
'globals': {
...globals.browser,
...globals.webextensions
}
},
'rules': {
'no-unsanitized/method': 'error',
'no-unsanitized/property': 'error'
}
}
];
File moved
images/icons/action/disabled/16.png

540 B