【发布时间】:2013-09-27 19:07:17
【问题描述】:
我目前在 Google Chrome 的 Tampermonkey 中使用以下脚本:
// ==UserScript==
// @name Youtube opt in Ads per channel
// @namespace schippi
// @include http://www.youtube.com/watch*
// @version 1
// ==/UserScript==
var u = window.location.href;
if (u.search("user=") == -1) {
var cont = document.getElementById("watch7-user-header").innerHTML;
var user=cont.replace(/.+\/user\//i,'').replace(/\?(?:.|\s)*/m,'');
window.location.href = u+"&user="+user;
}
它似乎在带有 Greasemonkey 的 Firefox 中完美运行,但在 Google Chrome 中,它似乎只适用于第一次点击 YouTube 视频。
更具体地说,如果我点击 YouTube 视频:
youtube.com/watch?v=MijmeoH9LT4,
它会将我重定向到:
youtube.com/watch?v=MijmeoH9LT4&user=Computerphile
但是,如果我点击相关视频垂直栏中的视频,它似乎不会进行任何进一步的重定向。
【问题讨论】:
-
@BrockAdams:嗯..它似乎仍然不起作用。新脚本:pastie.org/pastes/8347656/text
-
是的,这是同样的种类问题,但由于 YouTube 不再触发
hashchange事件,因此解决方案并不完全相同。稍后我会发布答案。
标签: javascript youtube cross-browser greasemonkey tampermonkey