Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function initListeners(){

var queryString = window.location.href.split("?");
if(queryString.length > 1){
loadForceFromString(queryString[1]);
loadForceFromString(safeDecompressForce(queryString[1]));
}else{
clearForce();
}
Expand Down Expand Up @@ -312,7 +312,7 @@ function updateLanguage(json){
forceString = queryString[1];
}
clearForce();
loadForceFromString(forceString);
loadForceFromString(safeDecompressForce(forceString));
}

function clearForce(){
Expand Down Expand Up @@ -2202,12 +2202,12 @@ function updateCaps(){
});

if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + getStringForForce();
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + getStringForForce(true);
window.history.pushState({path:newurl},'',newurl);
}
}

function getStringForForce(){
function getStringForForce(compress = false){
var forceString = "f=" + faction + ";";
forceString += "n=" + document.getElementById("listNameArea").value + ";";
if(force.hasOwnProperty("leader")){
Expand All @@ -2223,6 +2223,9 @@ function getStringForForce(){
forceString += charString;
});
}
if (compress) {
return LZString.compressToEncodedURIComponent(JSON.stringify(forceString));
}
return forceString;
}

Expand Down Expand Up @@ -2433,10 +2436,18 @@ function importFileHandler() {
let importData = fileElement.files[0];
const reader = new FileReader();
reader.onload = () => {
loadForceFromString(reader.result);
loadForceFromString(safeDecompressForce(reader.result));
};
reader.readAsText(importData);
} else {
console.log("No file selected for import!");
}
}

function safeDecompressForce(forceData){
if (forceData.startsWith("f=")){
return forceData;
} else {
return LZString.decompressFromEncodedURIComponent(forceData);
}
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js" integrity="sha512-qtX0GLM3qX8rxJN1gyDfcnMFFrKvixfoEOwbBib9VafR5vbChV5LeE5wSI/x+IlCkTY5ZFddFDCCfaVJJNnuKQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="builder.js"></script>
<script src="nixie.js"></script>
</head>
Expand Down