Right Click Shortcut Key
目前為
// ==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()
}
}
}
})