easter-egg-quest 1.0.11 → 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) {
|
|
@@ -730,43 +735,67 @@ class HiddenEntry {
|
|
|
730
735
|
const hints = this.script.hiddenEntryHints;
|
|
731
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.
|
|
738
|
-
}
|
|
739
|
-
this.hintTimers.push(timer);
|
|
741
|
+
thresholds.push({
|
|
742
|
+
at: FIRST_HINT_DELAY + i * HINT_INTERVAL,
|
|
743
|
+
fired: false,
|
|
744
|
+
action: () => this._showHint(hints[i])
|
|
745
|
+
});
|
|
740
746
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
}
|
|
748
|
-
/** Show hint only when the page is visible. If hidden, wait for visibility change. */
|
|
749
|
-
_showHintWhenVisible(text) {
|
|
750
|
-
if (this._destroyed) return;
|
|
751
|
-
if (document.visibilityState === "visible" && document.hasFocus()) {
|
|
752
|
-
this._showHint(text);
|
|
753
|
-
} else {
|
|
754
|
-
const handler = () => {
|
|
755
|
-
if (this._destroyed) {
|
|
756
|
-
document.removeEventListener("visibilitychange", handler);
|
|
757
|
-
window.removeEventListener("focus", handler);
|
|
758
|
-
return;
|
|
747
|
+
thresholds.push({
|
|
748
|
+
at: SHIMMER_DELAY,
|
|
749
|
+
fired: false,
|
|
750
|
+
action: () => {
|
|
751
|
+
if (this.targetElement) {
|
|
752
|
+
this.targetElement.classList.add("eeq-entry-target");
|
|
759
753
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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();
|
|
766
764
|
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
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;
|
|
770
799
|
}
|
|
771
800
|
}
|
|
772
801
|
_showHint(text) {
|