RightClickShortcutKey

Right Click Shortcut Key

目前為 2023-08-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         RightClickShortcutKey
// @namespace    http://tampermonkey.net/
// @version      0.0.6
// @description  Right Click Shortcut Key
// @author       Enjoy
// @icon         https://foruda.gitee.com/avatar/1671100286067517749/4867929_enjoy_li_1671100285.png!avatar60
// @match        *://*/*
// @exclude    *hrwork*
// @exclude    *zhaopinyun*
// @grant        GM_addElement
// @grant        GM_addStyle
// @grant        GM_setClipboard
// @license      GPL License
// ==/UserScript==

// 新页面打开链接
GM_addStyle('a>*{pointer-events: none;}')
window.addEventListener('mousedown',(e) => {
  let dom = e.target
  if (dom.tagName === "A") {
    dom.setAttribute('target','_blank')
  }
})




let ops = {
  x: 0,
  y: 0
}

let winSize = {
  width: 1,
  height: 1,
}

// 右击操作
window.addEventListener('mousedown',function onMousedown(e) {
  if (e.button !== 2) return
  winSize = {
    width: window.innerWidth,
    height: window.innerHeight,
  }

  ops = {
    x: e.clientX,
    y: e.clientY
  }

})

// 右击操作
window.addEventListener('mouseup',function onMousedown(e) {
  if (e.button !== 2) return
  let offsetX = e.clientX - ops.x
  let offsetY = e.clientY - ops.y
  console.log(`offsetY => %O `,offsetY);
  console.log(`offsetX => %O `,offsetX);

  if (Math.abs(offsetX) >= 10 || Math.abs(offsetY) >= 10) {
    if (offsetX < 0) {
      //X轴左方

      if (Math.abs(offsetY / offsetX) < 1) {
        console.log('向左,返回上一页')
        window.history.back()
      } else if (offsetY > 0 && Math.abs(offsetY / offsetX) > 1) {
        console.log('向下,刷新当前页')
        location.reload()
      } else if (offsetY < 0 && Math.abs(offsetY / offsetX) > 1) {
        console.log('向上,关闭当前页')
        window.close()
      }
    } else if (offsetX >= 0) {

      //X轴右方
      if (Math.abs(offsetY / offsetX) < 1) {
        console.log('向右,前进上一页')
        window.history.forward()
      } else if (offsetY > 0 && Math.abs(offsetY / offsetX) > 1) {
        console.log('向下,刷新当前页')
        location.reload()
      } else if (offsetY < 0 && Math.abs(offsetY / offsetX) > 1) {
        console.log('向上,关闭当前标签页')
        window.close()
      }
    }
  }
})