mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Add localstorage migration for iframe
This commit is contained in:
80
src/migrate.html
Normal file
80
src/migrate.html
Normal file
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Coriolis: Migrate to HTTPS</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
function fromJsonToObject(str) {
|
||||
try {
|
||||
var o = JSON.parse(str);
|
||||
if (o instanceof Object && !(o instanceof Array)) {
|
||||
return o;
|
||||
}
|
||||
} catch (e) { }
|
||||
return {};
|
||||
}
|
||||
|
||||
function listener(event) {
|
||||
var origin = event.origin || event.originalEvent.origin;
|
||||
var source = event.source;
|
||||
var data = event.message;
|
||||
|
||||
// Uncomment for production
|
||||
// if (origin !== "http://coriolis.io") {
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
var builds = fromJsonToObject(localStorage.getItem('builds'));
|
||||
var comparisons = fromJsonToObject(localStorage.getItem('comparisons'));
|
||||
|
||||
// merge builds
|
||||
if (typeof data.builds == 'object') {
|
||||
|
||||
for (var bName in data.builds) {
|
||||
// Build existing in http and does not existing in HTTPS
|
||||
if (data.builds.hasOwnProperty(bName) && !builds[bName]) {
|
||||
build[bName] = data.builds[bName];
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem('builds', JSON.stringify(builds));
|
||||
}
|
||||
// merge comparisons
|
||||
if (typeof data.comparisons == 'object') {
|
||||
|
||||
for (var comp in data.comparisons) {
|
||||
// Comparison existing in http and does not existing in HTTPS
|
||||
if (data.comparisons.hasOwnProperty(comp) && !data.comparisons[comp]) {
|
||||
comparisons[comp] = data.comparisons[comp];
|
||||
}
|
||||
}
|
||||
localStorage.setItem('comparisons', JSON.stringify(comparisons));
|
||||
}
|
||||
|
||||
source.postMessage({
|
||||
success: true,
|
||||
buildCount: Object.keys(builds).length,
|
||||
comparisonCount: Object.keys(comparisons).length
|
||||
}, origin);
|
||||
|
||||
} catch (e) {
|
||||
source.postMessage({ success: false, error: e }, origin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (window.addEventListener){
|
||||
window.addEventListener("message", listener, false);
|
||||
} else {
|
||||
window.attachEvent("onmessage", listener);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user