Skip to content

Commit 4457e1c

Browse files
author
James Fray
committed
first commit
0 parents  commit 4457e1c

File tree

228 files changed

+60030
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+60030
-0
lines changed

common.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* globals validate */
2+
'use strict';
3+
4+
var app = {};
5+
app.callbacks = {};
6+
app.on = (id, callback) => {
7+
app.callbacks[id] = app.callbacks[id] || [];
8+
app.callbacks[id].push(callback);
9+
};
10+
app.emit = (id, value) => (app.callbacks[id] || []).forEach(c => c(value));
11+
12+
var decentraleyes = {};
13+
14+
// importing from detection module from https://github.com/Synzvato/decentraleyes project
15+
(function (iframe) {
16+
iframe.src = './decentraleyes/loader.html';
17+
iframe.onload = function () {
18+
decentraleyes.getLocalTarget = iframe.contentWindow.exports.getLocalTarget;
19+
decentraleyes.mappings = iframe.contentWindow.mappings;
20+
decentraleyes.resources = iframe.contentWindow.resources;
21+
app.emit('decentraleyes-ready');
22+
};
23+
document.body.appendChild(iframe);
24+
})(document.createElement('iframe'));
25+
26+
app.on('decentraleyes-ready', () => {
27+
let mappings = decentraleyes.mappings;
28+
let filter = {
29+
urls: [],
30+
types: ['script', 'xmlhttprequest']
31+
};
32+
for (let host in mappings) {
33+
for (let path in mappings[host]) {
34+
filter.urls.push('*://' + host + path + '*');
35+
}
36+
}
37+
app.emit('filter-ready', filter);
38+
});
39+
40+
var cache = {};
41+
42+
// redirecting to local resource if possible
43+
app.on('filter-ready', (filter) => {
44+
chrome.webRequest.onBeforeRequest.addListener(d => {
45+
let url = new URL(d.url);
46+
let obj = decentraleyes.getLocalTarget(url.hostname, url.pathname);
47+
if (obj) {
48+
if (validate(obj.path)) {
49+
let redirectUrl = chrome.runtime.getURL('data/' + obj.path);
50+
// redirect even if tab is not found
51+
if (cache[d.tabId]) {
52+
cache[d.tabId].push({
53+
hostname: url.hostname,
54+
pathname: url.pathname
55+
});
56+
app.emit('update-badge', d.tabId);
57+
}
58+
else {
59+
console.error('resource is redirected but no tab is found');
60+
}
61+
return {
62+
redirectUrl
63+
};
64+
}
65+
else {
66+
console.error('resource not found', d.url, obj.path);
67+
}
68+
}
69+
return {};
70+
}, filter, ['blocking']);
71+
});
72+
// resetting toolbar badge
73+
chrome.webRequest.onBeforeRequest.addListener(d => {
74+
if (cache[d.tabId]) {
75+
cache[d.tabId] = [];
76+
app.emit('update-badge', d.tabId);
77+
}
78+
}, {
79+
urls: ['<all_urls>'],
80+
types: ['main_frame']
81+
}, []);
82+
83+
// badge
84+
chrome.tabs.query({}, tabs => tabs.forEach(t => cache[t.id] = []));
85+
app.on('update-badge', (tabId) => {
86+
if (!cache[tabId]) {
87+
return;
88+
}
89+
chrome.browserAction.setBadgeText({
90+
tabId,
91+
text: (cache[tabId].length || '') + ''
92+
});
93+
let title = cache[tabId].map((o, i) => (i + 1) + '. ' + o.hostname + ' -> ' + o.pathname.split('/').pop()).join('\n');
94+
title = 'Local CDN' + (title ? '\n\n' + title : '');
95+
chrome.browserAction.setTitle({
96+
tabId,
97+
title
98+
});
99+
});
100+
chrome.tabs.onCreated.addListener((tab) => cache[tab.id] = []);
101+
// cleanup
102+
chrome.tabs.onRemoved.addListener((tabId) => delete cache[tabId]);
103+
// FAQs
104+
chrome.storage.local.get('version', (obj) => {
105+
let version = chrome.runtime.getManifest().version;
106+
if (obj.version !== version) {
107+
chrome.storage.local.set({version}, () => {
108+
chrome.tabs.create({
109+
url: 'http://add0n.com/local-cdn.html?version=' + version + '&type=' +
110+
(obj.version ? ('upgrade&p=' + obj.version) : 'install')
111+
});
112+
});
113+
}
114+
});

data/icons/128.png

3.63 KB
Loading

data/icons/16.png

507 Bytes
Loading

data/icons/256.png

7.14 KB
Loading

data/icons/32.png

962 Bytes
Loading

data/icons/48.png

1.37 KB
Loading

data/icons/512.png

14.9 KB
Loading

data/icons/64.png

1.91 KB
Loading

data/resources/angularjs/1.0.1/angular.min.js.dec

Lines changed: 157 additions & 0 deletions
Large diffs are not rendered by default.

data/resources/angularjs/1.0.2/angular.min.js.dec

Lines changed: 158 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)