--- /dev/null
+"use strict";
+
+var greeting = {
+ /**
+ * Configuration
+ *
+ * Keys:
+ * storageKey {string} Prefix for localStorage keys
+ * greetingSelector {string} Selector for the element containing the greeting
+ * defaultHidden {boolean} Hidden by default?
+ */
+ config: {
+ storageKey: "greeting",
+ greetingSelector: "header h1",
+ defaultHidden: false,
+ },
+
+ /**
+ * Current greeting
+ */
+ text: "",
+
+ /**
+ * Wether the greeting is hidden
+ */
+ hidden: false,
+
+ /**
+ * Initialize greeting.js
+ */
+ init: function(greetingSelector = null, storageKey = null, hidden = null){
+ if (greetingSelector !== null) {
+ greeting.config.greetingSelector = greetingSelector;
+ }
+ if (storageKey !== null) {
+ greeting.config.storageKey = storageKey;
+ }
+ if (hidden !== null) {
+ greeting.config.defaultHidden = hidden;
+ }
+
+ // Read storage
+ greeting.readStorage();
+
+ // Update/set greeting element's content
+ greeting.update();
+ },
+
+ /**
+ * Get the HTMLElement matching config.greetingSelector
+ */
+ getElem: function() {
+ return document.querySelector(greeting.config.greetingSelector);
+ },
+
+ /**
+ * Set greeting.text to the value in localStorage.
+ * If the storage entry did not exist, default to getElem()'s
+ * innerText
+ */
+ readStorage: function(){
+ greeting.text = localStorage.getItem(greeting.config.storageKey + "_text");
+ if (greeting.text == null) {
+ // migrate old config
+ greeting.text = localStorage.getItem(greeting.config.storageKey);
+ if (greeting.text !== null) {
+ localStorage.setItem(greeting.config.storageKey + "_text", greeting.text);
+ } else {
+ // No greeting stored until now
+ greeting.text = greeting.getElem().innerText;
+ if (greeting.text.length < 1) {
+ greeting.text = "hello";
+ }
+ }
+ }
+
+ greeting.hidden = localStorage.getItem(greeting.config.storageKey + "_hidden");
+ if (greeting.hidden == null) {
+ // No greeting stored until now
+ greeting.hidden = greeting.config.defaultHidden;
+ }
+ },
+
+ /**
+ * Set a new greeting
+ */
+ set: function(newGreeting){
+ if (newGreeting === null || newGreeting.length < 1)
+ return false;
+
+ greeting.text = newGreeting;
+ //localStorage.setItem(greeting.config.storageKey, greeting.text);
+ greeting.update();
+ },
+
+ /**
+ * Update the greeting HTML element by setting it
+ * to greeting.text, and store it in localStorage
+ */
+ update: function(){
+ greeting.getElem().innerText = greeting.text;
+ localStorage.setItem(
+ greeting.config.storageKey + "_text",
+ greeting.text
+ );
+ localStorage.setItem(
+ greeting.config.storageKey + "_hidden",
+ greeting.hidden
+ );
+ },
+
+ /**
+ * Hide the greeting
+ */
+ hide: function(permanent = false){
+ console.debug('greeting.hide(): Hiding "'+greeting.config.greetingSelector+'"');
+ greeting.getElem().style.display = "none";
+ greeting.getElem().style.visibility = "hidden";
+ if (permanent === true) {
+ greeting.hidden = true;
+ greeting.update();
+ }
+ },
+
+ /**
+ * Un-Hide a.k.a. show the greeting
+ */
+ unHide: function(permanent = false){
+ console.debug('greeting.unHide(): Showing "'+greeting.config.greetingSelector+'"');
+ greeting.getElem().style.display = "";
+ greeting.getElem().style.visibility = "";
+ if (permanent === true) {
+ greeting.hidden = false;
+ greeting.update();
+ }
+ },
+};
--- /dev/null
+window.whoami = {
+ init: function() {
+ console.log("whoami.init()");
+ if (!this.section) {
+ this.section = document.getElementById("whoami")
+ }
+
+ this.whoami_user = localStorage.getItem("whoami_user");
+ this.whoami_host = localStorage.getItem("whoami_host");
+ this.whoami_format = localStorage.getItem("whoami_format");
+
+ if (!this.whoami_user) {
+ console.log("Asking for username");
+ this.whoami_user = prompt("Your user name", "malte70");
+ if (this.whoami_user === null)
+ this.whoami_user = "malte70";
+ }
+ if (!this.whoami_host) {
+ console.log("Asking for hostname");
+ this.whoami_host = prompt("Hostname", "localhost");
+ if (this.whoami_host === null)
+ this.whoami_host = "pc";
+ }
+ if (!this.whoami_format) {
+ console.log("Asking for format");
+ this.whoami_format = prompt("Format (unix|windows)", "unix");
+ if (this.whoami_format === null)
+ this.whoami_format = "windows";
+ }
+
+ /*var urlParams = new URLSearchParams(window.location.search);
+ if (!urlParams.has('user')) {
+ this.whoami_user = null;
+ } else {
+ this.whoami_user = urlParams.get('user');
+ this.whoami_host = "PLUTO";
+ }*/
+ },
+ deinit: function() {
+ localStorage.removeItem("whoami_user");
+ localStorage.removeItem("whoami_host");
+ localStorage.removeItem("whoami_format");
+ },
+ settings: function() {
+ console.log("whoami.settings()");
+ this.whoami_user = prompt("Your user name", localStorage.getItem("whoami_user"));
+ this.whoami_host = prompt("Hostname", localStorage.getItem("whoami_host"));
+ this.whoami_format = prompt("Format (unix|windows)", localStorage.getItem("whoami_format"));
+
+ if (this.whoami_user === null)
+ this.whoami_user = "malte70";
+ if (this.whoami_host === null) {
+ if (localStorage.getItem("whoami_host") !== null) {
+ this.whoami_host = localStorage.getItem("whoami_host");
+ } else {
+ this.whoami_host = "pc";
+ }
+ }
+ if (this.whoami_format === null)
+ this.whoami_format = "windows";
+
+ console.table(
+ [
+ ["whoami_user", this.whoami_user],
+ ["whoami_host", this.whoami_host],
+ ["whoami_format", this.whoami_format],
+ ]
+ );
+
+ this.update();
+ },
+ update: function() {
+ // Update localstorage
+ localStorage.setItem("whoami_user", this.whoami_user);
+ localStorage.setItem("whoami_host", this.whoami_host);
+ localStorage.setItem("whoami_format", this.whoami_format);
+
+ if (this.whoami_format.toLowerCase() == "windows") {
+ if (this.whoami_user == "root" || this.whoami_user == "admin")
+ this.whoami_user = "Administrator";
+
+ if (this.whoami_host == this.whoami_host.toLowerCase() && this.whoami_host != "localhost")
+ this.whoami_host = this.whoami_host.toUpperCase()
+
+ // strip domain from fqdn
+ this.whoami_host = this.whoami_host.substr(
+ 0,
+ this.whoami_host.indexOf(".")
+ );
+ user_login = '<span class="red">\\\\</span>'
+ + this.whoami_host
+ + '<span class="red">\\</span>'
+ + this.whoami_user;
+
+ } else {
+ user_login = this.whoami_user
+ + '<span class="red">@</span>'
+ + this.whoami_host;
+
+ }
+
+ this.section.innerHTML = '<p>'+user_login+'</p>';
+ },
+};
+window.notepad = function(selector, storageKey) {
+ //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")")
+
+ elem = document.querySelector(selector);
+ if (localStorage.getItem(storageKey) !== null) {
+ console.log("window.notepad(): Loading from LocalStorage")
+ elem.innerHTML = localStorage.getItem("notepad");
+ }
+ elem.addEventListener("focusout", function() {
+ console.log("window.notepad(): Focus lost. Storing on LocalStorage");
+ localStorage.setItem(storageKey, document.querySelector(selector).innerHTML);
+ });
+ //document.querySelector(selector).onclick = function() {
+ // localStorage.setItem(storageKey, document.querySelector(selector).innerHTML);
+ //};
+};
+window.onload = function() {
+ window.whoami.init();
+ window.whoami.update();
+
+ document.querySelector(
+ "button#settings"
+ ).onclick = function() {
+ window.whoami.settings();
+ //window.whoami.update();
+ };
+
+ window.notepad("#notepadContent", "notepad");
+
+ /**
+ * Hide footer
+ */
+ //document.getElementsByTagName("footer")[0].remove()
+};
+++ /dev/null
-window.whoami = {
- init: function() {
- console.log("whoami.init()");
- if (!this.section) {
- this.section = document.getElementById("whoami")
- }
-
- this.whoami_user = localStorage.getItem("whoami_user");
- this.whoami_host = localStorage.getItem("whoami_host");
- this.whoami_format = localStorage.getItem("whoami_format");
-
- if (!this.whoami_user) {
- console.log("Asking for username");
- this.whoami_user = prompt("Your user name", "malte70");
- if (this.whoami_user === null)
- this.whoami_user = "malte70";
- }
- if (!this.whoami_host) {
- console.log("Asking for hostname");
- this.whoami_host = prompt("Hostname", "localhost");
- if (this.whoami_host === null)
- this.whoami_host = "pc";
- }
- if (!this.whoami_format) {
- console.log("Asking for format");
- this.whoami_format = prompt("Format (unix|windows)", "unix");
- if (this.whoami_format === null)
- this.whoami_format = "windows";
- }
-
- /*var urlParams = new URLSearchParams(window.location.search);
- if (!urlParams.has('user')) {
- this.whoami_user = null;
- } else {
- this.whoami_user = urlParams.get('user');
- this.whoami_host = "PLUTO";
- }*/
-
- },
- deinit: function() {
- localStorage.removeItem("whoami_user");
- localStorage.removeItem("whoami_host");
- localStorage.removeItem("whoami_format");
- },
- settings: function() {
- console.log("whoami.settings()");
- this.whoami_user = prompt("Your user name", localStorage.getItem("whoami_user"));
- this.whoami_host = prompt("Hostname", localStorage.getItem("whoami_host"));
- this.whoami_format = prompt("Format (unix|windows)", localStorage.getItem("whoami_format"));
-
- if (this.whoami_user === null)
- this.whoami_user = "malte70";
- if (this.whoami_host === null) {
- if (localStorage.getItem("whoami_host") !== null) {
- this.whoami_host = localStorage.getItem("whoami_host");
- } else {
- this.whoami_host = "pc";
- }
- }
- if (this.whoami_format === null)
- this.whoami_format = "windows";
-
- console.table(
- [
- ["whoami_user", this.whoami_user],
- ["whoami_host", this.whoami_host],
- ["whoami_format", this.whoami_format],
- ]
- );
-
- this.update();
- },
- update: function() {
- // Update localstorage
- localStorage.setItem("whoami_user", this.whoami_user);
- localStorage.setItem("whoami_host", this.whoami_host);
- localStorage.setItem("whoami_format", this.whoami_format);
-
- if (this.whoami_format.toLowerCase() == "windows") {
- if (this.whoami_user == "root" || this.whoami_user == "admin")
- this.whoami_user = "Administrator";
-
- if (this.whoami_host == this.whoami_host.toLowerCase() && this.whoami_host != "localhost")
- this.whoami_host = this.whoami_host.toUpperCase()
-
- // strip domain from fqdn
- this.whoami_host = this.whoami_host.substr(
- 0,
- this.whoami_host.indexOf(".")
- );
- user_login = '<span class="red">\\\\</span>'
- + this.whoami_host
- + '<span class="red">\\</span>'
- + this.whoami_user;
-
- } else {
- user_login = this.whoami_user
- + '<span class="red">@</span>'
- + this.whoami_host;
-
- }
-
- this.section.innerHTML = '<p>'+user_login+'</p>';
- },
-};
-window.notepad = function(selector, storageKey) {
- //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")")
-
- elem = document.querySelector(selector);
- if (localStorage.getItem(storageKey) !== null) {
- console.log("window.notepad(): Loading from LocalStorage")
- elem.innerHTML = localStorage.getItem("notepad");
- }
- elem.addEventListener("focusout", function() {
- console.log("window.notepad(): Focus lost. Storing on LocalStorage");
- localStorage.setItem(storageKey, document.querySelector(selector).innerHTML);
- });
- //document.querySelector(selector).onclick = function() {
- // localStorage.setItem(storageKey, document.querySelector(selector).innerHTML);
- //};
-};
-window.onload = function() {
- window.whoami.init();
- window.whoami.update();
-
- document.querySelector(
- "button#settings"
- ).onclick = function() {
- window.whoami.settings();
- //window.whoami.update();
- };
-
- window.notepad("#notepadContent", "notepad");
-
- /**
- * Hide footer
- */
- //document.getElementsByTagName("footer")[0].remove()
-};
+++ /dev/null
-var greeting = {
- config: {
- storageKey: "greeting",
- greetingSelector: "header h1"
- },
- // current greeting
- text: "",
-
- /**
- * Initialize greeting.js
- */
- init: function(greetingSelector = null, storageKey = null){
- if (greetingSelector !== null) {
- greeting.config.greetingSelector = greetingSelector;
- }
- if (storageKey !== null) {
- greeting.config.storageKey = storageKey;
- }
-
- // Read storage
- greeting.readStorage();
-
- // Update/set greeting element's content
- greeting.update();
- },
-
- /**
- * Get the HTMLElement matching config.greetingSelector
- */
- getElem: function() {
- return document.querySelector(greeting.config.greetingSelector);
- },
-
- /**
- * Set greeting.text to the value in localStorage.
- * If the storage entry did not exist, default to getElem()'s
- * innerText
- */
- readStorage: function(){
- greeting.text = localStorage.getItem(greeting.config.storageKey);
- if (greeting.text == null) {
- // No greeting stored until now
- greeting.text = greeting.getElem().innerText;
- if (greeting.text.length < 1) {
- greeting.text = "hello";
- }
- }
- },
-
- /**
- * Set a new greeting
- */
- set: function(newGreeting){
- if (newGreeting.length < 1)
- return false;
-
- greeting.text = newGreeting;
- //localStorage.setItem(greeting.config.storageKey, greeting.text);
- greeting.update();
- },
-
- /**
- * Update the greeting HTML element by setting it
- * to greeting.text, and store it in localStorage
- */
- update: function(){
- greeting.getElem().innerText = greeting.text;
- localStorage.setItem(
- greeting.config.storageKey,
- greeting.text
- );
- },
-};
<title>Startseite</title>
- <link rel="stylesheet" type="text/css" href="../../normalize.css">
+ <link rel="stylesheet" type="text/css" href="https://xyz.malte70.de/css/normalize.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/png" sizes="512x512" href="https://dev.malte70.de/tango-icons/img/go-home-512.png">
</head>
</section>
</main>
- <script type="text/javascript" src="greeting.js"></script>
+ <script type="text/javascript" src="../js/greeting.js"></script>
<script type="text/javascript">
window.onload = function() {
var _useragent = navigator.userAgent;
</main>
<?php if ($Data["JS"]): ?>
<footer>
- <p>
- <button type="button" id="settings">Settings…</button>
- </p>
+ <p>
+ <button type="button" id="settings">Settings…</button>
+ </p>
<p>
© <?=$Data["Footer"]["CopyrightYear"]?> <a href="<?=$Data["Footer"]["AuthorURL"]?>" rel="me nofollow"><?=$Data["Footer"]["AuthorName"]?></a>
· <a href="https://ftp.malte70.de/pub/malte70-startseite.tar.gz" download>Download (.tar.gz)</a>
</p>
</footer>
- <!--<script src="main.js"></script>-->
+ <!--<script src="js/main.js"></script>-->
<script>
- <?php
- require("main.js");
- ?>
+ <?php
+ require("js/main.js");
+ ?>
</script>
<?php endif; ?>
</body>