Verified Commit bda683e5 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Refactor existing codebase

parent 770e6fb5
......@@ -15,12 +15,11 @@
* Imports
*/
var fileSystem, crypto, http, path, sourceMappingURL;
var fileSystem, crypto, https, sourceMappingURL;
fileSystem = require('fs');
crypto = require('crypto');
https = require('https');
path = require('path');
sourceMappingURL = require('source-map-url');
......@@ -205,7 +204,7 @@ resourceAmount = localResourcePaths.length;
* Script
*/
localResourcePaths.forEach(function (resourcePath, index) {
localResourcePaths.forEach(function (resourcePath) {
var resourceRoute = resourcePath.substr(localResourceLocationLength + 1);
resourceRoute = resourceRoute.substring(0, resourceRoute.length - 4);
......
/**
* Global Constants
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2017-10-27
* @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';
/**
* Constants
*/
const HOST_PREFIX = '*://';
const HOST_SUFFIX = '/*';
const HTTP_EXPRESSION = /^http?:\/\//;
const MAPPING_FILE_EXPRESSION = /\.map$/i;
const REQUEST_BLOCKING = 'blocking';
const REQUEST_HEADERS = 'requestHeaders';
const VALUE_SEPARATOR = ';';
const VERSION_EXPRESSION = /(?:\d{1,2}\.){1,3}\d{1,2}/;
const VERSION_PLACEHOLDER = '{version}';
const WEB_DOMAIN_EXPRESSION = /:\/\/(.[^/]+)(.*)/;
const WEB_PREFIX_LENGTH = 4;
const WEB_PREFIX_VALUE = 'www.';
......@@ -19,12 +19,6 @@
var interceptor = {};
/**
* Constants
*/
const HTTP_EXPRESSION = /^http?:\/\//;
/**
* Public Methods
*/
......@@ -60,7 +54,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
'udacity.com': true
};
if (undetectableTaintedDomains[tabDomain] || /yandex\./.test(tabDomain)) {
if (undetectableTaintedDomains[tabDomain] || (/yandex\./).test(tabDomain)) {
if (tabDomain !== 'yandex.ru') {
return interceptor._handleMissingCandidate(requestDetails.url);
......@@ -79,8 +73,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
}
stateManager.requests[requestDetails.requestId] = {
'tabIdentifier': tabIdentifier,
'targetDetails': targetDetails
tabIdentifier, targetDetails
};
return {
......@@ -103,10 +96,10 @@ interceptor._handleMissingCandidate = function (requestUrl) {
if (requestUrl.match(HTTP_EXPRESSION)) {
requestUrl = requestUrl.replace(HTTP_EXPRESSION, 'https://');
let secureRequestUrl = requestUrl.replace(HTTP_EXPRESSION, 'https://');
return {
'redirectUrl': requestUrl
'redirectUrl': secureRequestUrl
};
} else {
......
......@@ -52,19 +52,19 @@ main._initializeOptions = function () {
main._showReleaseNotes = function (details) {
let location = browser.extension.getURL('pages/welcome/welcome.html');
let location = chrome.extension.getURL('pages/welcome/welcome.html');
if (details.reason === 'install' || details.reason === 'update') {
if (details.temporary === false) {
if (details.temporary !== true) {
browser.storage.local.get({
chrome.storage.local.get({
'showReleaseNotes': true
}, function (options) {
if (options.showReleaseNotes === true) {
browser.tabs.create({
chrome.tabs.create({
'url': location,
'active': false
});
......@@ -78,7 +78,7 @@ main._showReleaseNotes = function (details) {
* Initializations
*/
browser.runtime.onInstalled.addListener(main._showReleaseNotes);
chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
main._initializeOptions();
chrome.runtime.getPlatformInfo(function (information) {
......
......@@ -37,40 +37,40 @@ var mappings = {
// Common Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': {
path: 'resources/dojo/1.6.1/dojo/dojo.js.dec',
type: 'application/javascript'
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript'
},
'jquery/1/jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jqueryui/1/jquery-ui.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript'
'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
'type': 'application/javascript'
},
'jqueryui/1/jquery-ui.min.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript'
'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
'type': 'application/javascript'
},
'mootools/1/mootools-yui-compressed.': {
path: 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec',
type: 'application/javascript'
'path': 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec',
'type': 'application/javascript'
},
'prototype/1/prototype.': {
path: 'resources/prototype/1.7.1.0/prototype.js.dec',
type: 'application/javascript'
'path': 'resources/prototype/1.7.1.0/prototype.js.dec',
'type': 'application/javascript'
},
'scriptaculous/1/scriptaculous.': {
path: 'resources/scriptaculous/1.9.0/scriptaculous.js.dec',
type: 'application/javascript'
'path': 'resources/scriptaculous/1.9.0/scriptaculous.js.dec',
'type': 'application/javascript'
},
'swfobject/2/swfobject.': {
path: 'resources/swfobject/2.2/swfobject.js.dec',
type: 'application/javascript'
'path': 'resources/swfobject/2.2/swfobject.js.dec',
'type': 'application/javascript'
},
'webfont/1/webfont.': {
path: 'resources/webfont/1.5.18/webfont.js.dec',
type: 'application/javascript'
'path': 'resources/webfont/1.5.18/webfont.js.dec',
'type': 'application/javascript'
}
}
},
......@@ -118,52 +118,52 @@ var mappings = {
// Common Shorthand Notations [Deprecated]
'jquery-latest.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.min.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.min.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.min.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.min.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.min.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
}
}
},
......
......@@ -19,17 +19,6 @@
var requestAnalyzer = {};
/**
* Constants
*/
const MAPPING_FILE_EXPRESSION = new RegExp('\.map$', 'i');
const VERSION_EXPRESSION = /(?:\d{1,2}\.){1,3}\d{1,2}/;
const VERSION_PLACEHOLDER = '{version}';
const WEB_DOMAIN_EXPRESSION = /:\/\/(.[^\/]+)(.*)/;
const WEB_PREFIX_VALUE = 'www.';
const WEB_PREFIX_LENGTH = WEB_PREFIX_VALUE.length;
/**
* Public Methods
*/
......@@ -96,7 +85,7 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath) {
var resourcePath, versionNumber, resourcePattern;
let resourcePath, versionNumber, resourcePattern;
resourcePath = channelPath.replace(basePath, '');
......@@ -116,9 +105,9 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
// Prepare and return a local target.
return {
source: channelHost,
version: version,
path: targetPath
'source': channelHost,
'version': version,
'path': targetPath
};
}
}
......@@ -128,7 +117,6 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
requestAnalyzer._applyWhitelistedDomains = function () {
//noinspection JSUnresolvedVariable
chrome.storage.local.get('whitelistedDomains', function (items) {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
});
......
......@@ -20,73 +20,73 @@
var resources = {
// AngularJS
angular: {
path: 'resources/angularjs/{version}/angular.min.js.dec',
type: 'application/javascript'
'angular': {
'path': 'resources/angularjs/{version}/angular.min.js.dec',
'type': 'application/javascript'
},
// Backbone.js
backbone: {
path: 'resources/backbone.js/{version}/backbone-min.js.dec',
type: 'application/javascript'
'backbone': {
'path': 'resources/backbone.js/{version}/backbone-min.js.dec',
'type': 'application/javascript'
},
// Dojo
dojo: {
path: 'resources/dojo/{version}/dojo/dojo.js.dec',
type: 'application/javascript'
'dojo': {
'path': 'resources/dojo/{version}/dojo/dojo.js.dec',
'type': 'application/javascript'
},
// Ember.js
ember: {
path: 'resources/ember.js/{version}/ember.min.js.dec',
type: 'application/javascript'
'ember': {
'path': 'resources/ember.js/{version}/ember.min.js.dec',
'type': 'application/javascript'
},
// Ext Core
extCore: {
path: 'resources/ext-core/{version}/ext-core.js.dec',
type: 'application/javascript'
'extCore': {
'path': 'resources/ext-core/{version}/ext-core.js.dec',
'type': 'application/javascript'
},
// jQuery
jQuery: {
path: 'resources/jquery/{version}/jquery.min.js.dec',
type: 'application/javascript'
'jQuery': {
'path': 'resources/jquery/{version}/jquery.min.js.dec',
'type': 'application/javascript'
},
// jQuery UI
jQueryUI: {
path: 'resources/jqueryui/{version}/jquery-ui.min.js.dec',
type: 'application/javascript'
'jQueryUI': {
'path': 'resources/jqueryui/{version}/jquery-ui.min.js.dec',
'type': 'application/javascript'
},
// Modernizr
modernizr: {
path: 'resources/modernizr/{version}/modernizr.min.js.dec',
type: 'application/javascript'
'modernizr': {
'path': 'resources/modernizr/{version}/modernizr.min.js.dec',
'type': 'application/javascript'
},
// MooTools
mootools: {
path: 'resources/mootools/{version}/mootools-yui-compressed.js.dec',
type: 'application/javascript'
'mootools': {
'path': 'resources/mootools/{version}/mootools-yui-compressed.js.dec',
'type': 'application/javascript'
},
// Prototype
prototypeJS: {
path: 'resources/prototype/{version}/prototype.js.dec',
type: 'application/javascript'
'prototypeJS': {
'path': 'resources/prototype/{version}/prototype.js.dec',
'type': 'application/javascript'
},
// Scriptaculous
scriptaculous: {
path: 'resources/scriptaculous/{version}/scriptaculous.js.dec',
type: 'application/javascript'
'scriptaculous': {
'path': 'resources/scriptaculous/{version}/scriptaculous.js.dec',
'type': 'application/javascript'
},
// SWFObject
swfobject: {
path: 'resources/swfobject/{version}/swfobject.js.dec',
type: 'application/javascript'
'swfobject': {
'path': 'resources/swfobject/{version}/swfobject.js.dec',
'type': 'application/javascript'
},
// Underscore.js
underscore: {
path: 'resources/underscore.js/{version}/underscore-min.js.dec',
type: 'application/javascript'
'underscore': {
'path': 'resources/underscore.js/{version}/underscore-min.js.dec',
'type': 'application/javascript'
},
// Web Font Loader
webfont: {
path: 'resources/webfont/{version}/webfont.js.dec',
type: 'application/javascript'
'webfont': {
'path': 'resources/webfont/{version}/webfont.js.dec',
'type': 'application/javascript'
}
};
......@@ -19,15 +19,6 @@
var stateManager = {};
/**
* Constants
*/
const BLOCKING_ACTION = 'blocking';
const HOST_PREFIX = '*://';
const HOST_SUFFIX = '/*';
const REQUEST_HEADERS = 'requestHeaders';
/**
* Public Methods
*/
......@@ -47,15 +38,15 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
if (injectionCount > 0) {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: injectionCount.toString()
'tabId': tabIdentifier,
'text': injectionCount.toString()
});
} else {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
'tabId': tabIdentifier,
'text': ''
});
}
}
......@@ -130,7 +121,7 @@ stateManager._createTab = function (tab) {
});
});
}, requestFilters, [BLOCKING_ACTION]);
}, requestFilters, [REQUEST_BLOCKING]);
};
stateManager._removeTab = function (tabIdentifier) {
......@@ -151,8 +142,8 @@ stateManager._updateTab = function (details) {
if (stateManager.showIconBadge === true) {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
'tabId': tabIdentifier,
'text': ''
});
}
......@@ -180,7 +171,7 @@ stateManager._stripMetadata = function (requestDetails) {
stateManager._handleStorageChanged = function (changes) {
if ('showIconBadge' in changes) {
stateManager.showIconBadge = changes.showIconBadge.newValue;
if (changes.showIconBadge.newValue !== true) {
......@@ -199,13 +190,13 @@ stateManager._handleStorageChanged = function (changes) {
onBeforeSendHeaders.removeListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
}, [REQUEST_BLOCKING, REQUEST_HEADERS]);
if (changes.stripMetadata.newValue !== false) {
onBeforeSendHeaders.addListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
}, [REQUEST_BLOCKING, REQUEST_HEADERS]);
}
}
};
......@@ -213,8 +204,8 @@ stateManager._handleStorageChanged = function (changes) {
stateManager._removeIconBadgeFromTab = function (tab) {
chrome.browserAction.setBadgeText({
tabId: tab.id,
text: ''
'tabId': tab.id,
'text': ''
});
};
......@@ -228,10 +219,6 @@ stateManager.validHosts = [];
for (let mapping in mappings) {
if (!mappings.hasOwnProperty(mapping)) {
continue;
}
let supportedHost = HOST_PREFIX + mapping + HOST_SUFFIX;
stateManager.validHosts.push(supportedHost);
}
......@@ -252,7 +239,7 @@ chrome.tabs.onCreated.addListener(stateManager._createTab);
chrome.tabs.onRemoved.addListener(stateManager._removeTab);
chrome.webNavigation.onCommitted.addListener(stateManager._updateTab, {
url: [{urlContains: ':'}]
'url': [{'urlContains': ':'}]
});
chrome.webRequest.onErrorOccurred.addListener(function (requestDetails) {
......@@ -277,6 +264,6 @@ chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
chrome.webRequest.onBeforeSendHeaders.addListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
}, [REQUEST_BLOCKING, REQUEST_HEADERS]);
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
......@@ -44,8 +44,7 @@
},
"options_ui": {
"page": "pages/options/options.html",
"browser_style": false
"page": "pages/options/options.html"
},
"applications": {
......
/**
* Internal Helper Module
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2017-10-26
* @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';
/**
* Helpers
*/
var helpers = {};
/**
* Public Functions
*/
helpers.insertI18nContentIntoDocument = function (document) {
let scriptDirection, i18nElements;
scriptDirection = helpers.determineScriptDirection(navigator.language);
i18nElements = document.querySelectorAll('[data-i18n-content]');
i18nElements.forEach(function (i18nElement) {
let i18nMessageName = i18nElement.getAttribute('data-i18n-content');
i18nElement.innerText = chrome.i18n.getMessage(i18nMessageName);
i18nElement.setAttribute('dir', scriptDirection);
});
};
helpers.insertI18nTitlesIntoDocument = function (document) {
let scriptDirection, i18nElements;
scriptDirection = helpers.determineScriptDirection(navigator.language);
i18nElements = document.querySelectorAll('[data-i18n-title]');
i18nElements.forEach(function (i18nElement) {
let i18nMessageName = i18nElement.getAttribute('data-i18n-title');