Skip to content

Commit f8348fc

Browse files
Remove useless logging.
1 parent 3351bc1 commit f8348fc

File tree

1 file changed

+89
-90
lines changed

1 file changed

+89
-90
lines changed
+89-90
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,89 @@
1-
"use strict";
2-
3-
function requireCondition(condition, options = {}) {
4-
options = {
5-
delay: 50,
6-
maxCycles: 1000,
7-
...options,
8-
};
9-
10-
// Preserve stack for throwing later when needed.
11-
const error = new Error("Maximum cycles reached.");
12-
13-
return new Promise((resolve, reject) => {
14-
if (checkCondition()) return;
15-
16-
let counter = 0;
17-
const checker = setInterval(() => {
18-
if (checkCounter(counter++) || checkCondition()) return clearInterval(checker);
19-
}, options.delay);
20-
21-
function checkCondition() {
22-
const response = condition();
23-
if (!response) return false;
24-
25-
if (typeof response === "boolean") {
26-
if (response) resolve();
27-
else reject();
28-
} else if (typeof response === "object") {
29-
if (response.hasOwnProperty("success")) {
30-
if (response.success === true) resolve(response.value);
31-
else reject(response.value);
32-
} else {
33-
resolve(response);
34-
}
35-
}
36-
return true;
37-
}
38-
39-
function checkCounter(count) {
40-
if (options.maxCycles <= 0) return false;
41-
42-
if (count > options.maxCycles) {
43-
reject(error);
44-
console.trace();
45-
return true;
46-
}
47-
return false;
48-
}
49-
});
50-
}
51-
52-
function requireElement(selector, attributes) {
53-
attributes = {
54-
invert: false,
55-
parent: document,
56-
...attributes,
57-
};
58-
if (attributes.invert) {
59-
return requireCondition(() => !attributes.parent.find(selector), attributes);
60-
} else {
61-
return requireCondition(() => attributes.parent.find(selector), attributes);
62-
}
63-
}
64-
65-
function requireSidebar() {
66-
return requireElement("#sidebar");
67-
}
68-
69-
function requireContent() {
70-
return requireElement(".content-wrapper");
71-
}
72-
73-
function requireItemsLoaded() {
74-
return requireElement(".items-cont[aria-expanded=true] > li > .title-wrap");
75-
}
76-
77-
function requireChatsLoaded() {
78-
return requireElement("#chatRoot [class*='chat-list-button__']");
79-
}
80-
81-
function requireFeatureManager() {
82-
return new Promise((resolve) => {
83-
const featureManagerIntervalID = setInterval(() => {
84-
while (typeof featureManager === "undefined") {}
85-
86-
clearInterval(featureManagerIntervalID);
87-
resolve();
88-
}, 100);
89-
});
90-
}
1+
"use strict";
2+
3+
function requireCondition(condition, options = {}) {
4+
options = {
5+
delay: 50,
6+
maxCycles: 1000,
7+
...options,
8+
};
9+
10+
// Preserve stack for throwing later when needed.
11+
const error = new Error("Maximum cycles reached.");
12+
13+
return new Promise((resolve, reject) => {
14+
if (checkCondition()) return;
15+
16+
let counter = 0;
17+
const checker = setInterval(() => {
18+
if (checkCounter(counter++) || checkCondition()) return clearInterval(checker);
19+
}, options.delay);
20+
21+
function checkCondition() {
22+
const response = condition();
23+
if (!response) return false;
24+
25+
if (typeof response === "boolean") {
26+
if (response) resolve();
27+
else reject();
28+
} else if (typeof response === "object") {
29+
if (response.hasOwnProperty("success")) {
30+
if (response.success === true) resolve(response.value);
31+
else reject(response.value);
32+
} else {
33+
resolve(response);
34+
}
35+
}
36+
return true;
37+
}
38+
39+
function checkCounter(count) {
40+
if (options.maxCycles <= 0) return false;
41+
42+
if (count > options.maxCycles) {
43+
reject(error);
44+
return true;
45+
}
46+
return false;
47+
}
48+
});
49+
}
50+
51+
function requireElement(selector, attributes) {
52+
attributes = {
53+
invert: false,
54+
parent: document,
55+
...attributes,
56+
};
57+
if (attributes.invert) {
58+
return requireCondition(() => !attributes.parent.find(selector), attributes);
59+
} else {
60+
return requireCondition(() => attributes.parent.find(selector), attributes);
61+
}
62+
}
63+
64+
function requireSidebar() {
65+
return requireElement("#sidebar");
66+
}
67+
68+
function requireContent() {
69+
return requireElement(".content-wrapper");
70+
}
71+
72+
function requireItemsLoaded() {
73+
return requireElement(".items-cont[aria-expanded=true] > li > .title-wrap");
74+
}
75+
76+
function requireChatsLoaded() {
77+
return requireElement("#chatRoot [class*='chat-list-button__']");
78+
}
79+
80+
function requireFeatureManager() {
81+
return new Promise((resolve) => {
82+
const featureManagerIntervalID = setInterval(() => {
83+
while (typeof featureManager === "undefined") {}
84+
85+
clearInterval(featureManagerIntervalID);
86+
resolve();
87+
}, 100);
88+
});
89+
}

0 commit comments

Comments
 (0)