YouTube Better Window Title

Add video length in minutes (rounded) and Channel Name to Window Title

< 脚本YouTube Better Window Title的反馈

评价:好评 - 脚本运行良好

§
发表于:2024-03-29

I managed to improve the window.addEventListener call by adapting this suggestion

So this:

setTimeout(function () {
    waitForLoad();
}, 6000);
// window eventListener doesn't work well for some reason
// window.addEventListener('load', waitForLoad, true);
log('YouTube Better Window Title: started script')

becomes this:

// setTimeout(function () {
//  waitForLoad();
// }, 6000);
//
// use focus instead of load for window eventListener
window.addEventListener('focus', waitForLoad, true);
log('YouTube Better Window Title: started script')
Boris Joffe作者
§
发表于:2024-04-05

I tried this out and it looks like the focus listener can get triggered multiple times causing the setTimeout in updateWindowTitle to update the title too often. If you remove that setTimeout, it doesn't get triggered often enough.

I'll likely clean up the code a bit later and replace all these setTimeouts with a ~5 second setInterval.

I also eventually want this script to run on all youtube URLs with the update title logic running only on actual video pages. This will fix the issue with the script not running when opening a video in the same tab from the home/subscription page. In that case a setInterval would work better than a focus listener. I appreciate your suggestion though.

发表回复

登录以发表回复。