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.

Refactor existing codebase

parent 770e6fb5
...@@ -15,12 +15,11 @@ ...@@ -15,12 +15,11 @@
* Imports * Imports
*/ */
var fileSystem, crypto, http, path, sourceMappingURL; var fileSystem, crypto, https, sourceMappingURL;
fileSystem = require('fs'); fileSystem = require('fs');
crypto = require('crypto'); crypto = require('crypto');
https = require('https'); https = require('https');
path = require('path');
sourceMappingURL = require('source-map-url'); sourceMappingURL = require('source-map-url');
...@@ -205,7 +204,7 @@ resourceAmount = localResourcePaths.length; ...@@ -205,7 +204,7 @@ resourceAmount = localResourcePaths.length;
* Script * Script
*/ */
localResourcePaths.forEach(function (resourcePath, index) { localResourcePaths.forEach(function (resourcePath) {
var resourceRoute = resourcePath.substr(localResourceLocationLength + 1); var resourceRoute = resourcePath.substr(localResourceLocationLength + 1);
resourceRoute = resourceRoute.substring(0, resourceRoute.length - 4); 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 @@ ...@@ -19,12 +19,6 @@
var interceptor = {}; var interceptor = {};
/**
* Constants
*/
const HTTP_EXPRESSION = /^http?:\/\//;
/** /**
* Public Methods * Public Methods
*/ */
...@@ -60,7 +54,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { ...@@ -60,7 +54,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
'udacity.com': true 'udacity.com': true
}; };
if (undetectableTaintedDomains[tabDomain] || /yandex\./.test(tabDomain)) { if (undetectableTaintedDomains[tabDomain] || (/yandex\./).test(tabDomain)) {
if (tabDomain !== 'yandex.ru') { if (tabDomain !== 'yandex.ru') {
return interceptor._handleMissingCandidate(requestDetails.url); return interceptor._handleMissingCandidate(requestDetails.url);
...@@ -79,8 +73,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { ...@@ -79,8 +73,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
} }
stateManager.requests[requestDetails.requestId] = { stateManager.requests[requestDetails.requestId] = {
'tabIdentifier': tabIdentifier, tabIdentifier, targetDetails
'targetDetails': targetDetails
}; };
return { return {
...@@ -103,10 +96,10 @@ interceptor._handleMissingCandidate = function (requestUrl) { ...@@ -103,10 +96,10 @@ interceptor._handleMissingCandidate = function (requestUrl) {
if (requestUrl.match(HTTP_EXPRESSION)) { if (requestUrl.match(HTTP_EXPRESSION)) {
requestUrl = requestUrl.replace(HTTP_EXPRESSION, 'https://'); let secureRequestUrl = requestUrl.replace(HTTP_EXPRESSION, 'https://');
return { return {
'redirectUrl': requestUrl 'redirectUrl': secureRequestUrl
}; };
} else { } else {
......
...@@ -52,19 +52,19 @@ main._initializeOptions = function () { ...@@ -52,19 +52,19 @@ main._initializeOptions = function () {
main._showReleaseNotes = function (details) { 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.reason === 'install' || details.reason === 'update') {
if (details.temporary === false) { if (details.temporary !== true) {
browser.storage.local.get({ chrome.storage.local.get({
'showReleaseNotes': true 'showReleaseNotes': true
}, function (options) { }, function (options) {
if (options.showReleaseNotes === true) { if (options.showReleaseNotes === true) {
browser.tabs.create({ chrome.tabs.create({
'url': location, 'url': location,
'active': false 'active': false
}); });
...@@ -78,7 +78,7 @@ main._showReleaseNotes = function (details) { ...@@ -78,7 +78,7 @@ main._showReleaseNotes = function (details) {
* Initializations * Initializations
*/ */
browser.runtime.onInstalled.addListener(main._showReleaseNotes); chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
main._initializeOptions(); main._initializeOptions();
chrome.runtime.getPlatformInfo(function (information) { chrome.runtime.getPlatformInfo(function (information) {
......
...@@ -37,40 +37,40 @@ var mappings = { ...@@ -37,40 +37,40 @@ var mappings = {
// Common Shorthand Notations [Deprecated] // Common Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': { 'dojo/1/dojo/dojo.': {
path: 'resources/dojo/1.6.1/dojo/dojo.js.dec', 'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery/1/jquery.': { 'jquery/1/jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec', 'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jqueryui/1/jquery-ui.js': { 'jqueryui/1/jquery-ui.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec', 'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jqueryui/1/jquery-ui.min.js': { 'jqueryui/1/jquery-ui.min.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec', 'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'mootools/1/mootools-yui-compressed.': { 'mootools/1/mootools-yui-compressed.': {
path: 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec', 'path': 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'prototype/1/prototype.': { 'prototype/1/prototype.': {
path: 'resources/prototype/1.7.1.0/prototype.js.dec', 'path': 'resources/prototype/1.7.1.0/prototype.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'scriptaculous/1/scriptaculous.': { 'scriptaculous/1/scriptaculous.': {
path: 'resources/scriptaculous/1.9.0/scriptaculous.js.dec', 'path': 'resources/scriptaculous/1.9.0/scriptaculous.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'swfobject/2/swfobject.': { 'swfobject/2/swfobject.': {
path: 'resources/swfobject/2.2/swfobject.js.dec', 'path': 'resources/swfobject/2.2/swfobject.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'webfont/1/webfont.': { 'webfont/1/webfont.': {
path: 'resources/webfont/1.5.18/webfont.js.dec', 'path': 'resources/webfont/1.5.18/webfont.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
} }
} }
}, },
...@@ -118,52 +118,52 @@ var mappings = { ...@@ -118,52 +118,52 @@ var mappings = {
// Common Shorthand Notations [Deprecated] // Common Shorthand Notations [Deprecated]
'jquery-latest.': { 'jquery-latest.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec', 'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery.': { 'jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec', 'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.3.min.js': { 'jquery-1.3.min.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec', 'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.3.js': { 'jquery-1.3.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec', 'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.4.min.js': { 'jquery-1.4.min.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec', 'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.4.js': { 'jquery-1.4.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec', 'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.5.min.js': { 'jquery-1.5.min.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec', 'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.5.js': { 'jquery-1.5.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec', 'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.6.min.js': { 'jquery-1.6.min.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec', 'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.6.js': { 'jquery-1.6.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec', 'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.7.min.js': { 'jquery-1.7.min.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec', 'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
'jquery-1.7.js': { 'jquery-1.7.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec', 'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
} }
} }
}, },
......
...@@ -19,17 +19,6 @@ ...@@ -19,17 +19,6 @@
var requestAnalyzer = {}; 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 * Public Methods
*/ */
...@@ -96,7 +85,7 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) { ...@@ -96,7 +85,7 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath) { requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath) {
var resourcePath, versionNumber, resourcePattern; let resourcePath, versionNumber, resourcePattern;
resourcePath = channelPath.replace(basePath, ''); resourcePath = channelPath.replace(basePath, '');
...@@ -116,9 +105,9 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel ...@@ -116,9 +105,9 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
// Prepare and return a local target. // Prepare and return a local target.
return { return {
source: channelHost, 'source': channelHost,
version: version, 'version': version,
path: targetPath 'path': targetPath
}; };
} }
} }
...@@ -128,7 +117,6 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel ...@@ -128,7 +117,6 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
requestAnalyzer._applyWhitelistedDomains = function () { requestAnalyzer._applyWhitelistedDomains = function () {
//noinspection JSUnresolvedVariable
chrome.storage.local.get('whitelistedDomains', function (items) { chrome.storage.local.get('whitelistedDomains', function (items) {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {}; requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
}); });
......
...@@ -20,73 +20,73 @@ ...@@ -20,73 +20,73 @@
var resources = { var resources = {
// AngularJS // AngularJS
angular: { 'angular': {
path: 'resources/angularjs/{version}/angular.min.js.dec', 'path': 'resources/angularjs/{version}/angular.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Backbone.js // Backbone.js
backbone: { 'backbone': {
path: 'resources/backbone.js/{version}/backbone-min.js.dec', 'path': 'resources/backbone.js/{version}/backbone-min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Dojo // Dojo
dojo: { 'dojo': {
path: 'resources/dojo/{version}/dojo/dojo.js.dec', 'path': 'resources/dojo/{version}/dojo/dojo.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Ember.js // Ember.js
ember: { 'ember': {
path: 'resources/ember.js/{version}/ember.min.js.dec', 'path': 'resources/ember.js/{version}/ember.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Ext Core // Ext Core
extCore: { 'extCore': {
path: 'resources/ext-core/{version}/ext-core.js.dec', 'path': 'resources/ext-core/{version}/ext-core.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// jQuery // jQuery
jQuery: { 'jQuery': {
path: 'resources/jquery/{version}/jquery.min.js.dec', 'path': 'resources/jquery/{version}/jquery.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// jQuery UI // jQuery UI
jQueryUI: { 'jQueryUI': {
path: 'resources/jqueryui/{version}/jquery-ui.min.js.dec', 'path': 'resources/jqueryui/{version}/jquery-ui.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Modernizr // Modernizr
modernizr: { 'modernizr': {
path: 'resources/modernizr/{version}/modernizr.min.js.dec', 'path': 'resources/modernizr/{version}/modernizr.min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// MooTools // MooTools
mootools: { 'mootools': {
path: 'resources/mootools/{version}/mootools-yui-compressed.js.dec', 'path': 'resources/mootools/{version}/mootools-yui-compressed.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Prototype // Prototype
prototypeJS: { 'prototypeJS': {
path: 'resources/prototype/{version}/prototype.js.dec', 'path': 'resources/prototype/{version}/prototype.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Scriptaculous // Scriptaculous
scriptaculous: { 'scriptaculous': {
path: 'resources/scriptaculous/{version}/scriptaculous.js.dec', 'path': 'resources/scriptaculous/{version}/scriptaculous.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// SWFObject // SWFObject
swfobject: { 'swfobject': {
path: 'resources/swfobject/{version}/swfobject.js.dec', 'path': 'resources/swfobject/{version}/swfobject.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Underscore.js // Underscore.js
underscore: { 'underscore': {
path: 'resources/underscore.js/{version}/underscore-min.js.dec', 'path': 'resources/underscore.js/{version}/underscore-min.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
}, },
// Web Font Loader // Web Font Loader
webfont: { 'webfont': {
path: 'resources/webfont/{version}/webfont.js.dec', 'path': 'resources/webfont/{version}/webfont.js.dec',
type: 'application/javascript' 'type': 'application/javascript'
} }
}; };
...@@ -19,15 +19,6 @@ ...@@ -19,15 +19,6 @@
var stateManager = {}; var stateManager = {};
/**
* Constants
*/
const BLOCKING_ACTION = 'blocking';
const HOST_PREFIX = '*://';
const HOST_SUFFIX = '/*';
const REQUEST_HEADERS = 'requestHeaders';
/** /**
* Public Methods * Public Methods
*/ */
...@@ -47,15 +38,15 @@ stateManager.registerInjection = function (tabIdentifier, injection) { ...@@ -47,15 +38,15 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
if (injectionCount > 0) { if (injectionCount > 0) {
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
tabId: tabIdentifier, 'tabId': tabIdentifier,
text: injectionCount.toString() 'text': injectionCount.toString()
}); });
} else { } else {
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
tabId: tabIdentifier, 'tabId': tabIdentifier,
text: '' 'text': ''
}); });
} }
} }
...@@ -130,7 +121,7 @@ stateManager._createTab = function (tab) { ...@@ -130,7 +121,7 @@ stateManager._createTab = function (tab) {
}); });
}); });
}, requestFilters, [BLOCKING_ACTION]); }, requestFilters, [REQUEST_BLOCKING]);
}; };
stateManager._removeTab = function (tabIdentifier) { stateManager._removeTab = function (tabIdentifier) {
...@@ -151,8 +142,8 @@ stateManager._updateTab = function (details) { ...@@ -151,8 +142,8 @@ stateManager._updateTab = function (details) {
if (stateManager.showIconBadge === true) { if (stateManager.showIconBadge === true) {