File tree Expand file tree Collapse file tree 2 files changed +44
-7
lines changed
Expand file tree Collapse file tree 2 files changed +44
-7
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments