Microsoft has acquired GitHub. Decentraleyes has left GitHub. Welcome to its new home!

To participate, please register, or sign in with an existing GitLab.com, Bitbucket, or GitHub account.

Past contributions on GitHub? Be sure to reclaim your Comments, Issues, and Pull Requests.

Verified Commit 1f41032a authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Update and refactor existing codebase

parent 02c61290
......@@ -30,7 +30,7 @@
"Whitelist": true,
"wrappers": true
},
"overrides": {
"overrides": [{
"files": [
"core/constants.js",
"core/files.js",
......@@ -41,7 +41,7 @@
"rules": {
"no-unused-vars": "off"
}
},
}],
"plugins": [
"no-unsanitized"
],
......
artifacts
audit/node_modules
audit/report.txt
node_modules
......@@ -44,7 +44,7 @@
"description": "Disable prefetch title."
},
"disablePrefetchDescription": {
"message": "Prevent disallowed requests from leaking out to delivery networks.",
"message": "বিতরণ নেটওয়ার্কগুলোতে অনুরোধগুলি ফাঁস হওয়া থেকে প্রতিরোধ করো।",
"description": "Disable prefetch description."
},
"stripMetadataTitle": {
......@@ -52,7 +52,7 @@
"description": "Strip metadata title."
},
"stripMetadataDescription": {
"message": "Erase sensitive data from allowed CDN requests for improved privacy.",
"message": "উন্নত গোপনীয়তার জন্য অনুমোদিত সিডিএন অনুরোধগুলি থেকে সংবেদনশীল ডেটা মুছো।",
"description": "Strip metadata description."
},
"whitelistedDomainsTitle": {
......
{
"name": "decentraleyes-audit",
"version": "1.6.0",
"version": "1.7.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "decentraleyes-audit",
"version": "1.6.0",
"version": "1.7.0",
"author": "Thomas Rientjes",
"license": "MPL-2.0",
"description": "Library audit tool for Decentraleyes.",
......
......@@ -65,7 +65,7 @@ function _getLocalResourceContents (fileLocation, callback) {
fileSystem.open(fileLocation, 'r', function (error, fileDescriptor) {
var buffer = new Buffer(statistics.size);
var buffer = Buffer.alloc(statistics.size);
fileSystem.read(fileDescriptor, buffer, 0, buffer.length, null, function (error, bytesRead, buffer) {
......
......@@ -289,6 +289,8 @@ var files = {
'resources/jquery/3.3.1/jquery.min.jsm': true,
'resources/jquery/3.4.0/jquery.min.jsm': true,
'resources/jquery/3.4.1/jquery.min.jsm': true,
'resources/jquery/3.5.0/jquery.min.jsm': true,
'resources/jquery/3.5.1/jquery.min.jsm': true,
// Moment.js
'resources/moment.js/2.8.3/moment.min.jsm': true,
......
......@@ -136,12 +136,14 @@ interceptor.taintedDomains = {
'10fastfingers.com': true,
'ack.net': true,
'adelnews.com': true,
'adherent.lavilleavelo.org': true,
'advocatepress.com': true,
'aledotimesrecord.com': true,
'alicetx.com': true,
'amarillo.com': true,
'amestrib.com': true,
'amtrib.com': true,
'anyvan.com': true,
'apalachtimes.com': true,
'ardmoreite.com': true,
'augustachronicle.com': true,
......@@ -177,6 +179,7 @@ interceptor.taintedDomains = {
'chillicothetimesbulletin.com': true,
'chipleypaper.com': true,
'chronicle-express.com': true,
'circuitlab.com': true,
'cjonline.com': true,
'code.world': true,
'columbiadailyherald.com': true,
......@@ -185,6 +188,7 @@ interceptor.taintedDomains = {
'creativecommons.org': true,
'crestviewbulletin.com': true,
'crookstontimes.com': true,
'csgostats.gg': true,
'daily-jeff.com': true,
'dailycomet.com': true,
'dailycommercial.com': true,
......@@ -455,6 +459,7 @@ interceptor.taintedDomains = {
'timesonline.com': true,
'timesreporter.com': true,
'timestelegram.com': true,
'tones.be': true,
'topsailadvertiser.com': true,
'tr.sharkoon.com': true,
[`tr.span${'kb'}ang.com`]: true,
......@@ -473,6 +478,7 @@ interceptor.taintedDomains = {
'waxahachietx.com': true,
'wayneindependent.com': true,
'waynepost.com': true,
'web-patient.dk': true,
'weeklycitizen.com': true,
'wellingtondailynews.com': true,
'wellsvilledaily.com': true,
......@@ -501,7 +507,7 @@ interceptor.relatedSettings.push(Setting.AMOUNT_INJECTED);
interceptor.relatedSettings.push(Setting.XHR_TEST_DOMAIN);
interceptor.relatedSettings.push(Setting.BLOCK_MISSING);
chrome.storage.local.get(interceptor.relatedSettings, function (items) {
helpers.getStoredSettings(interceptor.relatedSettings, function (items) {
interceptor.amountInjected = items.amountInjected || 0;
interceptor.xhrTestDomain = items.xhrTestDomain || Address.DECENTRALEYES;
......
......@@ -25,21 +25,17 @@ var main = {};
main._initializeSettings = function () {
let settingDefaults = {
[Setting.XHR_TEST_DOMAIN]: Address.DECENTRALEYES,
[Setting.SHOW_ICON_BADGE]: true,
[Setting.BLOCK_MISSING]: false,
[Setting.DISABLE_PREFETCH]: true,
[Setting.ENFORCE_STAGING]: false,
[Setting.STRIP_METADATA]: true,
[Setting.WHITELISTED_DOMAINS]: {}
};
chrome.storage.local.get(settingDefaults, function (items) {
if (items === null) {
items = settingDefaults; // Restore setting defaults.
}
let settings = [
Setting.XHR_TEST_DOMAIN,
Setting.SHOW_ICON_BADGE,
Setting.BLOCK_MISSING,
Setting.DISABLE_PREFETCH,
Setting.ENFORCE_STAGING,
Setting.STRIP_METADATA,
Setting.WHITELISTED_DOMAINS
];
helpers.getStoredSettings(settings, function (items) {
if (items.blockMissing === true || items.enforceStaging === true) {
stateManager.updateEnvironment(Environment.STAGING);
......@@ -53,14 +49,12 @@ main._initializeSettings = function () {
'value': false
});
}
chrome.storage.local.set(items);
});
};
main._showReleaseNotes = function (details) {
let location, previousVersion;
let location, previousVersion, setting;
location = chrome.extension.getURL('pages/welcome/welcome.html');
......@@ -68,26 +62,26 @@ main._showReleaseNotes = function (details) {
details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
previousVersion = details.previousVersion;
setting = Setting.SHOW_RELEASE_NOTES;
if (previousVersion && previousVersion.charAt(0) === '2') {
return; // Do not show release notes after minor updates.
}
if (details.temporary !== true) {
if (details.temporary === true) {
return; // Only show release notes on full installations.
}
chrome.storage.local.get({
[Setting.SHOW_RELEASE_NOTES]: true
}, function (items) {
helpers.getStoredSettings(setting, function (items) {
if (items.showReleaseNotes === true) {
if (items.showReleaseNotes === true) {
chrome.tabs.create({
'url': location,
'active': false
});
}
});
}
chrome.tabs.create({
'url': location,
'active': false
});
}
});
}
};
......@@ -98,10 +92,10 @@ main._showReleaseNotes = function (details) {
chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
main._initializeSettings();
wrappers.setBadgeBackgroundColor({
wrappers.browserAction.setBadgeBackgroundColor({
'color': [74, 130, 108, 255]
});
wrappers.setBadgeTextColor({
wrappers.browserAction.setBadgeTextColor({
'color': [255, 255, 255, 255]
});
......@@ -132,7 +132,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
requestAnalyzer._applyWhitelistedDomains = function () {
chrome.storage.local.get(Setting.WHITELISTED_DOMAINS, function (items) {
helpers.getStoredSettings(Setting.WHITELISTED_DOMAINS, function (items) {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
});
};
......
......@@ -65,7 +65,7 @@ requestSanitizer._stripMetadata = function (requestDetails) {
* Initializations
*/
chrome.storage.local.get({[Setting.STRIP_METADATA]: true}, function (items) {
helpers.getStoredSettings(Setting.STRIP_METADATA, function (items) {
if (items === null || items.stripMetadata !== false) {
requestSanitizer.enable();
......
......@@ -42,7 +42,7 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
if (stateManager.showIconBadge === true) {
wrappers.setBadgeText({
wrappers.browserAction.setBadgeText({
'tabId': tabIdentifier,
'text': injectionCount.toString()
});
......@@ -51,7 +51,7 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
if (isNaN(interceptor.amountInjected)) {
chrome.storage.local.get(Setting.AMOUNT_INJECTED, function (items) {
helpers.getStoredSettings(Setting.AMOUNT_INJECTED, function (items) {
interceptor.amountInjected = items.amountInjected;
......@@ -90,7 +90,7 @@ stateManager.updateEnvironment = function (preferredEnvironment) {
let requiredItems = [Setting.BLOCK_MISSING, Setting.ENFORCE_STAGING];
chrome.storage.local.get(requiredItems, function (items) {
helpers.getStoredSettings(requiredItems, function (items) {
if (items.blockMissing === true || items.enforceStaging === true) {
stateManager.setEnvironment(Environment.STAGING);
......@@ -233,7 +233,7 @@ stateManager._handleStorageChanged = function (changes) {
stateManager._clearBadgeText = function (tabIdentifier) {
wrappers.setBadgeText({
wrappers.browserAction.setBadgeText({
'tabId': tabIdentifier,
'text': ''
});
......@@ -260,7 +260,7 @@ stateManager._domainIsWhitelisted = function (domain) {
stateManager._setIconDefault = function (tabIdentifier) {
wrappers.setIcon({
wrappers.browserAction.setIcon({
'path': stateManager.defaultIconPath,
'tabId': tabIdentifier
});
......@@ -268,7 +268,7 @@ stateManager._setIconDefault = function (tabIdentifier) {
stateManager._setIconDisabled = function (tabIdentifier) {
wrappers.setIcon({
wrappers.browserAction.setIcon({
'path': stateManager.disabledIconPath,
'tabId': tabIdentifier
});
......@@ -324,7 +324,7 @@ chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab);
});
chrome.storage.local.get(Setting.SHOW_ICON_BADGE, function (items) {
helpers.getStoredSettings(Setting.SHOW_ICON_BADGE, function (items) {
if (items.showIconBadge === undefined) {
items.showIconBadge = true;
......
"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"
"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"
"nl": "nl"
"pl": "pl"
"ro": "ro"
"ru": "ru"
"sr": "sr"
"sv-SE": "sv"
"tl": "tl"
"tr": "tr"
"uk": "uk"
#
# Your Crowdin credentials
#
"project_id" : "153483"
"base_path" : "."
"base_url" : "https://api.crowdin.com"
#
# Choose file structure in Crowdin
# e.g. true or false
#
"preserve_hierarchy": true
#
# Files configuration
#
files: [
{
#
# Source files filter
# e.g. "/resources/en/*.json"
#
"source" : "/_locales/en_US/messages.json",
#
# Where translations will be placed
# e.g. "/resources/%two_letters_code%/%original_file_name%"
#
"translation" : "/_locales/%locale_with_underscore%/messages.json",
#
# Files or directories for ignore
# e.g. ["/**/?.txt", "/**/[0-9].txt", "/**/*\?*.txt"]
#
#"ignore" : [],
#
# The dest allows you to specify a file name in Crowdin
# e.g. "/messages.json"
#
#"dest" : "",
#
# File type
# e.g. "json"
#
#"type" : "",
#
# The parameter "update_option" is optional. If it is not set, after the files update the translations for changed strings will be removed. Use to fix typos and for minor changes in the source strings
# e.g. "update_as_unapproved" or "update_without_changes"
#
#"update_option" : "",
#
# Start block (for XML only)
#
#
# Defines whether to translate tags attributes.
# e.g. 0 or 1 (Default is 1)
#
# "translate_attributes" : 1,
#
# Defines whether to translate texts placed inside the tags.
# e.g. 0 or 1 (Default is 1)
#
# "translate_content" : 1,
#
# This is an array of strings, where each item is the XPaths to DOM element that should be imported
# e.g. ["/content/text", "/content/text[@value]"]
#
# "translatable_elements" : [],
#
# Defines whether to split long texts into smaller text segments
# e.g. 0 or 1 (Default is 1)
#
# "content_segmentation" : 1,
#
# End block (for XML only)
#
#
# Start .properties block
#
#
# Defines whether single quote should be escaped by another single quote or backslash in exported translations
# e.g. 0 or 1 or 2 or 3 (Default is 3)
# 0 - do not escape single quote;
# 1 - escape single quote by another single quote;
# 2 - escape single quote by backslash;
# 3 - escape single quote by another single quote only in strings containing variables ( {0} ).
#
# "escape_quotes" : 3,
#
# Defines whether any special characters (=, :, ! and #) should be escaped by backslash in exported translations.
# e.g. 0 or 1 (Default is 0)
# 0 - do not escape special characters
# 1 - escape special characters by a backslash
#
# "escape_special_characters": 0
#
#
# End .properties block
#
#
# Often software projects have custom names for the directories where translations are placed. crowdin-cli allows you to map your own languages to be understandable by Crowdin.
#
"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",
"nl": "nl",
"pl": "pl",
"ro": "ro",
"ru": "ru",
"sr": "sr",
"sv-SE": "sv",
"tl": "tl",
"tr": "tr",
"uk": "uk",
}
},
#
# Does the first line contain header?
# e.g. true or false
#
#"first_line_contains_header" : true,
#
# for spreadsheets
# e.g. "identifier,source_phrase,context,uk,ru,fr"
#
# "scheme" : "",
}
]
......@@ -23,6 +23,59 @@ var helpers = {};
* Public Methods
*/
helpers.getStoredSettings = function (keys, callback) {
helpers.getSettingDefaults(keys, function (defaults) {
chrome.storage.managed.get(defaults, function (managedItems) {
if (!window.chrome.runtime.lastError) {
defaults = managedItems || defaults;
}
chrome.storage.local.get(defaults, function (localItems) {
if (localItems === null) {
return callback(defaults);
}
callback(localItems);
});
});
});
};
helpers.getSettingDefaults = function (keys, callback) {
let defaults, defaultKeys, matches;
defaults = {
[Setting.AMOUNT_INJECTED]: 0,
[Setting.BLOCK_MISSING]: false,
[Setting.DISABLE_PREFETCH]: true,
[Setting.ENFORCE_STAGING]: false,
[Setting.SHOW_ICON_BADGE]: true,
[Setting.SHOW_RELEASE_NOTES]: true,
[Setting.STRIP_METADATA]: true,
[Setting.WHITELISTED_DOMAINS]: {},
[Setting.XHR_TEST_DOMAIN]: Address.DECENTRALEYES,
};
defaultKeys = Object.keys(defaults);
matches = defaultKeys.reduce(function (accumulator, currentValue) {
if (keys.includes(currentValue)) {
accumulator[currentValue] = defaults[currentValue];
}
return accumulator;
}, {});
callback(matches);
};
helpers.insertI18nContentIntoDocument = function (document) {
let scriptDirection, i18nElements;
......@@ -62,9 +115,9 @@ helpers.languageIsFullySupported = function (language) {
languageSupported = false;
supportedLanguages = [
'ar', 'bg', 'zh', 'hr', 'cs', 'da', 'nl', 'en', 'eo', 'et',
'fi', 'fr', 'de', 'el', 'he', 'hu', 'is', 'id', 'it', 'ja',
'ko', 'nb', 'pl', 'pt', 'ro', 'ru', 'es', 'sv', 'tr'
'ar', 'bn', 'bg', 'zh', 'hr', 'cs', 'da', 'nl', 'en', 'eo',
'et', 'fi', 'fr', 'de', 'el', 'he', 'hu', 'is', 'id', 'it',
'ja', 'ko', 'nb', 'pl', 'pt', 'ro', 'ru', 'es', 'sv', 'tr'
];
for (let supportedLanguage of supportedLanguages) {
......
......@@ -23,30 +23,33 @@ var wrappers = {};
* Public Methods
*/
wrappers.setBadgeBackgroundColor = function (details) {
wrappers.browserAction = {
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
chrome.browserAction.setBadgeBackgroundColor(details);
}
};
setBadgeBackgroundColor (details) {
wrappers.setBadgeText = function (details) {
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
chrome.browserAction.setBadgeBackgroundColor(details);
}
},
if (chrome.browserAction.setBadgeText !== undefined) {
chrome.browserAction.setBadgeText(details);
}
};
setBadgeText (details) {
wrappers.setBadgeTextColor = function (details) {
if (chrome.browserAction.setBadgeText !== undefined) {
chrome.browserAction.setBadgeText(details);
}