doc-access 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +1 -0
- package/.prettierrc +4 -1
- package/{CONTRIBUTE.md → CONTRIBUTING.md} +1 -1
- package/dist/doc-access.d.ts +3 -3
- package/dist/doc-access.js +3 -3
- package/dist/modules/doc-access-classes.js +4 -3
- package/dist/modules/doc-access-functions.d.ts +1 -1
- package/dist/modules/doc-access-functions.js +18 -17
- package/package.json +8 -1
- package/src/doc-access.ts +3 -3
- package/src/modules/doc-access-classes.ts +61 -29
- package/src/modules/doc-access-extra.ts +9 -3
- package/src/modules/doc-access-functions.ts +76 -40
package/.prettierignore
CHANGED
package/.prettierrc
CHANGED
package/dist/doc-access.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./modules/doc-access-classes";
|
|
2
|
+
export * from "./modules/doc-access-functions";
|
|
3
|
+
export * from "./modules/doc-access-extra";
|
package/dist/doc-access.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
if (typeof document === "undefined") {
|
|
2
2
|
throw new Error("Not a browser!");
|
|
3
3
|
}
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
4
|
+
export * from "./modules/doc-access-classes.js";
|
|
5
|
+
export * from "./modules/doc-access-functions.js";
|
|
6
|
+
export * from "./modules/doc-access-extra.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { check_inv_html_elem, err_msg_finisher } from
|
|
1
|
+
import { check_inv_html_elem, err_msg_finisher } from "./doc-access-extra.js";
|
|
2
2
|
class Detacher {
|
|
3
3
|
parent;
|
|
4
4
|
err_msg;
|
|
@@ -76,8 +76,9 @@ export class Accessible_Section extends Detacher {
|
|
|
76
76
|
this.#heading_text = value;
|
|
77
77
|
this.heading.textContent = this.#heading_text;
|
|
78
78
|
const heading_text_copy = this.heading.textContent
|
|
79
|
-
.
|
|
80
|
-
.toLowerCase()
|
|
79
|
+
.trim()
|
|
80
|
+
.toLowerCase()
|
|
81
|
+
.replace(/\s+/g, "") + "-heading";
|
|
81
82
|
this.heading.id = heading_text_copy;
|
|
82
83
|
this.self.setAttribute("aria-labelledby", this.heading.id);
|
|
83
84
|
// console.info("Updated heading text");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Heading_Choice } from
|
|
1
|
+
import { Heading_Choice } from "./doc-access-classes";
|
|
2
2
|
/** Makes existing grouped sections containing the describer heading WCAG friendly (omitting contrast)
|
|
3
3
|
*
|
|
4
4
|
* WARNING: Replaces both the section and heading ID
|
|
@@ -15,17 +15,15 @@ const returning_msg_ = "Returning...";
|
|
|
15
15
|
export const grouped_sections_accessible = (class_name, heading_choice, search_parent) => {
|
|
16
16
|
if (!search_parent)
|
|
17
17
|
search_parent = document.body;
|
|
18
|
-
if (!
|
|
18
|
+
if (!class_name.trim().startsWith(".")) {
|
|
19
19
|
console.warn("Class name must start with a dot!");
|
|
20
20
|
}
|
|
21
|
-
const sections = search_parent.
|
|
22
|
-
querySelectorAll(`${class_name}`);
|
|
21
|
+
const sections = search_parent.querySelectorAll(`${class_name}`);
|
|
23
22
|
if (!sections.length) {
|
|
24
23
|
throw new Error(`Can't find sections! ${returning_msg_}`);
|
|
25
24
|
}
|
|
26
|
-
sections.forEach(section => {
|
|
27
|
-
const heading = section
|
|
28
|
-
.querySelector(heading_choice);
|
|
25
|
+
sections.forEach((section) => {
|
|
26
|
+
const heading = section.querySelector(heading_choice);
|
|
29
27
|
if (!heading) {
|
|
30
28
|
throw new Error(`Can't find ${heading_choice}! ${returning_msg_}`);
|
|
31
29
|
}
|
|
@@ -34,8 +32,9 @@ export const grouped_sections_accessible = (class_name, heading_choice, search_p
|
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
const heading_text_copy = heading.textContent
|
|
37
|
-
.
|
|
38
|
-
.toLowerCase()
|
|
35
|
+
.trim()
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/\s+/g, "") + "-heading";
|
|
39
38
|
heading.id = heading_text_copy;
|
|
40
39
|
section.setAttribute("aria-labelledby", heading.id);
|
|
41
40
|
});
|
|
@@ -48,14 +47,16 @@ export const grouped_sections_accessible = (class_name, heading_choice, search_p
|
|
|
48
47
|
export const all_headings_nav_friendly = (parent) => {
|
|
49
48
|
if (!parent)
|
|
50
49
|
parent = document.body;
|
|
51
|
-
const all_headings = parent
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!(heading.textContent)) {
|
|
50
|
+
const all_headings = parent.querySelectorAll("h2, h3, h4, h5, h6");
|
|
51
|
+
all_headings.forEach((heading) => {
|
|
52
|
+
if (!heading.textContent) {
|
|
55
53
|
console.warn(`A heading's text content is empty! Heading number: ${heading.tagName}`);
|
|
56
54
|
}
|
|
57
|
-
heading.id =
|
|
58
|
-
|
|
55
|
+
heading.id =
|
|
56
|
+
heading.textContent
|
|
57
|
+
.trim()
|
|
58
|
+
.toLowerCase()
|
|
59
|
+
.replace(/\s+/g, "") + "-heading";
|
|
59
60
|
});
|
|
60
61
|
};
|
|
61
62
|
/** Makes an existing link open in a new tab when activated
|
|
@@ -67,9 +68,9 @@ export const all_headings_nav_friendly = (parent) => {
|
|
|
67
68
|
export const new_tab_existing = (existing_link, secure, accessible) => {
|
|
68
69
|
const skipping_msg_ = "Skipping...";
|
|
69
70
|
existing_link.target = "_blank";
|
|
70
|
-
if (typeof
|
|
71
|
+
if (typeof secure !== "boolean")
|
|
71
72
|
secure = true;
|
|
72
|
-
if (typeof
|
|
73
|
+
if (typeof accessible != "boolean")
|
|
73
74
|
accessible = true;
|
|
74
75
|
if (existing_link.rel === "noopener noreferrer") {
|
|
75
76
|
console.warn(`${existing_link.id || "Existing link"} - already secure! ${skipping_msg_}`);
|
|
@@ -99,7 +100,7 @@ export const new_tab_existing = (existing_link, secure, accessible) => {
|
|
|
99
100
|
export const wait = (time_in_ms, abort) => {
|
|
100
101
|
return new Promise((resolve, reject) => {
|
|
101
102
|
const timeout = setTimeout(resolve, time_in_ms);
|
|
102
|
-
abort?.addEventListener(
|
|
103
|
+
abort?.addEventListener("abort", () => {
|
|
103
104
|
clearTimeout(timeout);
|
|
104
105
|
reject(new Error(`Delay removed! ${time_in_ms}`));
|
|
105
106
|
}, { once: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doc-access",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A JS/TS module that reduces coding time spent on accessibility.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Placewith5s",
|
|
@@ -24,6 +24,13 @@
|
|
|
24
24
|
"import": "./dist/doc_access.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/Placewith5s/doc-access.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Placewith5s/doc-access/issues"
|
|
33
|
+
},
|
|
27
34
|
"scripts": {
|
|
28
35
|
"build": "tsc",
|
|
29
36
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/doc-access.ts
CHANGED
|
@@ -2,6 +2,6 @@ if (typeof document === "undefined") {
|
|
|
2
2
|
throw new Error("Not a browser!");
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
5
|
+
export * from "./modules/doc-access-classes";
|
|
6
|
+
export * from "./modules/doc-access-functions";
|
|
7
|
+
export * from "./modules/doc-access-extra";
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
check_inv_html_elem,
|
|
3
3
|
err_msg_finisher
|
|
4
|
-
} from
|
|
5
|
-
|
|
6
|
-
export type Heading_Choice = "h2" | "h3" | "h4" | "h5" | "h6";
|
|
4
|
+
} from "./doc-access-extra";
|
|
7
5
|
|
|
6
|
+
export type Heading_Choice =
|
|
7
|
+
| "h2"
|
|
8
|
+
| "h3"
|
|
9
|
+
| "h4"
|
|
10
|
+
| "h5"
|
|
11
|
+
| "h6";
|
|
8
12
|
|
|
9
13
|
class Detacher {
|
|
10
14
|
parent: HTMLElement;
|
|
11
15
|
err_msg: string;
|
|
12
|
-
|
|
13
|
-
constructor
|
|
16
|
+
|
|
17
|
+
constructor(parent: HTMLElement, err_msg: string) {
|
|
14
18
|
this.parent = parent;
|
|
15
19
|
this.err_msg = err_msg;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/** Removes parent node, removing its children in the process
|
|
19
|
-
*
|
|
23
|
+
*
|
|
20
24
|
* @returns {void}
|
|
21
25
|
*/
|
|
22
26
|
detach(): void {
|
|
@@ -38,11 +42,15 @@ export class Elem extends Detacher {
|
|
|
38
42
|
* @param {HTMLElement} [parent] - Default: body
|
|
39
43
|
* @param {string} [id]
|
|
40
44
|
*/
|
|
41
|
-
constructor
|
|
45
|
+
constructor(
|
|
46
|
+
tag_name: keyof HTMLElementTagNameMap,
|
|
47
|
+
parent?: HTMLElement,
|
|
42
48
|
id?: string
|
|
43
49
|
) {
|
|
44
|
-
super(
|
|
45
|
-
|
|
50
|
+
super(
|
|
51
|
+
parent || document.body,
|
|
52
|
+
err_msg_finisher("new creation", parent)
|
|
53
|
+
);
|
|
46
54
|
this.self = null;
|
|
47
55
|
this.tag_name = tag_name;
|
|
48
56
|
this.parent = parent ?? document.body;
|
|
@@ -73,17 +81,24 @@ export class Accessible_Section extends Detacher {
|
|
|
73
81
|
* @param {HTMLElement} [parent] - Default: body
|
|
74
82
|
* @param {string} [heading_text]
|
|
75
83
|
*/
|
|
76
|
-
constructor
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
constructor(
|
|
85
|
+
heading_choice: Heading_Choice,
|
|
86
|
+
parent?: HTMLElement,
|
|
87
|
+
heading_text?: string
|
|
88
|
+
) {
|
|
89
|
+
super(
|
|
90
|
+
parent || document.body,
|
|
91
|
+
err_msg_finisher("new section", parent)
|
|
92
|
+
);
|
|
80
93
|
|
|
81
94
|
this.parent = parent ?? document.body;
|
|
82
95
|
|
|
83
96
|
this.heading_choice = heading_choice;
|
|
84
97
|
|
|
85
98
|
this.self = document.createElement("section");
|
|
86
|
-
this.heading = document.createElement(
|
|
99
|
+
this.heading = document.createElement(
|
|
100
|
+
this.heading_choice
|
|
101
|
+
);
|
|
87
102
|
|
|
88
103
|
this.#heading_text = heading_text ?? "";
|
|
89
104
|
|
|
@@ -92,28 +107,36 @@ export class Accessible_Section extends Detacher {
|
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
/** Updates section to keep it accessible
|
|
95
|
-
*
|
|
110
|
+
*
|
|
96
111
|
* @returns {void}
|
|
97
112
|
*/
|
|
98
113
|
#upd(value: string): void {
|
|
99
114
|
this.#heading_text = value;
|
|
100
115
|
this.heading.textContent = this.#heading_text;
|
|
101
116
|
|
|
102
|
-
const heading_text_copy: string =
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
const heading_text_copy: string =
|
|
118
|
+
this.heading.textContent
|
|
119
|
+
.trim()
|
|
120
|
+
.toLowerCase()
|
|
121
|
+
.replace(/\s+/g, "") + "-heading";
|
|
105
122
|
|
|
106
123
|
this.heading.id = heading_text_copy;
|
|
107
|
-
this.self.setAttribute(
|
|
124
|
+
this.self.setAttribute(
|
|
125
|
+
"aria-labelledby",
|
|
126
|
+
this.heading.id
|
|
127
|
+
);
|
|
108
128
|
// console.info("Updated heading text");
|
|
109
129
|
}
|
|
110
130
|
|
|
111
131
|
/** Parents both the section and heading
|
|
112
|
-
*
|
|
132
|
+
*
|
|
113
133
|
* @returns {void}
|
|
114
134
|
*/
|
|
115
135
|
attach(): void {
|
|
116
|
-
check_inv_html_elem(
|
|
136
|
+
check_inv_html_elem(
|
|
137
|
+
this.parent,
|
|
138
|
+
`Can't parent section - invalid parent! Parent: ${parent}`
|
|
139
|
+
);
|
|
117
140
|
this.parent.append(this.self);
|
|
118
141
|
this.self.appendChild(this.heading);
|
|
119
142
|
// console.info("Parented new section and heading");
|
|
@@ -146,11 +169,17 @@ export class Tab_Link extends Detacher {
|
|
|
146
169
|
* @param {boolean} [secure] - Default: true
|
|
147
170
|
* @param {boolean} [accessible] - Default: true
|
|
148
171
|
*/
|
|
149
|
-
constructor
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
constructor(
|
|
173
|
+
parent?: HTMLElement,
|
|
174
|
+
secure?: boolean,
|
|
175
|
+
accessible?: boolean,
|
|
176
|
+
link_text?: string
|
|
177
|
+
) {
|
|
178
|
+
super(
|
|
179
|
+
parent || document.body,
|
|
180
|
+
err_msg_finisher("new link", parent)
|
|
181
|
+
);
|
|
182
|
+
|
|
154
183
|
this.self = document.createElement("a");
|
|
155
184
|
this.parent = parent ?? document.body;
|
|
156
185
|
this.secure = secure ?? true;
|
|
@@ -180,11 +209,14 @@ export class Tab_Link extends Detacher {
|
|
|
180
209
|
}
|
|
181
210
|
|
|
182
211
|
/** Parents the new tab link
|
|
183
|
-
*
|
|
212
|
+
*
|
|
184
213
|
* @returns {void}
|
|
185
214
|
*/
|
|
186
215
|
attach(): void {
|
|
187
|
-
check_inv_html_elem(
|
|
216
|
+
check_inv_html_elem(
|
|
217
|
+
this.parent,
|
|
218
|
+
`Can't parent new link - invalid parent! Parent: ${this.parent}`
|
|
219
|
+
);
|
|
188
220
|
this.parent.append(this.self);
|
|
189
221
|
// console.info("Parented new tab link");
|
|
190
222
|
}
|
|
@@ -201,4 +233,4 @@ export class Tab_Link extends Detacher {
|
|
|
201
233
|
set link_text(value: string) {
|
|
202
234
|
this.#upd(value);
|
|
203
235
|
}
|
|
204
|
-
}
|
|
236
|
+
}
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* @throws - If provided HTML element is invalid
|
|
6
6
|
* @returns {void}
|
|
7
7
|
*/
|
|
8
|
-
export const check_inv_html_elem = (
|
|
8
|
+
export const check_inv_html_elem = (
|
|
9
|
+
html_elem: HTMLElement | undefined | null,
|
|
10
|
+
msg: string
|
|
11
|
+
): void => {
|
|
9
12
|
if (!html_elem) throw new Error(msg);
|
|
10
13
|
};
|
|
11
14
|
|
|
@@ -15,6 +18,9 @@ export const check_inv_html_elem = (html_elem: HTMLElement | undefined | null, m
|
|
|
15
18
|
* @param [parent]
|
|
16
19
|
* @returns {string}
|
|
17
20
|
*/
|
|
18
|
-
export const err_msg_finisher = (
|
|
21
|
+
export const err_msg_finisher = (
|
|
22
|
+
what: string,
|
|
23
|
+
parent?: HTMLElement
|
|
24
|
+
): string => {
|
|
19
25
|
return `Can't parent ${what} - invalid parent! Parent: ${parent || document.body}`;
|
|
20
|
-
};
|
|
26
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Heading_Choice } from
|
|
1
|
+
import { Heading_Choice } from "./doc-access-classes";
|
|
2
2
|
|
|
3
3
|
const returning_msg_: string = "Returning...";
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
/** Makes existing grouped sections containing the describer heading WCAG friendly (omitting contrast)
|
|
7
6
|
*
|
|
8
7
|
* WARNING: Replaces both the section and heading ID
|
|
@@ -16,38 +15,47 @@ const returning_msg_: string = "Returning...";
|
|
|
16
15
|
* @throws - If no heading is found (based on section parent and heading choice)
|
|
17
16
|
* @returns {void}
|
|
18
17
|
*/
|
|
19
|
-
export const grouped_sections_accessible = (
|
|
20
|
-
|
|
18
|
+
export const grouped_sections_accessible = (
|
|
19
|
+
class_name: string,
|
|
20
|
+
heading_choice: Heading_Choice,
|
|
21
|
+
search_parent?: HTMLElement
|
|
22
|
+
): void => {
|
|
21
23
|
if (!search_parent) search_parent = document.body;
|
|
22
24
|
|
|
23
|
-
if (!
|
|
25
|
+
if (!class_name.trim().startsWith(".")) {
|
|
24
26
|
console.warn("Class name must start with a dot!");
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
const sections: NodeListOf<HTMLElement> =
|
|
28
|
-
|
|
29
|
+
const sections: NodeListOf<HTMLElement> =
|
|
30
|
+
search_parent.querySelectorAll(`${class_name}`);
|
|
29
31
|
|
|
30
32
|
if (!sections.length) {
|
|
31
|
-
throw new Error(
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Can't find sections! ${returning_msg_}`
|
|
35
|
+
);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
sections.forEach(section => {
|
|
35
|
-
const heading: HTMLHeadingElement | null =
|
|
36
|
-
|
|
38
|
+
sections.forEach((section) => {
|
|
39
|
+
const heading: HTMLHeadingElement | null =
|
|
40
|
+
section.querySelector(heading_choice);
|
|
37
41
|
|
|
38
42
|
if (!heading) {
|
|
39
43
|
throw new Error(
|
|
40
|
-
`Can't find ${heading_choice}! ${returning_msg_}`
|
|
44
|
+
`Can't find ${heading_choice}! ${returning_msg_}`
|
|
45
|
+
);
|
|
41
46
|
}
|
|
42
47
|
if (!heading.textContent) {
|
|
43
48
|
console.warn(
|
|
44
|
-
`${heading_choice} text content - empty! ${returning_msg_}`
|
|
45
|
-
|
|
49
|
+
`${heading_choice} text content - empty! ${returning_msg_}`
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
const heading_text_copy: string =
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
const heading_text_copy: string =
|
|
55
|
+
heading.textContent
|
|
56
|
+
.trim()
|
|
57
|
+
.toLowerCase()
|
|
58
|
+
.replace(/\s+/g, "") + "-heading";
|
|
51
59
|
|
|
52
60
|
heading.id = heading_text_copy;
|
|
53
61
|
section.setAttribute("aria-labelledby", heading.id);
|
|
@@ -59,19 +67,28 @@ export const grouped_sections_accessible = (class_name: string, heading_choice:
|
|
|
59
67
|
* @param {HTMLElement} [parent] - Default: body. Recommended: main
|
|
60
68
|
* @returns {void}
|
|
61
69
|
*/
|
|
62
|
-
export const all_headings_nav_friendly = (
|
|
70
|
+
export const all_headings_nav_friendly = (
|
|
71
|
+
parent?: HTMLElement
|
|
72
|
+
): void => {
|
|
63
73
|
if (!parent) parent = document.body;
|
|
64
74
|
|
|
65
|
-
const all_headings: NodeListOf<HTMLHeadingElement> =
|
|
66
|
-
|
|
75
|
+
const all_headings: NodeListOf<HTMLHeadingElement> =
|
|
76
|
+
parent.querySelectorAll<HTMLHeadingElement>(
|
|
77
|
+
"h2, h3, h4, h5, h6"
|
|
78
|
+
);
|
|
67
79
|
|
|
68
|
-
all_headings.forEach(heading => {
|
|
69
|
-
if (!
|
|
70
|
-
console.warn(
|
|
80
|
+
all_headings.forEach((heading) => {
|
|
81
|
+
if (!heading.textContent) {
|
|
82
|
+
console.warn(
|
|
83
|
+
`A heading's text content is empty! Heading number: ${heading.tagName}`
|
|
84
|
+
);
|
|
71
85
|
}
|
|
72
86
|
|
|
73
|
-
heading.id =
|
|
74
|
-
|
|
87
|
+
heading.id =
|
|
88
|
+
heading.textContent
|
|
89
|
+
.trim()
|
|
90
|
+
.toLowerCase()
|
|
91
|
+
.replace(/\s+/g, "") + "-heading";
|
|
75
92
|
});
|
|
76
93
|
};
|
|
77
94
|
|
|
@@ -81,18 +98,22 @@ export const all_headings_nav_friendly = (parent?: HTMLElement): void => {
|
|
|
81
98
|
* @param {boolean} [secure] - Default: true
|
|
82
99
|
* @param {boolean} [accessible] - Default: true
|
|
83
100
|
*/
|
|
84
|
-
export const new_tab_existing = (
|
|
85
|
-
|
|
101
|
+
export const new_tab_existing = (
|
|
102
|
+
existing_link: HTMLAnchorElement,
|
|
103
|
+
secure?: boolean,
|
|
104
|
+
accessible?: boolean
|
|
105
|
+
): void => {
|
|
86
106
|
const skipping_msg_: string = "Skipping...";
|
|
87
|
-
|
|
107
|
+
|
|
88
108
|
existing_link.target = "_blank";
|
|
89
109
|
|
|
90
|
-
if (typeof
|
|
91
|
-
if (typeof
|
|
110
|
+
if (typeof secure !== "boolean") secure = true;
|
|
111
|
+
if (typeof accessible != "boolean") accessible = true;
|
|
92
112
|
|
|
93
113
|
if (existing_link.rel === "noopener noreferrer") {
|
|
94
114
|
console.warn(
|
|
95
|
-
`${existing_link.id || "Existing link"} - already secure! ${skipping_msg_}`
|
|
115
|
+
`${existing_link.id || "Existing link"} - already secure! ${skipping_msg_}`
|
|
116
|
+
);
|
|
96
117
|
} else {
|
|
97
118
|
if (secure) {
|
|
98
119
|
// console.info("Wants a new secure link");
|
|
@@ -101,7 +122,8 @@ export const new_tab_existing = (existing_link: HTMLAnchorElement,
|
|
|
101
122
|
}
|
|
102
123
|
if (existing_link.title === "opens in a new tab") {
|
|
103
124
|
console.warn(
|
|
104
|
-
`${existing_link.id || "Existing link"} - already secure! ${skipping_msg_}`
|
|
125
|
+
`${existing_link.id || "Existing link"} - already secure! ${skipping_msg_}`
|
|
126
|
+
);
|
|
105
127
|
} else {
|
|
106
128
|
if (accessible) {
|
|
107
129
|
// console.info("Wants a new accessible link");
|
|
@@ -116,13 +138,27 @@ export const new_tab_existing = (existing_link: HTMLAnchorElement,
|
|
|
116
138
|
* @param {AbortSignal} [abort]
|
|
117
139
|
* @returns {Promise<void>}
|
|
118
140
|
*/
|
|
119
|
-
export const wait = (
|
|
141
|
+
export const wait = (
|
|
142
|
+
time_in_ms: number,
|
|
143
|
+
abort?: AbortSignal
|
|
144
|
+
): Promise<void> => {
|
|
120
145
|
return new Promise((resolve, reject) => {
|
|
121
|
-
const timeout: number = setTimeout(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
const timeout: number = setTimeout(
|
|
147
|
+
resolve,
|
|
148
|
+
time_in_ms
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
abort?.addEventListener(
|
|
152
|
+
"abort",
|
|
153
|
+
() => {
|
|
154
|
+
clearTimeout(timeout);
|
|
155
|
+
reject(
|
|
156
|
+
new Error(
|
|
157
|
+
`Delay removed! ${time_in_ms}`
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
{ once: true }
|
|
162
|
+
);
|
|
127
163
|
});
|
|
128
|
-
}
|
|
164
|
+
};
|