forked from Groshie/groshie.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfengShuiObjectHandler.html
More file actions
171 lines (161 loc) · 6.34 KB
/
fengShuiObjectHandler.html
File metadata and controls
171 lines (161 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!doctype HTML>
<html>
<head>
</head>
<script>
/*
#############################################
### Lägga till värden i en lista-program! ###
#############################################
*/
/*
#############################
# 1. Variabler #
# 2. Objekt #
# 3. Funktioner #
#############################
*/
/*
################
# 1. Variabler #
################
*/
var entriesString;
/*
#############
# 2. Objekt #
#############
*/
var entriesObject = {};
/*
#################
# 3. Funktioner #
#################
*/
function init() {
// Funktion som körs när sidan laddar
console.log("By: Groshie (2021)")
if (!(localStorage.getItem("fengShuiObject"))) {
console.log("Inget sparat objekt sedan tidigare, nollställer lista!");
entriesObject = {};
localStorage.setItem("fengShuiObject", JSON.stringify(entriesObject));
} else {
console.log("Återställer objekt från senaste sessionen!");
entriesObject = JSON.parse(localStorage.getItem("fengShuiObject"))
document.getElementById("rawText").innerHTML = "<p>" + JSON.stringify(entriesObject) + "</p>";
let tableText = "";
for (mainCat in entriesObject) {
tableText += "<h3>" + mainCat + "</h3>";
for (subCat in entriesObject[mainCat]) {
tableText += "<p><em>" + subCat + "</em></p>";
tableText += "<p><u>Attribute:</u> " + entriesObject[mainCat][subCat]["attr"] + ", <u>Cost:</u> " + entriesObject[mainCat][subCat]["cost"] + ", <u>Time:</u> " + entriesObject[mainCat][subCat]["time"] + "</p>";
tableText += "<p><u>Description:</u><br>" + entriesObject[mainCat][subCat]["descr"] + "</p>";
}
tableText += "<hr>";
}
document.getElementById("tableText").innerHTML = tableText;
document.getElementById("right").style.display = "block";
}
return
}
function addToObject(attr, main, sub, cost, time, descr) {
// Funktion för att lägga till värden i objektet
if (!(entriesObject[main])) {
entriesObject[main] = {};
}
if (!(entriesObject[main][sub])) {
entriesObject[main][sub] = {};
}
entriesObject[main][sub]["attr"] = attr;
entriesObject[main][sub]["cost"] = cost;
entriesObject[main][sub]["time"] = time;
entriesObject[main][sub]["descr"] = descr;
//console.log(entriesObject);
document.getElementById("right").style.display = "block";
document.getElementById("rawText").innerHTML = "<p>" + JSON.stringify(entriesObject) + "</p>";
localStorage.setItem("fengShuiObject", JSON.stringify(entriesObject));
let tableText = "";
for (mainCat in entriesObject) {
tableText += "<h3>" + mainCat + "</h3>";
for (subCat in entriesObject[mainCat]) {
tableText += "<p><em>" + subCat + "</em></p>";
tableText += "<p><u>Attribute:</u> " + entriesObject[mainCat][subCat]["attr"] + ", <u>Cost:</u> " + entriesObject[mainCat][subCat]["cost"] + ", <u>Time:</u> " + entriesObject[mainCat][subCat]["time"] + "</p>";
tableText += "<p><u>Description:</u><br>" + entriesObject[mainCat][subCat]["descr"] + "</p>";
}
tableText += "<hr>";
}
document.getElementById("tableText").innerHTML = tableText;
return entriesObject
}
function downloadData(obj) {
// Funktion för att ladda ned json i strängformat, txt-fil
var dataStr = "data:text/txt;charset=utf-8," + encodeURIComponent(JSON.stringify(obj));
var downloadElement = document.createElement('a');
downloadElement.setAttribute("href", dataStr);
downloadElement.setAttribute("download", "FengShuiObject.txt");
document.body.appendChild(downloadElement); // required for firefox
downloadElement.click();
downloadElement.remove();
}
function loadObject() {
// Funktion för att ladda objekt från en json i strängformat
let loadObject = prompt("Klistra in objektet i textform nedan.\nOm det inte visas är JSON-formatet fel.");
entriesObject = JSON.parse(loadObject);
if (entriesObject !== Object(JSON.parse(loadObject))) {
alert("Not valid JSON!");
return
}
document.getElementById("rawText").innerHTML = "<p>" + JSON.stringify(entriesObject) + "</p>";
localStorage.setItem("fengShuiObject", JSON.stringify(entriesObject));
let tableText = "";
for (mainCat in entriesObject) {
tableText += "<h3>" + mainCat + "</h3>";
for (subCat in entriesObject[mainCat]) {
tableText += "<p><em>" + subCat + "</em></p>";
tableText += "<p><u>Attribute:</u> " + entriesObject[mainCat][subCat]["attr"] + ", <u>Cost:</u> " + entriesObject[mainCat][subCat]["cost"] + ", <u>Time:</u> " + entriesObject[mainCat][subCat]["time"] + "</p>";
tableText += "<p><u>Description:</u><br>" + entriesObject[mainCat][subCat]["descr"] + "</p>";
}
tableText += "<hr>";
}
document.getElementById("tableText").innerHTML = tableText;
document.getElementById("right").style.display = "block";
return entriesObject
}
</script>
<style>
h1,h2,h3,p {font-family: calibri;color: white}
body {background-color: black;margin:20px}
.split {float: left;width: 50%}
.hidden {display: none}
</style>
<title>Feng Shui: Object handler</title>
</head>
<body onload="init()">
<h1>Feng Shui | Object Handler</h1>
<div id="left" class="split">
<h3>Huvudkategori (ex. Skills)</h3>
<input name="adds" id="mainCat"></input>
<h3>Underkategori (ex. Martial arts)</h3>
<input name="adds" id="subCat"></input>
<h3>Attribut (ex. Agility)</h3>
<input name="adds" id="attr"></input>
<h3>Resurskostnad (ex. 0)</h3>
<input name="adds" id="cost"></input>
<h3>Tidskostnad/shots (ex. 3)</h3>
<input name="adds" id="time"></input>
<h3>Beskrivning (ex. "Handlar om...")</h3>
<textarea name="adds" id="descr"></textarea>
<p><button onclick="addToObject(document.getElementById('attr').value, document.getElementById('mainCat').value, document.getElementById('subCat').value, document.getElementById('cost').value, document.getElementById('time').value, document.getElementById('descr').value)">Lägg till</button>
<button onclick="entriesObject={}">Nollställ</button>
<button id="downloadButton" onclick="downloadData(entriesObject)">Ladda ned</button></p>
<p>Du kan också ladda ett objekt från en textsträng (JSON-format):</p>
<button id="loadObjectButton" onclick="loadObject()">Ladda objekt</button>
</div>
<div id="right" class="split hidden">
<h2>Objekt - Rå text:</h2>
<p id="rawText"></p>
<h2>Objekt - Strukturerat innehåll:</h2>
<div id="tableText"></div>
</div>
</body>
</html>