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) {
|
||||
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
||||
switch(request.method) {
|
||||
case 'setData':
|
||||
localStorage['customjs'] = JSON.stringify(request.customjs);
|
||||
case 'getData':
|
||||
var customjs = JSON.parse(localStorage['customjs'] || 'false');
|
||||
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
|
||||
break;
|
||||
case 'removeData':
|
||||
delete localStorage['customjs'];
|
||||
break;
|
||||
case 'goTo':
|
||||
window.location = request.link;
|
||||
break;
|
||||
default:
|
||||
sendResponse({src: '', config: {}});
|
||||
}
|
||||
if( request.reload ) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
||||
var website = location.protocol + '//' + location.host;
|
||||
switch(request.method) {
|
||||
case 'setData':
|
||||
var syncdata = {};
|
||||
syncdata[website] = request.customjs;
|
||||
chrome.storage.sync.set(syncdata);
|
||||
case 'getData':
|
||||
chrome.storage.sync.get(website, function(obj) {
|
||||
var customjs = obj[website] || JSON.parse('false');
|
||||
sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
|
||||
});
|
||||
break;
|
||||
case 'removeData':
|
||||
chrome.storage.sync.remove(website, function() {});
|
||||
break;
|
||||
case 'goTo':
|
||||
window.location = request.link;
|
||||
break;
|
||||
default:
|
||||
sendResponse({src: '', config: {}});
|
||||
}
|
||||
if( request.reload ) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
})(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 injectScript(src, where) {
|
||||
var elm = document.createElement('script');
|
||||
elm.src = src;
|
||||
document[where || 'head'].appendChild(elm);
|
||||
}
|
||||
function injectScript(src, where) {
|
||||
var elm = document.createElement('script');
|
||||
elm.src = src;
|
||||
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 ) {
|
||||
customjs = JSON.parse(customjs);
|
||||
|
||||
if( customjs.config.enable ) {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if( customjs.config.enable ) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Reference in a new issue