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
11
lib/api.js
11
lib/api.js
|
@ -1,14 +1,19 @@
|
|||
(function(chrome) {
|
||||
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
||||
var website = location.protocol + '//' + location.host;
|
||||
switch(request.method) {
|
||||
case 'setData':
|
||||
localStorage['customjs'] = JSON.stringify(request.customjs);
|
||||
var syncdata = {};
|
||||
syncdata[website] = request.customjs;
|
||||
chrome.storage.sync.set(syncdata);
|
||||
case 'getData':
|
||||
var customjs = JSON.parse(localStorage['customjs'] || 'false');
|
||||
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':
|
||||
delete localStorage['customjs'];
|
||||
chrome.storage.sync.remove(website, function() {});
|
||||
break;
|
||||
case 'goTo':
|
||||
window.location = request.link;
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
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);
|
||||
|
@ -30,7 +29,7 @@
|
|||
injectScript(customjs.source, 'body');
|
||||
}, 250);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Reference in a new issue