当页面位置改变时调用 Tampermonkey 脚本

Recall Tampermonkey script when page location changes

好吧,我想知道是否可以在用户更改其位置时调用 Tampermonkey 脚本(但匹配仍然有效)。例如,我的脚本挂钩了 youtube 网站。

我需要让脚本在我更改视频时自动调用,我的实际脚本是:

// ==UserScript==
// @name        xxx
// @namespace    xxx
// @version      1.0
// @description  xxx
// @author       Ikillnukes
// @match        https://www.youtube.com/*
// @match        https://youtu.be/*
// @grant        none
// ==/UserScript==

console.log("Tampermonkey hook!");
var script = document.createElement('script');
script.src = document.location.protocol+"//xxx";
(document.body || document.head || document.documentElement).appendChild(script);

如您所见,我调用 console.log 对其进行调试,当我刷新或首次加载网页时会调用它。但是有一次我改变了视频,它不再被调用,这就是我想要避免的。

我也评论了这个:http://tampermonkey.net/documentation.php但我没有找到任何东西,也许我评论得太快了?

那么,有什么建议吗?

使用由 youtube 脚本定义的自定义 YouTube SPF events

window.addEventListener("spfrequest", function(e) { console.log("requesting new page") });
window.addEventListener("spfprocess", function(e) { console.log("new page is processed") });
window.addEventListener("spfdone", function(e) { console.log("new page is displayed") });

Chrome 用户查找此类事件的提示:
使用 DevTools → Elements 面板 → Event Listeners 面板

在较新版本的 Chrome 上:
使用 DevTools → Sources 面板 → Event Listeners(不是断点)