1
0
Fork 0

use chrome storage sync instead of localStorage

This commit is contained in:
xcv58 2015-04-15 15:58:54 -04:00 committed by Lukas Winkler
parent 39b83914d2
commit 8b7d62f0d3
3 changed files with 636 additions and 632 deletions

View file

@ -1,14 +1,19 @@
(function(chrome) { (function(chrome) {
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
var website = location.protocol + '//' + location.host;
switch(request.method) { switch(request.method) {
case 'setData': case 'setData':
localStorage['customjs'] = JSON.stringify(request.customjs); var syncdata = {};
syncdata[website] = request.customjs;
chrome.storage.sync.set(syncdata);
case 'getData': 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}); sendResponse({customjs: customjs, host: location.host, protocol: location.protocol});
});
break; break;
case 'removeData': case 'removeData':
delete localStorage['customjs']; chrome.storage.sync.remove(website, function() {});
break; break;
case 'goTo': case 'goTo':
window.location = request.link; window.location = request.link;

View file

@ -5,12 +5,11 @@
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 ) { if( customjs.config.enable ) {
// Predefined include // Predefined include
if( customjs.config.include ) { if( customjs.config.include ) {
injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include); injectScript('https://ajax.googleapis.com/ajax/libs' + customjs.config.include);
@ -30,7 +29,7 @@
injectScript(customjs.source, 'body'); injectScript(customjs.source, 'body');
}, 250); }, 250);
} }
} }
} }
});
})(); })();