Skip to content

Commit e586765

Browse files
committed
- Update adds new utilities
- Change namespace from an object to a class - Adds a file to test libraries
1 parent 704964a commit e586765

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

_lib/utility.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
// ==UserScript==
2-
// @name Edexal Utility Library
2+
// @name Edexal's Utility Library
33
// @namespace 1330126-edexal
44
// @license Unlicense
5-
// @version 1.1
5+
// @version 2.0
66
// @author Edexal
77
// @description Utility library for common reusable tasks
88
// ==/UserScript==
9-
const edexal = {
10-
//Apply custom styles in a style tag
11-
applyCSS(css) {
9+
class Edexal {
10+
static addCSS(css) {
1211
let styleEl = document.querySelector("style");
1312
if (styleEl === null) {
1413
styleEl = document.createElement('style');
1514
}
1615
styleEl.appendChild(document.createTextNode(css));
1716
document.head.appendChild(styleEl);
1817
}
19-
//Test
20-
}
18+
19+
static newEl(elObj) {
20+
if (!Object.hasOwn(elObj, 'element')) return;
21+
const el = document.createElement(elObj.element);
22+
const {element, ...otherObjs} = elObj;
23+
for (const [key, val] of Object.entries(otherObjs)) {
24+
switch (key) {
25+
case 'class':
26+
el.classList.add(...val);
27+
break;
28+
case 'text':
29+
const txt = document.createTextNode(val);
30+
el.append(txt);
31+
break;
32+
default:
33+
el.setAttribute(key, val);
34+
break;
35+
}
36+
}
37+
return el;
38+
}
39+
40+
static onEv(el, eventType, callback, options) {
41+
el.addEventListener(eventType, callback, options);
42+
}
43+
}

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="description" content="This is a test document page">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<script src="_lib/utility.js" defer></script>
8+
<script src="_lib/game-request-templates.js" defer></script>
9+
<title>Test Document</title>
10+
</head>
11+
<body>
12+
<h1>Hello World!</h1>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)