diff --git a/README.md b/README.md index d687279..693a672 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ A [web browser extension](https://decentraleyes.org) that emulates Content Deliv > **Note:** Decentraleyes is no silver bullet, but it does prevent a lot of websites from making you send these kinds of requests. Ultimately, you can make Decentraleyes block requests for any missing CDN resources, too. +## Custom Resources + +You can set a folder path to a custom resource folder in Addon options menu. Place your versions of supported resources, complying with the scheme of bundled resources (without .dec extension). See resources.js paths for currently supported resources and file names. +Example: [YourFolder]/resources/jquery/3.2.1/jquery.min.js + ## Roadmap Now that there's a solid, Mozilla approved, foundation, it's time to move forward. Mobility, extensibility (through support for community-powered resource packages), and usability, will be the main points of attention during this phase. diff --git a/lib/data-handler.js b/lib/data-handler.js index a9894ef..23f0d9c 100644 --- a/lib/data-handler.js +++ b/lib/data-handler.js @@ -19,22 +19,18 @@ var { Cc, Ci } = require('chrome'); var self = require('sdk/self'); +var fileIO = require("sdk/io/file"); //noinspection JSUnresolvedFunction var ioService = Cc['@mozilla.org/network/io-service;1'] .getService(Ci.nsIIOService); -/** - * Absolute resource file paths. - * @var {object} files - */ -var files = require('./files'); - /** * Constants */ const DELIVERY_NOTICE = '/**\n * Local delivery by Decentraleyes (' + self.version + ').\n */\n\n'; +const PATH_SEP = require('sdk/fs/path').sep; /** * Variables @@ -46,17 +42,39 @@ var resourceData = self.data; * Public Methods */ -function getRedirectionURI(targetPath, characterSet, type) { - - var data, dataURI, redirectionURI; - - data = _loadResource(targetPath); - dataURI = _buildDataURI(type, characterSet, data); - redirectionURI = ioService.newURI(dataURI, null, null); - +function getRedirectionURI(targetPath, characterSet, type, userDir) {    + var data, dataURI, redirectionURI;     + var invalidationChar = false;         + + data = _loadUserResource(targetPath, userDir);  //First, attempt to load from User Resource Dir     + if (data == "")    {         + data = _loadResource(targetPath); //After, check bundled Resources         + invalidationChar = true;     + }    + dataURI = _buildDataURI(type, characterSet, data, invalidationChar);    + redirectionURI = ioService.newURI(dataURI, null, null);        return redirectionURI; } +function _loadUserResource(targetPath, userDir){ + if (!userDir || userDir == "") return ""; + if (!userDir.endsWith("/") && !userDir.endsWith("\\")) + userDir += PATH_SEP; + var userTargetPath = userDir + targetPath.substring(0, targetPath.length-4); + userTargetPath = userTargetPath.replace(/\//g, PATH_SEP).replace(/\\/g, PATH_SEP); + var text = ""; + try { + if (fileIO.exists(userTargetPath)) { + var file = fileIO.open(userTargetPath, "r"); + if (!file.closed) { + text = file.read(); + file.close(); + } + } + } catch (e) {} + return text; +} + /** * Exports */ @@ -71,16 +89,16 @@ function _loadResource(targetPath) { var resource; - // Find the result inside a static path index. - if (!files[targetPath]) { - throw new Error('The requested resource is missing.'); - } - - // Attempt to load resource contents. - return resource = resourceData.load(targetPath); +    try {         + resource = resourceData.load(targetPath);     + }     + catch (e) {         + throw new Error('The requested resource is missing.');     + }         + return resource; } -function _buildDataURI(type, characterSet, data) { +function _buildDataURI(type, characterSet, data, stripfirst) { var addNotice, dataURI; @@ -88,8 +106,9 @@ function _buildDataURI(type, characterSet, data) { addNotice = require('sdk/simple-prefs').prefs.addNotice; dataURI = 'data:' + type + ';charset=' + characterSet + ','; - // Remove the syntax invalidation character. - data = data.substring(1); +    // Remove the syntax invalidation character for bundled resources.     + if (stripfirst)         + data = data.substring(1); if (!addNotice) { dataURI = dataURI + encodeURIComponent(data); diff --git a/lib/files.js b/lib/files.js deleted file mode 100644 index cb45448..0000000 --- a/lib/files.js +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Files - * Belongs to Decentraleyes. - * - * @author Thomas Rientjes - * @since 2014-07-24 - * @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'; - -/** - * Files - */ - -var files = { - - // AngularJS - 'resources/angularjs/1.0.1/angular.min.js.dec': true, - 'resources/angularjs/1.0.2/angular.min.js.dec': true, - 'resources/angularjs/1.0.3/angular.min.js.dec': true, - 'resources/angularjs/1.0.4/angular.min.js.dec': true, - 'resources/angularjs/1.0.5/angular.min.js.dec': true, - 'resources/angularjs/1.0.6/angular.min.js.dec': true, - 'resources/angularjs/1.0.8/angular.min.js.dec': true, - 'resources/angularjs/1.2.0/angular.min.js.dec': true, - 'resources/angularjs/1.2.1/angular.min.js.dec': true, - 'resources/angularjs/1.2.10/angular.min.js.dec': true, - 'resources/angularjs/1.2.15/angular.min.js.dec': true, - 'resources/angularjs/1.2.16/angular.min.js.dec': true, - 'resources/angularjs/1.2.20/angular.min.js.dec': true, - 'resources/angularjs/1.2.23/angular.min.js.dec': true, - 'resources/angularjs/1.2.26/angular.min.js.dec': true, - 'resources/angularjs/1.2.28/angular.min.js.dec': true, - 'resources/angularjs/1.2.29/angular.min.js.dec': true, - 'resources/angularjs/1.3.0/angular.min.js.dec': true, - 'resources/angularjs/1.3.3/angular.min.js.dec': true, - 'resources/angularjs/1.3.8/angular.min.js.dec': true, - 'resources/angularjs/1.3.10/angular.min.js.dec': true, - 'resources/angularjs/1.3.11/angular.min.js.dec': true, - 'resources/angularjs/1.3.14/angular.min.js.dec': true, - 'resources/angularjs/1.3.15/angular.min.js.dec': true, - 'resources/angularjs/1.4.0/angular.min.js.dec': true, - 'resources/angularjs/1.4.2/angular.min.js.dec': true, - 'resources/angularjs/1.4.8/angular.min.js.dec': true, - - // Backbone.js - 'resources/backbone.js/0.9.0/backbone-min.js.dec': true, - 'resources/backbone.js/0.9.1/backbone-min.js.dec': true, - 'resources/backbone.js/0.9.2/backbone-min.js.dec': true, - 'resources/backbone.js/0.9.9/backbone-min.js.dec': true, - 'resources/backbone.js/0.9.10/backbone-min.js.dec': true, - 'resources/backbone.js/1.0.0/backbone-min.js.dec': true, - 'resources/backbone.js/1.1.0/backbone-min.js.dec': true, - 'resources/backbone.js/1.1.1/backbone-min.js.dec': true, - 'resources/backbone.js/1.1.2/backbone-min.js.dec': true, - 'resources/backbone.js/1.2.0/backbone-min.js.dec': true, - 'resources/backbone.js/1.2.1/backbone-min.js.dec': true, - 'resources/backbone.js/1.2.2/backbone-min.js.dec': true, - 'resources/backbone.js/1.2.3/backbone-min.js.dec': true, - - // Dojo - 'resources/dojo/1.4.1/dojo/dojo.js.dec': true, - 'resources/dojo/1.4.5/dojo/dojo.js.dec': true, - 'resources/dojo/1.5.0/dojo/dojo.js.dec': true, - 'resources/dojo/1.6.1/dojo/dojo.js.dec': true, - 'resources/dojo/1.7.5/dojo/dojo.js.dec': true, - 'resources/dojo/1.8.3/dojo/dojo.js.dec': true, - 'resources/dojo/1.8.7/dojo/dojo.js.dec': true, - 'resources/dojo/1.8.9/dojo/dojo.js.dec': true, - 'resources/dojo/1.9.1/dojo/dojo.js.dec': true, - 'resources/dojo/1.9.3/dojo/dojo.js.dec': true, - 'resources/dojo/1.9.7/dojo/dojo.js.dec': true, - 'resources/dojo/1.10.4/dojo/dojo.js.dec': true, - - // Ember.js - 'resources/ember.js/1.0.1/ember.min.js.dec': true, - 'resources/ember.js/1.1.3/ember.min.js.dec': true, - 'resources/ember.js/1.2.2/ember.min.js.dec': true, - 'resources/ember.js/1.3.2/ember.min.js.dec': true, - 'resources/ember.js/1.4.0/ember.min.js.dec': true, - 'resources/ember.js/1.5.1/ember.min.js.dec': true, - 'resources/ember.js/2.0.0/ember.min.js.dec': true, - 'resources/ember.js/2.0.2/ember.min.js.dec': true, - 'resources/ember.js/2.1.0/ember.min.js.dec': true, - - // Ext Core - 'resources/ext-core/3.0.0/ext-core.js.dec': true, - 'resources/ext-core/3.1.0/ext-core.js.dec': true, - - // jQuery - 'resources/jquery/1.2.3/jquery.min.js.dec': true, - 'resources/jquery/1.2.6/jquery.min.js.dec': true, - 'resources/jquery/1.3.0/jquery.min.js.dec': true, - 'resources/jquery/1.3.1/jquery.min.js.dec': true, - 'resources/jquery/1.3.2/jquery.min.js.dec': true, - 'resources/jquery/1.4.0/jquery.min.js.dec': true, - 'resources/jquery/1.4.1/jquery.min.js.dec': true, - 'resources/jquery/1.4.2/jquery.min.js.dec': true, - 'resources/jquery/1.4.3/jquery.min.js.dec': true, - 'resources/jquery/1.4.4/jquery.min.js.dec': true, - 'resources/jquery/1.5.0/jquery.min.js.dec': true, - 'resources/jquery/1.5.1/jquery.min.js.dec': true, - 'resources/jquery/1.5.2/jquery.min.js.dec': true, - 'resources/jquery/1.6.0/jquery.min.js.dec': true, - 'resources/jquery/1.6.1/jquery.min.js.dec': true, - 'resources/jquery/1.6.2/jquery.min.js.dec': true, - 'resources/jquery/1.6.3/jquery.min.js.dec': true, - 'resources/jquery/1.6.4/jquery.min.js.dec': true, - 'resources/jquery/1.7.0/jquery.min.js.dec': true, - 'resources/jquery/1.7.1/jquery.min.js.dec': true, - 'resources/jquery/1.7.2/jquery.min.js.dec': true, - 'resources/jquery/1.8.0/jquery.min.js.dec': true, - 'resources/jquery/1.8.1/jquery.min.js.dec': true, - 'resources/jquery/1.8.2/jquery.min.js.dec': true, - 'resources/jquery/1.8.3/jquery.min.js.dec': true, - 'resources/jquery/1.9.0/jquery.min.js.dec': true, - 'resources/jquery/1.9.1/jquery.min.js.dec': true, - 'resources/jquery/1.10.0/jquery.min.js.dec': true, - 'resources/jquery/1.10.1/jquery.min.js.dec': true, - 'resources/jquery/1.10.2/jquery.min.js.dec': true, - 'resources/jquery/1.11.0/jquery.min.js.dec': true, - 'resources/jquery/1.11.1/jquery.min.js.dec': true, - 'resources/jquery/1.11.2/jquery.min.js.dec': true, - 'resources/jquery/1.11.3/jquery.min.js.dec': true, - 'resources/jquery/1.12.0/jquery.min.js.dec': true, - 'resources/jquery/1.12.1/jquery.min.js.dec': true, - 'resources/jquery/1.12.2/jquery.min.js.dec': true, - 'resources/jquery/1.12.3/jquery.min.js.dec': true, - 'resources/jquery/1.12.4/jquery.min.js.dec': true, - 'resources/jquery/2.0.0/jquery.min.js.dec': true, - 'resources/jquery/2.0.1/jquery.min.js.dec': true, - 'resources/jquery/2.0.2/jquery.min.js.dec': true, - 'resources/jquery/2.0.3/jquery.min.js.dec': true, - 'resources/jquery/2.1.0/jquery.min.js.dec': true, - 'resources/jquery/2.1.1/jquery.min.js.dec': true, - 'resources/jquery/2.1.3/jquery.min.js.dec': true, - 'resources/jquery/2.1.4/jquery.min.js.dec': true, - - // jQuery UI - 'resources/jqueryui/1.5.3/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.6.0/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.7.3/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.8.24/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.9.2/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.11.0/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.11.1/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.11.2/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.11.3/jquery-ui.min.js.dec': true, - 'resources/jqueryui/1.11.4/jquery-ui.min.js.dec': true, - - // Modernizr - 'resources/modernizr/2.6.2/modernizr.min.js.dec': true, - 'resources/modernizr/2.7.1/modernizr.min.js.dec': true, - 'resources/modernizr/2.7.2/modernizr.min.js.dec': true, - 'resources/modernizr/2.8.2/modernizr.min.js.dec': true, - 'resources/modernizr/2.8.3/modernizr.min.js.dec': true, - - // MooTools - 'resources/mootools/1.1.1/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.2.1/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.2.3/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.2.4/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.2.5/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.3.0/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.3.1/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.3.2/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.4.1/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.4.5/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.5.0/mootools-yui-compressed.js.dec': true, - 'resources/mootools/1.5.1/mootools-yui-compressed.js.dec': true, - - // Prototype - 'resources/prototype/1.6.0.2/prototype.js.dec': true, - 'resources/prototype/1.6.0.3/prototype.js.dec': true, - 'resources/prototype/1.6.1.0/prototype.js.dec': true, - 'resources/prototype/1.7.0.0/prototype.js.dec': true, - 'resources/prototype/1.7.1.0/prototype.js.dec': true, - 'resources/prototype/1.7.2.0/prototype.js.dec': true, - 'resources/prototype/1.7.3.0/prototype.js.dec': true, - - // Scriptaculous - 'resources/scriptaculous/1.8.1/scriptaculous.js.dec': true, - 'resources/scriptaculous/1.8.2/scriptaculous.js.dec': true, - 'resources/scriptaculous/1.8.3/scriptaculous.js.dec': true, - 'resources/scriptaculous/1.9.0/scriptaculous.js.dec': true, - - // SWFObject - 'resources/swfobject/2.1/swfobject.js.dec': true, - 'resources/swfobject/2.2/swfobject.js.dec': true, - - // Underscore.js - 'resources/underscore.js/1.3.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.3.1/underscore-min.js.dec': true, - 'resources/underscore.js/1.3.3/underscore-min.js.dec': true, - 'resources/underscore.js/1.4.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.4.1/underscore-min.js.dec': true, - 'resources/underscore.js/1.4.2/underscore-min.js.dec': true, - 'resources/underscore.js/1.4.3/underscore-min.js.dec': true, - 'resources/underscore.js/1.4.4/underscore-min.js.dec': true, - 'resources/underscore.js/1.5.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.5.1/underscore-min.js.dec': true, - 'resources/underscore.js/1.5.2/underscore-min.js.dec': true, - 'resources/underscore.js/1.6.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.7.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.8.0/underscore-min.js.dec': true, - 'resources/underscore.js/1.8.1/underscore-min.js.dec': true, - 'resources/underscore.js/1.8.2/underscore-min.js.dec': true, - 'resources/underscore.js/1.8.3/underscore-min.js.dec': true, - - // Web Font Loader - 'resources/webfont/1.0.0/webfont.js.dec': true, - 'resources/webfont/1.0.1/webfont.js.dec': true, - 'resources/webfont/1.0.2/webfont.js.dec': true, - 'resources/webfont/1.0.3/webfont.js.dec': true, - 'resources/webfont/1.0.4/webfont.js.dec': true, - 'resources/webfont/1.0.5/webfont.js.dec': true, - 'resources/webfont/1.0.6/webfont.js.dec': true, - 'resources/webfont/1.0.9/webfont.js.dec': true, - 'resources/webfont/1.0.10/webfont.js.dec': true, - 'resources/webfont/1.0.11/webfont.js.dec': true, - 'resources/webfont/1.0.12/webfont.js.dec': true, - 'resources/webfont/1.0.13/webfont.js.dec': true, - 'resources/webfont/1.0.14/webfont.js.dec': true, - 'resources/webfont/1.0.15/webfont.js.dec': true, - 'resources/webfont/1.0.16/webfont.js.dec': true, - 'resources/webfont/1.0.17/webfont.js.dec': true, - 'resources/webfont/1.0.18/webfont.js.dec': true, - 'resources/webfont/1.0.19/webfont.js.dec': true, - 'resources/webfont/1.0.21/webfont.js.dec': true, - 'resources/webfont/1.0.22/webfont.js.dec': true, - 'resources/webfont/1.0.23/webfont.js.dec': true, - 'resources/webfont/1.0.24/webfont.js.dec': true, - 'resources/webfont/1.0.25/webfont.js.dec': true, - 'resources/webfont/1.0.26/webfont.js.dec': true, - 'resources/webfont/1.0.27/webfont.js.dec': true, - 'resources/webfont/1.0.28/webfont.js.dec': true, - 'resources/webfont/1.0.29/webfont.js.dec': true, - 'resources/webfont/1.0.30/webfont.js.dec': true, - 'resources/webfont/1.0.31/webfont.js.dec': true, - 'resources/webfont/1.1.0/webfont.js.dec': true, - 'resources/webfont/1.1.1/webfont.js.dec': true, - 'resources/webfont/1.1.2/webfont.js.dec': true, - 'resources/webfont/1.3.0/webfont.js.dec': true, - 'resources/webfont/1.4.2/webfont.js.dec': true, - 'resources/webfont/1.4.6/webfont.js.dec': true, - 'resources/webfont/1.4.7/webfont.js.dec': true, - 'resources/webfont/1.4.8/webfont.js.dec': true, - 'resources/webfont/1.4.10/webfont.js.dec': true, - 'resources/webfont/1.5.0/webfont.js.dec': true, - 'resources/webfont/1.5.2/webfont.js.dec': true, - 'resources/webfont/1.5.3/webfont.js.dec': true, - 'resources/webfont/1.5.6/webfont.js.dec': true, - 'resources/webfont/1.5.10/webfont.js.dec': true, - 'resources/webfont/1.5.18/webfont.js.dec': true -}; - -/** - * Exports - */ - -module.exports = files; diff --git a/lib/interceptor.js b/lib/interceptor.js index 262a305..1e70a9b 100644 --- a/lib/interceptor.js +++ b/lib/interceptor.js @@ -97,7 +97,7 @@ var Interceptor = new Class({ // Fetch local data and create a redirection URI. try { - redirectionURI = dataHandler.getRedirectionURI(target.path, characterSet, target.type); + redirectionURI = dataHandler.getRedirectionURI(target.path, characterSet, target.type, preferences.userContentDir); } catch (exception) { return this.handleMissingCandidate(httpChannel); } diff --git a/locale/de/options.dtd b/locale/de/options.dtd index 61ff3e5..cb0a2a6 100644 --- a/locale/de/options.dtd +++ b/locale/de/options.dtd @@ -6,3 +6,5 @@ + + diff --git a/locale/en-GB/options.dtd b/locale/en-GB/options.dtd index 4bff19b..ad5e256 100644 --- a/locale/en-GB/options.dtd +++ b/locale/en-GB/options.dtd @@ -6,3 +6,5 @@ + + diff --git a/locale/en-US/options.dtd b/locale/en-US/options.dtd index 4bff19b..ad5e256 100644 --- a/locale/en-US/options.dtd +++ b/locale/en-US/options.dtd @@ -6,3 +6,5 @@ + + diff --git a/options.xul b/options.xul index 1d09829..1ae9e96 100644 --- a/options.xul +++ b/options.xul @@ -5,4 +5,5 @@ &options.blockMissing.description; &options.domainWhitelist.description; &options.amountInjected.description; + &options.userContentDir.description;