diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/htmlbuilder.js | 2 | ||||
-rw-r--r-- | lib/popups.js | 34 | ||||
-rw-r--r-- | lib/t.js | 26 |
3 files changed, 61 insertions, 1 deletions
diff --git a/lib/htmlbuilder.js b/lib/htmlbuilder.js index 483b77b..110da39 100644 --- a/lib/htmlbuilder.js +++ b/lib/htmlbuilder.js @@ -8,7 +8,7 @@ function makeSigmaHtmlPlusElement(elem) { elem.innerHTML = html; return elem; } - elem.text = function (text) { + elem.text = elem.txt = function (text) { elem.innerText = text; return elem; } diff --git a/lib/popups.js b/lib/popups.js new file mode 100644 index 0000000..3d7e592 --- /dev/null +++ b/lib/popups.js @@ -0,0 +1,34 @@ +function DocElemListFromHTML(html) { + return new DOMParser().parseFromString(html, "text/html").body.childNodes; +} + +/** AboutPad popup system */ +export function openPopup(html) { + document.querySelector(".ap-popup-container").classList.remove("hidden") + document.querySelector(".ap-popup").innerHTML = "" + let popup = document.querySelector(".ap-popup") + let elems; + console.log(typeof html) + if(typeof html == 'string') { + let htm = String(html) + htm = htm.replace(/\$\((.*?)\)\$/g, (a) => { + return eval(a.replace(/\$\((.*?)\)\$/g, "$1")) + }) + elems = DocElemListFromHTML(String(htm)) + } else elems = [html] + let len = elems.length + for (let i = 0; i < len; i++) { + const element = elems[0]; + popup.appendChild(element) + } + let closeBtn = document.querySelector("#ap-btn-close-popup") + if(closeBtn) closeBtn.addEventListener('click', (ev) => { + document.querySelector(".ap-popup-container").classList.add("hidden") + }) +} + +document.querySelector(".ap-popup-container").addEventListener("click", function(ev) { + if(ev.target != this) return; + this.classList.add("hidden") + console.log("click!", ev) +}) \ No newline at end of file diff --git a/lib/t.js b/lib/t.js new file mode 100644 index 0000000..77af51f --- /dev/null +++ b/lib/t.js @@ -0,0 +1,26 @@ +export function timeSince(date) { + const seconds = Math.floor((new Date() - date) / 1000); + + const interval = seconds / 31536000; + + if (interval > 1) { + return Math.floor(interval) + " years"; + } + interval = seconds / 2592000; + if (interval > 1) { + return Math.floor(interval) + " months"; + } + interval = seconds / 86400; + if (interval > 1) { + return Math.floor(interval) + " days"; + } + interval = seconds / 3600; + if (interval > 1) { + return Math.floor(interval) + " hours"; + } + interval = seconds / 60; + if (interval > 1) { + return Math.floor(interval) + " minutes"; + } + return Math.floor(seconds) + " seconds"; +} \ No newline at end of file |