1、通过按下鼠标右键拖动,分别实现的【← 后退上页】、【→ 前进下页】、【↑ 上移一屏】、【↓ 下移一屏】、【↗ 移到底部】、【↘ 移到顶部】、【↖ 关闭页面】、【↙ 刷新页面】当前标签页的八大功能;
目前為
// ==UserScript==
// @name 八边形快捷方式
// @namespace http://tampermonkey.net/
// @version 0.2.15
// @description 1、通过按下鼠标右键拖动,分别实现的【← 后退上页】、【→ 前进下页】、【↑ 上移一屏】、【↓ 下移一屏】、【↗ 移到底部】、【↘ 移到顶部】、【↖ 关闭页面】、【↙ 刷新页面】当前标签页的八大功能;
// @author Enjoy
// @icon https://foruda.gitee.com/avatar/1671100286067517749/4867929_enjoy_li_1671100285.png!avatar60
// @match *://*/*
// @match file:///*
// @exclude *localhost*
// @grant GM_addElement
// @grant GM_setClipboard
// @license GPL License
// ==/UserScript==
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 664:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ createElement: () => (/* binding */ createElement),
/* harmony export */ isOperated: () => (/* binding */ isOperated),
/* harmony export */ prependMetaUF8: () => (/* binding */ prependMetaUF8)
/* harmony export */ });
/** @描述 函数文档 https://www.tampermonkey.net/documentation.php#api:GM_addElement */
function createElement(tag) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var win = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
if (!win.GM_createElement) {
win.GM_createElement = GM_createElement;
}
return GM_createElement(tag, options);
function GM_createElement(tag, options) {
var _options$el = options.el,
el = _options$el === void 0 ? 'html' : _options$el,
_options$auto = options.auto,
auto = _options$auto === void 0 ? true : _options$auto,
_options$id = options.id,
id = _options$id === void 0 ? '_' + Math.floor(Math.random() * 1000) : _options$id,
_options$insertType = options.insertType,
insertType = _options$insertType === void 0 ? tag === 'style' ? 'appendChild' : 'prepend' : _options$insertType;
options.id = id;
var dom = document.querySelector("#".concat(id));
if (!dom) {
dom = document.createElement(tag);
}
for (var key in options) {
if (Object.hasOwnProperty.call(options, key) && key !== 'el') {
dom[key] = options[key];
}
}
if (auto) {
if (typeof el === 'string') {
el = document.querySelector(el);
}
//insertType prepend | appendChild
el[insertType](dom);
}
return dom;
}
}
/** @描述 进入可以操作的页面 */
function isOperated() {
var urls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var currentUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.href;
if (typeof urls === 'string') {
urls = [urls];
}
return !!urls.find(function (regUrl) {
return new RegExp(regUrl).test(currentUrl);
});
}
function prependMetaUF8() {
var metaUtf8 = document.querySelector('meta[charset="UTF-8"]');
if (!metaUtf8) {
metaUtf8 = createElement('meta', {
'charset': 'utf-8'
});
}
return metaUtf8;
}
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/* provided dependency */ var $GM = __webpack_require__(664);
run();
function run() {
// 禁用右击菜单 document.oncontextmenu=function(){return false }
var isDisableContextmenu = false;
document.addEventListener("contextmenu", function (e) {
if (isDisableContextmenu) {
e.preventDefault();
}
});
var timestamp = 0;
var ops = null;
var winSize = null;
var offsetValue = 100;
// 右击操作
window.addEventListener('mousedown', function onMousedown(e) {
if (e.button !== 2) return;
timestamp = Date.now();
// 浏览器视图容器高度
winSize = {
width: window.innerHeight,
height: window.innerHeight
};
ops = {
x: e.clientX,
y: e.clientY,
screenY: e.screenY
};
// createHr(e,true)
});
var y_x = 0.364; //对应20度
var x_y = 1 / 0.364; //对应70度
// 右击操作
window.addEventListener('mouseup', function onMousedown(e) {
if (e.button !== 2) return;
// if (Date.now() - timestamp > 1 * 1000) return;
var offsetX = e.clientX - ops.x;
var offsetY = e.clientY - ops.y;
// x:y=1:10 或 x:y=10:1 ,以浏览器左上角为原点,右下面积为正向区域,八边形
/*
window.history.back()
window.history.forward()
location.reload()
window.close()
window.scrollBy({ top: -window.innerHeight + 50,behavior: 'smooth' })
window.scrollBy({ top: window.innerHeight - 50,behavior: 'smooth' })
window.scrollBy({ top: -1000000,behavior: 'smooth' })
window.scrollBy({ top: 1000000,behavior: 'smooth' })
*/
// ↑↓←→↖↗↙↘
if (Math.abs(offsetX) >= 10 || Math.abs(offsetY) >= 10) {
isDisableContextmenu = true;
var direction = '';
var feature = '';
if (offsetX < 0) {
//X轴左方
if (Math.abs(offsetY / offsetX) < y_x) {
direction = '向左';
feature = '← 后退上页';
setTimeout(function () {
return window.history.back();
}, 1 * 1000);
} else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY < 0) {
direction = '向左上';
feature = '↖ 关闭页面';
setTimeout(function () {
return window.close();
}, 1 * 1000);
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY < 0) {
direction = '向上';
feature = '↑ 上移一屏';
createHr(e, true);
window.scrollBy({
top: window.innerHeight - offsetValue,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY > 0) {
direction = '向左下';
feature = '↙ 刷新页面';
setTimeout(function () {
return location.reload();
}, 1 * 1000);
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY > 0) {
direction = '向下';
feature = '↓ 下移一屏';
createHr(e);
window.scrollBy({
top: -window.innerHeight + offsetValue,
behavior: 'smooth'
});
}
} else if (offsetX >= 0) {
//X轴右方
if (Math.abs(offsetY / offsetX) < y_x) {
direction = '向右';
feature = '→ 前进下页';
setTimeout(function () {
return window.history.forward();
}, 1 * 1000);
} else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY > 0) {
direction = '向右下';
feature = '↘ 移到顶部';
window.scrollTo({
top: 0,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY > 0) {
direction = '向下';
feature = '↓ 下移一屏';
createHr(e);
window.scrollBy({
top: -window.innerHeight + offsetValue,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY < 0) {
direction = '向右上';
feature = '↗ 移到底部';
window.scrollBy({
top: 1000 * window.innerHeight,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY < 0) {
direction = '向上';
feature = '↑ 上移一屏';
createHr(e, true);
window.scrollBy({
top: window.innerHeight - offsetValue,
behavior: 'smooth'
});
}
}
createElementTip(feature, e);
} else {
isDisableContextmenu = false;
}
});
function createElementTip(tip, e) {
var tipDom = $GM.createElement('span', {
textContent: tip,
style: "position: fixed;left: ".concat(e.clientX - 46, "px;top: ").concat(e.clientY - 25, "px;background: rgba(255, 255, 0, 1);opacity: 0.5;border-radius: 6px;padding: 0 4px;z-index:").concat((Math.floor(Date.now() / 1000) + '').slice(-2))
});
setTimeout(function () {
tipDom.remove();
}, 1 * 1000);
}
function createHr(e) {
var isUp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var target = e.target;
var calcVal = "calc(".concat(window.innerHeight, "px - ").concat(e.clientY, "px)");
if (!isUp) {
calcVal = "calc(-".concat(e.clientY, "px + 40px)");
}
console.log("calcVal => %O ", calcVal);
var tipDom = $GM.createElement('span', {
el: target.tagName === "IMG" ? target.parentElement : target,
style: "position: relative;top:".concat(calcVal, ";height:0;outline: 2px solid rgba(255, 255, 0, 1);opacity: 0.5;width: 100vw;display: block;z-index:").concat((Math.floor(Date.now() / 1000) + '').slice(-2))
});
setTimeout(function () {
tipDom.remove();
}, 1 * 1000);
}
}
})();
/******/ })()
;