mirror of
https://github.com/danbulant/dribbblish-dynamic-theme
synced 2026-06-04 23:30:21 +00:00
add ready state to info so it won't throw an error when registering items too early
This commit is contained in:
parent
a880871db0
commit
59daccdbf2
1 changed files with 13 additions and 0 deletions
|
|
@ -24,11 +24,16 @@ export default class Info {
|
||||||
/** @type {MarkdownIt} */
|
/** @type {MarkdownIt} */
|
||||||
#md;
|
#md;
|
||||||
|
|
||||||
|
/** @type {Boolean} */
|
||||||
|
#ready = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
waitForElement([".main-topBar-container", ".main-userWidget-box"], ([topBarContainer, userWidget]) => {
|
waitForElement([".main-topBar-container", ".main-userWidget-box"], ([topBarContainer, userWidget]) => {
|
||||||
this.#container = document.createElement("div");
|
this.#container = document.createElement("div");
|
||||||
this.#container.id = "dribbblish-info-container";
|
this.#container.id = "dribbblish-info-container";
|
||||||
topBarContainer.insertBefore(this.#container, userWidget);
|
topBarContainer.insertBefore(this.#container, userWidget);
|
||||||
|
|
||||||
|
this.#ready = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +42,11 @@ export default class Info {
|
||||||
* @param {DribbblishInfo} info
|
* @param {DribbblishInfo} info
|
||||||
*/
|
*/
|
||||||
set(key, info) {
|
set(key, info) {
|
||||||
|
if (!this.#ready) {
|
||||||
|
setTimeout(() => this.set(key, info), 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.remove(key);
|
this.remove(key);
|
||||||
if (info.text == null && info.icon == null) throw new Error("invalid info");
|
if (info.text == null && info.icon == null) throw new Error("invalid info");
|
||||||
|
|
||||||
|
|
@ -58,6 +68,9 @@ export default class Info {
|
||||||
this.#container.appendChild(elem);
|
this.#container.appendChild(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} key
|
||||||
|
*/
|
||||||
remove(key) {
|
remove(key) {
|
||||||
$(this.#container).find(`.dribbblish-info-item[key="${key}"]`).remove();
|
$(this.#container).find(`.dribbblish-info-item[key="${key}"]`).remove();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue