forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerySelector.js
More file actions
39 lines (38 loc) · 1.26 KB
/
Copy pathquerySelector.js
File metadata and controls
39 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
/**
* Prefix for document.querySelectorAll()
* @param {Object} element - Elements for query selection
* @param {Object} [root=document] - Root selector Element
* @returns {Object} Returns root.querySelectorAll(element)
*/
const qsA = (element, root) => {
root = root ?? document;
return root.querySelectorAll(element);
},
/**
* Prefix for document.querySelector()
* @param {Object} element - Element for query selection
* @param {Object} [root=document] - Root selector Element
* @returns {Object} Returns root.querySelector(element)
*/
qs = (element, root) => {
root = root ?? document;
return root.querySelector(element);
},
/**
* Prefix for document.querySelector() w/ Promise
* @param {Object} element - Element for query selection
* @param {Object} [root=document] - Root selector Element
* @returns {Object} Returns root.querySelector(element)
*/
query = async (element, root) => {
root = root ?? document ?? document.body;
while (
Object.is(root.querySelector(element), null) ||
Object.is(root.querySelector(element), undefined)
) {
await new Promise((resolve) => requestAnimationFrame(resolve));
}
return root.querySelector(element);
};
export { qs, qsA, query };