Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit422c4067c35e8a33fdb2ac349b746b4492fa21b5 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-11-03 08:30:42 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-11-03 08:32:42 +0200
Fileseed086e0466e88abeef0d55c088af5ddb1f9104c
uni-projects-422c4067c35e8a33fdb2ac349b746b4492fa21b5.tar
uni-projects-422c4067c35e8a33fdb2ac349b746b4492fa21b5.tar.gz
uni-projects-422c4067c35e8a33fdb2ac349b746b4492fa21b5.zip
Parentf4ce0313e7af5d5e32ffe0e0df4d95e9c2a8e6cb (diff)
[OKG] Practicum helper remembers index before reload, has a reload button and is more robust
1 files changed, 27 insertions, 3 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/okg-prac-helper.js30
diff --git a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
index 58c12a2..fdc2619 100644
--- a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
+++ b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
@@ -10,6 +10,11 @@ const scrSel = document.createElement('select');
scrSel.id = 'scrSel';
scrCont.appendChild(scrSel);
+const reloadBtn = document.createElement('button');
+reloadBtn.id = 'reloadBtn';
+reloadBtn.innerHTML = 'Reload';
+scrCont.appendChild(reloadBtn);
+
/* Add options to scrSel, from scripts array */
for (var i = 0; i < scripts.length; i++) {
@@ -30,11 +35,30 @@ function renderScr (index) {
}
var oldIndex = scrSel.value;
-renderScr(scrSel.value);
scrSel.onchange = function() {
- document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
- document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ try {
+ document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
+ document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ } catch(e) {}
+
renderScr(scrSel.value);
oldIndex = scrSel.value;
+ localStorage.setItem('render', scrSel.value);
+}
+
+if (localStorage.getItem('render') !== 0 && localStorage.getItem('render')) {
+ scrSel.value = localStorage.getItem('render');
+ scrSel.onchange();
+} else {
+ renderScr(scrSel.value);
+}
+
+reloadBtn.onclick = function() {
+ try {
+ document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
+ document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ } catch(e) {}
+
+ renderScr(oldIndex);
}