-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility.ts
44 lines (38 loc) · 1.29 KB
/
utility.ts
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
40
41
42
43
44
(function () {
const SHARER_UTILITY_PROBLEM_FORMAT = function (problem: string) {
return `Sharer utility script tag doesn't have ${problem}.`;
},
SHARER_NOT_DEFINED =
"Sharer is not defined. Get it today from https://kpverse.in/sharer/.",
SCRIPT_TAG_ID = "sharer-utility-js";
if (!(window as any).Sharer) {
console.warn(SHARER_NOT_DEFINED);
return;
}
if (!document.body) {
console.warn(SHARER_UTILITY_PROBLEM_FORMAT(`"defer" attribute`));
return;
}
let script = document.getElementById(SCRIPT_TAG_ID);
if (!script) {
console.warn(SHARER_UTILITY_PROBLEM_FORMAT(`id="${SCRIPT_TAG_ID}"`));
return;
}
let classesList = script.classList;
classesList.forEach(function (className) {
if (className === "activate-button") {
try {
(window as any).Sharer.button.activate();
} catch (error) {
console.warn(error);
}
} else if (className.indexOf("set-color-") === 0) {
let color = className.replace("set-color-", "#");
try {
(window as any).Sharer.setColor(color);
} catch (error) {
console.warn(error);
}
}
});
})();