1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2025-08-17 01:31:42 +02:00
Files
.github
.idea
.vscode
app
.idea
Desktop
Resources
Icons
Schemas
Tracker
Viewer
scripts
bootstrap.js
discord.js
dom.js
gui.js
processor.js
settings.js
state.js
template.js
styles
index.html
Server
Utils
.gitignore
DiscordHistoryTracker.sln
Version.cs
build.bat
build.sh
empty.dht
global.json
minify.py
bld
lib
src
tools
web
.gitattributes
.gitignore
LICENSE.md
README.md
build.py
reserve.txt
2021-06-19 10:40:34 +02:00

55 lines
1.4 KiB
JavaScript

const HTML_ENTITY_MAP = {
"&": "&",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"'": "&#39;"
};
const HTML_ENTITY_REGEX = /[&<>"']/g;
class DOM {
/**
* Returns a child element by its ID. Parent defaults to the entire document.
*/
static id(id, parent) {
return (parent || document).getElementById(id);
}
/**
* Returns an array of all child elements containing the specified class. Parent defaults to the entire document.
*/
static cls(cls, parent) {
return Array.prototype.slice.call((parent || document).getElementsByClassName(cls));
}
/**
* Returns an array of all child elements that have the specified tag. Parent defaults to the entire document.
*/
static tag(tag, parent) {
return Array.prototype.slice.call((parent || document).getElementsByTagName(tag));
}
/**
* Returns the first child element containing the specified class. Parent defaults to the entire document.
*/
static fcls(cls, parent) {
return (parent || document).getElementsByClassName(cls)[0];
}
/**
* Converts characters to their HTML entity form.
*/
static escapeHTML(html) {
return String(html).replace(HTML_ENTITY_REGEX, s => HTML_ENTITY_MAP[s]);
}
/**
* Converts a timestamp into a human readable time, using the browser locale.
*/
static getHumanReadableTime(timestamp) {
const date = new Date(timestamp);
return date.toLocaleDateString() + ", " + date.toLocaleTimeString();
};
}