parent
1bf2dae945
commit
871f31c6f9
@ -0,0 +1,30 @@ |
||||
var queryParams = require('./query-params'); |
||||
|
||||
function handleLoad(cb) { |
||||
var params = queryParams.get(); |
||||
var loadingFromGist = false; |
||||
if (typeof params['gist'] != undefined) { |
||||
var gistId; |
||||
if (params['gist'] === '') { |
||||
var str = prompt("Enter the URL or ID of the Gist you would like to load."); |
||||
if (str !== '') { |
||||
gistId = getGistId( str ); |
||||
loadingFromGist = !!gistId; |
||||
} |
||||
} else { |
||||
gistId = params['gist']; |
||||
loadingFromGist = !!gistId; |
||||
} |
||||
if (loadingFromGist) cb(gistId); |
||||
}
|
||||
} |
||||
|
||||
function getGistId(str) { |
||||
var idr = /[0-9A-Fa-f]{8,}/; |
||||
var match = idr.exec(str); |
||||
return match ? match[0] : null; |
||||
} |
||||
|
||||
module.exports = { |
||||
handleLoad: handleLoad |
||||
}; |
@ -0,0 +1,36 @@ |
||||
function getQueryParams() { |
||||
var qs = window.location.hash.substr(1); |
||||
|
||||
if (window.location.search.length > 0) { |
||||
// use legacy query params instead of hash
|
||||
window.location.hash = window.location.search.substr(1); |
||||
window.location.search = ""; |
||||
} |
||||
|
||||
var params = {}; |
||||
var parts = qs.split("&"); |
||||
for (var x in parts) { |
||||
var keyValue = parts[x].split("="); |
||||
if (keyValue[0] !== "") params[keyValue[0]] = keyValue[1]; |
||||
} |
||||
return params; |
||||
} |
||||
|
||||
function updateQueryParams(params) { |
||||
var currentParams = getQueryParams(); |
||||
var keys = Object.keys(params); |
||||
for (var x in keys) { |
||||
currentParams[keys[x]] = params[keys[x]]; |
||||
} |
||||
var queryString = "#"; |
||||
var updatedKeys = Object.keys(currentParams); |
||||
for( var y in updatedKeys) { |
||||
queryString += updatedKeys[y] + "=" + currentParams[updatedKeys[y]] + "&"; |
||||
} |
||||
window.location.hash = queryString.slice(0, -1); |
||||
} |
||||
|
||||
module.exports = { |
||||
get: getQueryParams, |
||||
update: updateQueryParams, |
||||
}; |
@ -0,0 +1,40 @@ |
||||
function StorageHandler(SOL_CACHE_FILE_PREFIX) { |
||||
|
||||
this.sync = function() { |
||||
|
||||
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) return; |
||||
|
||||
var obj = {}; |
||||
var done = false; |
||||
var count = 0 |
||||
var dont = 0; |
||||
|
||||
function check(key){ |
||||
chrome.storage.sync.get( key, function(resp){ |
||||
console.log("comparing to cloud", key, resp); |
||||
if (typeof resp[key] != 'undefined' && obj[key] !== resp[key] && confirm("Overwrite '" + fileNameFromKey(key) + "'? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.")) { |
||||
console.log("Overwriting", key ); |
||||
localStorage.setItem( key, resp[key] ); |
||||
updateFiles(); |
||||
} else { |
||||
console.log( "add to obj", obj, key); |
||||
obj[key] = localStorage[key]; |
||||
} |
||||
done++; |
||||
if (done >= count) chrome.storage.sync.set( obj, function(){ |
||||
console.log( "updated cloud files with: ", obj, this, arguments); |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
for (var y in window.localStorage) { |
||||
console.log("checking", y); |
||||
obj[y] = window.localStorage.getItem(y); |
||||
if (y.indexOf(SOL_CACHE_FILE_PREFIX) !== 0) continue; |
||||
count++; |
||||
check(y); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
module.exports = StorageHandler; |
Loading…
Reference in new issue