use chrome storage sync instead of localStorage
This commit is contained in:
parent
39b83914d2
commit
8b7d62f0d3
3 changed files with 636 additions and 632 deletions
47
lib/api.js
47
lib/api.js
|
@ -1,24 +1,29 @@
|
||||||
(function(chrome) {
|
(function(chrome) {
|
||||||
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
||||||
switch(request.method) {
|
var website = location.protocol + '//' + location.host;
|
||||||
case 'setData':
|
switch(request.method) {
|
||||||
localStorage['customjs'] = JSON.stringify(request.customjs);
|
case 'setData':
|
||||||
case 'getData':
|
var syncdata = {};
|
||||||
var customjs = JSON.parse(localStorage['customjs'] || 'false');
|
syncdata[website] = request.customjs;
|
||||||
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
|
chrome.storage.sync.set(syncdata);
|
||||||
break;
|
case 'getData':
|
||||||
case 'removeData':
|
chrome.storage.sync.get(website, function(obj) {
|
||||||
delete localStorage['customjs'];
|
var customjs = obj[website] || JSON.parse('false');
|
||||||
break;
|
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
|
||||||
case 'goTo':
|
});
|
||||||
window.location = request.link;
|
break;
|
||||||
break;
|
case 'removeData':
|
||||||
default:
|
chrome.storage.sync.remove(website, function() {});
|
||||||
sendResponse({src: '', config: {}});
|
break;
|
||||||
}
|
case 'goTo':
|
||||||
if( request.reload ) {
|
window.location = request.link;
|
||||||
window.location.reload();
|
break;
|
||||||
}
|
default:
|
||||||
});
|
sendResponse({src: '', config: {}});
|
||||||
|
}
|
||||||
|
if( request.reload ) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})(chrome);
|
})(chrome);
|
||||||
|
|
1162
lib/popup.js
1162
lib/popup.js
File diff suppressed because it is too large
Load diff
59
lib/run.js
59
lib/run.js
|
@ -1,36 +1,35 @@
|
||||||
(function() {
|
(function() {
|
||||||
function injectScript(src, where) {
|
function injectScript(src, where) {
|
||||||
var elm = document.createElement('script');
|
var elm = document.createElement('script');
|
||||||
elm.src = src;
|
elm.src = src;
|
||||||
document[where || 'head'].appendChild(elm);
|
document[where || 'head'].appendChild(elm);
|
||||||
}
|
}
|
||||||
|
|
||||||
var customjs = localStorage['customjs'];
|
var website = location.protocol + '//' + location.host;
|
||||||
|
chrome.storage.sync.get(website, function(obj) {
|
||||||
|
var customjs = obj[website];
|
||||||
if( customjs ) {
|
if( customjs ) {
|
||||||
customjs = JSON.parse(customjs);
|
if( customjs.config.enable ) {
|
||||||
|
// Predefined include
|
||||||
if( customjs.config.enable ) {
|
if( customjs.config.include ) {
|
||||||
|
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
|
||||||
// Predefined include
|
|
||||||
if( customjs.config.include ) {
|
|
||||||
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extra include
|
|
||||||
var extra = (customjs.config.extra || '').split(';');
|
|
||||||
extra.forEach(function(line) {
|
|
||||||
if( line.substr(0, 1) !== '#' ) {
|
|
||||||
injectScript(line);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Script
|
|
||||||
if( customjs.source ) {
|
|
||||||
setTimeout(function() {
|
|
||||||
injectScript(customjs.source, 'body');
|
|
||||||
}, 250);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extra include
|
||||||
|
var extra = (customjs.config.extra || '').split(';');
|
||||||
|
extra.forEach(function(line) {
|
||||||
|
if( line.substr(0, 1) !== '#' ) {
|
||||||
|
injectScript(line);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Script
|
||||||
|
if( customjs.source ) {
|
||||||
|
setTimeout(function() {
|
||||||
|
injectScript(customjs.source, 'body');
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
|
Reference in a new issue