Javascript YouTube-don';t右键单击时显示关联菜单

Javascript YouTube-don';t右键单击时显示关联菜单,javascript,youtube,greasemonkey,youtube-javascript-api,greasemonkey-4,Javascript,Youtube,Greasemonkey,Youtube Javascript Api,Greasemonkey 4,想法:通过右键拖放视频播放器(例如,每2%屏幕宽度1秒)来搜索YouTube视频。因此,在1920x1080屏幕上,如果我按下鼠标右键,将其向左拖动384px(20%),然后松开它,视频应该会倒带10秒 我有一个GreaseMonkey脚本,它可以实现我想要的功能,但是当我松开按钮时,上下文菜单仍然会弹出。这不是默认的上下文菜单,而是YouTube的自定义上下文菜单,它可能在某种程度上绑定到mouseup事件。我想摆脱这个菜单,我还想阻止默认上下文菜单打开 有没有办法更改鼠标事件的默认操作?我希

想法:通过右键拖放视频播放器(例如,每2%屏幕宽度1秒)来搜索YouTube视频。因此,在1920x1080屏幕上,如果我按下鼠标右键,将其向左拖动384px(20%),然后松开它,视频应该会倒带10秒

我有一个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)
}
if(window.top==window.self){
//YT视频不能在GM运行的范围内进行操作
//因此,我们在文档中添加一个元素以使其正常工作
addJsNode(installListeners)
}
函数installListeners(){
常数系数=屏幕宽度/70
const mp=document.getElementById('movie\u player')
让startpos
mp.onmousedown=(e)=>{
//仅使用FF,因此不需要跨浏览器兼容性
如果(e.button==2){startpos=e.clientX}
}
mp.onmouseup=(e)=>{
如果(e.按钮==2){
//=>以某种方式阻止YT显示上下文菜单
const diff=e.clientX-startpos
mp.seekBy(差异/系数)
}
}
}
函数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(脚本节点)
}

您可以使用remove()方法删除元素。您需要元素的类名,您可以在inspect facility或view page source的帮助下找到该元素