prevent massive stacks in chrome

This commit is contained in:
ed 2021-08-12 22:12:05 +02:00
parent ed5f6736df
commit f0125cdc36
4 changed files with 45 additions and 20 deletions

View file

@ -21,7 +21,6 @@ function main() {
} }
function collect() { function collect() {
setTimeout(collect, interval * 1000);
try { try {
var pd = document.querySelector('ytd-watch-flexy'); var pd = document.querySelector('ytd-watch-flexy');
if (!pd) if (!pd)
@ -39,7 +38,7 @@ function main() {
console.log("[yt-pdh]", ex); console.log("[yt-pdh]", ex);
} }
} }
collect(); setInterval(collect, interval * 1000);
} }
var scr = document.createElement('script'); var scr = document.createElement('script');

View file

@ -921,14 +921,16 @@ function playpause(e) {
var mpui = (function () { var mpui = (function () {
var r = {}, var r = {},
nth = 0, nth = 0,
timeout = null,
preloaded = null; preloaded = null;
r.progress_updater = function () { r.progress_updater = function () {
clearTimeout(timeout); timer.add(updater_impl, true);
};
function updater_impl() {
if (!mp.au) { if (!mp.au) {
widget.paused(true); widget.paused(true);
timer.rm(updater_impl);
return; return;
} }
@ -970,9 +972,9 @@ var mpui = (function () {
} }
} }
if (!mp.au.paused) if (mp.au.paused)
timeout = setTimeout(r.progress_updater, 100); timer.rm(updater_impl);
}; }
r.progress_updater(); r.progress_updater();
return r; return r;
})(); })();
@ -2822,7 +2824,7 @@ var treectl = (function () {
} }
function onscroll() { function onscroll() {
if (!entreed || treectl.hidden) if (!entreed || treectl.hidden || document.visibilityState == 'hidden')
return; return;
var tree = ebi('tree'), var tree = ebi('tree'),
@ -2858,12 +2860,7 @@ var treectl = (function () {
tree.style.height = treeh < 10 ? '' : treeh + 'px'; tree.style.height = treeh < 10 ? '' : treeh + 'px';
} }
} }
timer.add(onscroll, true);
function periodic() {
onscroll();
setTimeout(periodic, document.visibilityState ? 100 : 5000);
}
periodic();
function onresize(e) { function onresize(e) {
if (!entreed || treectl.hidden) if (!entreed || treectl.hidden)

View file

@ -929,21 +929,17 @@ function up2k_init(subtle) {
} }
var tasker = (function () { var tasker = (function () {
var tto = null, var running = false,
running = false,
was_busy = false; was_busy = false;
function defer() { function defer() {
running = false; running = false;
clearTimeout(tto);
tto = setTimeout(taskerd, 100);
} }
function taskerd() { function taskerd() {
if (running) if (running)
return; return;
clearTimeout(tto);
if (crashed) if (crashed)
return defer(); return defer();
@ -1034,7 +1030,7 @@ function up2k_init(subtle) {
return defer(); return defer();
} }
} }
taskerd(); timer.add(taskerd, true);
return taskerd; return taskerd;
})(); })();

View file

@ -555,6 +555,39 @@ function hist_replace(url) {
} }
var timer = (function () {
var r = {};
r.q = [];
r.last = 0;
r.add = function (fun, run) {
r.rm(fun);
r.q.push(fun);
if (run)
fun();
};
r.rm = function (fun) {
apop(r.q, fun);
};
function impl() {
if (Date.now() - r.last < 69)
return;
var q = r.q.slice(0);
for (var a = 0; a < q.length; a++)
q[a]();
r.last = Date.now();
}
setInterval(impl, 100);
return r;
})();
var tt = (function () { var tt = (function () {
var r = { var r = {
"tt": mknod("div"), "tt": mknod("div"),