想法是:通过在视频播放器上用鼠标右键拖放来查找YouTube视频(例如每2%屏幕宽度1秒)。因此,在1920x1080屏幕上,如果我按下右键,将其向左拖动一些384px(20%),然后释放它,视频应该倒回10秒。
我有一个GreaseMonkey脚本,几乎可以做到我想要的所有功能,但当我松开按钮时,上下文菜单仍会弹出。这不是默认的上下文菜单,而是YouTube的自定义上下文菜单,可能与mouseup事件绑定在某个位置。我想摆脱这个菜单,并且还想防止默认的上下文菜单打开。
有没有办法改变鼠标事件的默认操作? 我想保留所有其他操作(左键单击,键盘操作等)。 我没有找到一种方法可以删除元素上特定事件的事件处理程序。
我有一个GreaseMonkey脚本,几乎可以做到我想要的所有功能,但当我松开按钮时,上下文菜单仍会弹出。这不是默认的上下文菜单,而是YouTube的自定义上下文菜单,可能与mouseup事件绑定在某个位置。我想摆脱这个菜单,并且还想防止默认的上下文菜单打开。
有没有办法改变鼠标事件的默认操作? 我想保留所有其他操作(左键单击,键盘操作等)。 我没有找到一种方法可以删除元素上特定事件的事件处理程序。
if (window.top === window.self) {
// YT video cannot be manipulated from the scope in which GM is running
// so we add a <script> element in the document to make it work
addJsNode(installListeners)
}
function installListeners() {
const FACTOR = screen.width / 70
const mp = document.getElementById('movie_player')
let startpos
mp.onmousedown = (e) => {
// only using FF so cross-browser compatibility is not required
if (e.button == 2) { startpos = e.clientX }
}
mp.onmouseup = (e) => {
if (e.button == 2) {
//===> somehow prevent YT from displaying context menu
const diff = e.clientX - startpos
mp.seekBy(diff / FACTOR)
}
}
}
function addJsNode(func) {
var scriptNode = document.createElement('script')
scriptNode.type = 'text/javascript'
scriptNode.textContent = '('+func.toString()+')()'
var target = document.getElementsByTagName ('head')[0] ||
document.body || document.documentElement
target.appendChild(scriptNode)
}