MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / run

Function run

scripts/web_timer.js:131–508  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129};
130
131function run() {
132 if (typeof window.ufs_web_timer_cleanup === "function") {
133 window.ufs_web_timer_cleanup();
134 }
135
136 const isMainFrame = window === window.top;
137 const cleanupFn = [];
138
139 function addEventListener(target, event, func, options) {
140 target.addEventListener(event, func, options);
141 cleanupFn.push(() => target.removeEventListener(event, func));
142 }
143 window.ufs_web_timer_cleanup = () => {
144 if (typeof saveTimer === "function") saveTimer();
145 cleanupFn.forEach((fn) => fn());
146 };
147
148 // track user events: mouse, keyboard, touch, ...
149 let needUpdateLastActive = true;
150 let updateLastActive = throttle(function (e, mainframe) {
151 needUpdateLastActive = true;
152 }, 1000 / 24);
153
154 const allEvents = [
155 // https://javascript.info/pointer-events
156 "pointerover",
157 "pointerenter",
158 "pointerdown",
159 "pointermove",
160 "pointerup",
161 "pointerleave",
162
163 "click",
164 "contextmenu",
165 "touchstart",
166 "touchmove",
167 "touchend",
168
169 "keydown",
170 "keyup",
171 "keypress",
172
173 "wheel",
174 "scroll",
175
176 "blur",
177 // "focusin",
178 // "focusout",
179 "focus",
180 ];
181
182 const updateLastActiveMsg = "ufs_web_timer_updateLastActive";
183 const overlayId = "ufs-web-timer-overlay";
184 allEvents.forEach((event) => {
185 // main frame => update last active directly
186 if (isMainFrame) {
187 addEventListener(window, event, (e) => {
188 if (e.target?.id == overlayId) return;

Callers

nothing calls this directly

Calls 8

saveTimerFunction · 0.85
throttleFunction · 0.85
getTodayTimerFunction · 0.85
getIdleStateFunction · 0.85
setShowOverlayFunction · 0.85
makeTitleFunction · 0.85
addEventListenerFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected