私は質問をし、ここで答えを得ました:GreasemonkeyからこのYouTube関数を呼び出す方法は?
そのコードは機能し、ビデオ時間をキャプチャするボタンをページに追加します。
ただし、重要な部分はターゲットページスコープで実行する必要があります。GreasemonkeyのGM_
機能は使用できません。
GM_setValue()
ビデオ時間を記録するために使用したい。GM_setValue()
ボタンのclick
ハンドラーから呼び出すにはどうすればよいですか?
完全なスクリプトの関連部分は次のとおりです(右クリックして保存します):
... ...
//-- Only run in the top page, not the various iframes.
if (window.top === window.self) {
var timeBtn = document.createElement ('a');
timeBtn.id = "gmTimeBtn";
timeBtn.textContent = "Time";
//-- Button is styled using CSS, in GM_addStyle, below.
document.body.appendChild (timeBtn);
addJS_Node (null, null, activateTimeButton);
}
function activateTimeButton () {
var timeBtn = document.getElementById ("gmTimeBtn");
if (timeBtn) {
timeBtn.addEventListener ('click',
function () {
var ytplayer = document.getElementById ("movie_player");
//-- IMPORTANT: GM_functions will not work here.
console.log ("getCurrentTime(): ", ytplayer.getCurrentTime() );
alert (ytplayer.getCurrentTime() );
},
false
);
}
else {
alert ("Time button not found!");
}
}
... ...
ありがとうございました :-)