easter-egg-quest 1.0.10 → 1.0.12
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.
|
@@ -524,6 +524,10 @@ class HiddenEntry {
|
|
|
524
524
|
this.fallbackButton = null;
|
|
525
525
|
this._injectedElement = null;
|
|
526
526
|
this._destroyed = false;
|
|
527
|
+
this._hintVisibleElapsed = 0;
|
|
528
|
+
this._hintVisibleStart = 0;
|
|
529
|
+
this._hintCheckInterval = null;
|
|
530
|
+
this._hintVisibilityHandler = null;
|
|
527
531
|
this.config = config;
|
|
528
532
|
this.script = script;
|
|
529
533
|
this.onFound = onFound;
|
|
@@ -547,6 +551,7 @@ class HiddenEntry {
|
|
|
547
551
|
cleanup() {
|
|
548
552
|
var _a2, _b2, _c, _d;
|
|
549
553
|
this._destroyed = true;
|
|
554
|
+
this._stopHintTimer();
|
|
550
555
|
for (const t of this.hintTimers) clearTimeout(t);
|
|
551
556
|
this.hintTimers = [];
|
|
552
557
|
if (this.clickHandler && this.targetElement) {
|
|
@@ -728,22 +733,70 @@ class HiddenEntry {
|
|
|
728
733
|
this._injectShimmerStyles();
|
|
729
734
|
this._createHintContainer();
|
|
730
735
|
const hints = this.script.hiddenEntryHints;
|
|
731
|
-
const FIRST_HINT_DELAY =
|
|
736
|
+
const FIRST_HINT_DELAY = 12e4;
|
|
732
737
|
const HINT_INTERVAL = 6e4;
|
|
738
|
+
const SHIMMER_DELAY = 24e4;
|
|
739
|
+
const thresholds = [];
|
|
733
740
|
for (let i = 0; i < hints.length; i++) {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
this._showHint(hints[i])
|
|
738
|
-
}
|
|
739
|
-
|
|
741
|
+
thresholds.push({
|
|
742
|
+
at: FIRST_HINT_DELAY + i * HINT_INTERVAL,
|
|
743
|
+
fired: false,
|
|
744
|
+
action: () => this._showHint(hints[i])
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
thresholds.push({
|
|
748
|
+
at: SHIMMER_DELAY,
|
|
749
|
+
fired: false,
|
|
750
|
+
action: () => {
|
|
751
|
+
if (this.targetElement) {
|
|
752
|
+
this.targetElement.classList.add("eeq-entry-target");
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
const getVisibleElapsed = () => this._hintVisibleElapsed + (this._hintVisibleStart ? Date.now() - this._hintVisibleStart : 0);
|
|
757
|
+
const checkThresholds = () => {
|
|
758
|
+
if (this._destroyed) return;
|
|
759
|
+
const elapsed = getVisibleElapsed();
|
|
760
|
+
for (const t of thresholds) {
|
|
761
|
+
if (!t.fired && elapsed >= t.at) {
|
|
762
|
+
t.fired = true;
|
|
763
|
+
t.action();
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
if (thresholds.every((t) => t.fired)) this._stopHintTimer();
|
|
767
|
+
};
|
|
768
|
+
const startTimer = () => {
|
|
769
|
+
if (this._hintCheckInterval) return;
|
|
770
|
+
this._hintVisibleStart = Date.now();
|
|
771
|
+
this._hintCheckInterval = setInterval(checkThresholds, 1e3);
|
|
772
|
+
};
|
|
773
|
+
const pauseTimer = () => {
|
|
774
|
+
if (this._hintVisibleStart) {
|
|
775
|
+
this._hintVisibleElapsed += Date.now() - this._hintVisibleStart;
|
|
776
|
+
this._hintVisibleStart = 0;
|
|
777
|
+
}
|
|
778
|
+
if (this._hintCheckInterval) {
|
|
779
|
+
clearInterval(this._hintCheckInterval);
|
|
780
|
+
this._hintCheckInterval = null;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
this._hintVisibilityHandler = () => {
|
|
784
|
+
if (this._destroyed) return;
|
|
785
|
+
if (document.visibilityState === "visible") startTimer();
|
|
786
|
+
else pauseTimer();
|
|
787
|
+
};
|
|
788
|
+
document.addEventListener("visibilitychange", this._hintVisibilityHandler);
|
|
789
|
+
if (document.visibilityState === "visible") startTimer();
|
|
790
|
+
}
|
|
791
|
+
_stopHintTimer() {
|
|
792
|
+
if (this._hintCheckInterval) {
|
|
793
|
+
clearInterval(this._hintCheckInterval);
|
|
794
|
+
this._hintCheckInterval = null;
|
|
795
|
+
}
|
|
796
|
+
if (this._hintVisibilityHandler) {
|
|
797
|
+
document.removeEventListener("visibilitychange", this._hintVisibilityHandler);
|
|
798
|
+
this._hintVisibilityHandler = null;
|
|
740
799
|
}
|
|
741
|
-
const shimmerDelay = 42e4;
|
|
742
|
-
const shimmerTimer = setTimeout(() => {
|
|
743
|
-
if (this._destroyed || !this.targetElement) return;
|
|
744
|
-
this.targetElement.classList.add("eeq-entry-target");
|
|
745
|
-
}, shimmerDelay);
|
|
746
|
-
this.hintTimers.push(shimmerTimer);
|
|
747
800
|
}
|
|
748
801
|
_showHint(text) {
|
|
749
802
|
if (!this.hintContainer) return;
|