()
| 129 | }; |
| 130 | |
| 131 | function 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; |
nothing calls this directly
no test coverage detected