1、通过按下鼠标右键拖动,分别实现的后退(左)、前进(右)、关闭(左上)、刷新(左下)、上整屏移动(下)、下整屏移动(上)、回到顶部(右上)、回到底部(右下)当前标签页的八大功能;2、打开链接方式,总是以命名的新窗口
目前為
// ==UserScript==
// @name 八边形快捷方式
// @namespace http://tampermonkey.net/
// @version 0.2.10
// @description 1、通过按下鼠标右键拖动,分别实现的后退(左)、前进(右)、关闭(左上)、刷新(左下)、上整屏移动(下)、下整屏移动(上)、回到顶部(右上)、回到底部(右下)当前标签页的八大功能;2、打开链接方式,总是以命名的新窗口
// @author Enjoy
// @icon https://foruda.gitee.com/avatar/1671100286067517749/4867929_enjoy_li_1671100285.png!avatar60
// @match *://*/*
// @match file:///*
// @exclude *hrwork*
// @exclude *zhaopinyun*
// @exclude *localhost*
// @exclude *127.0.0.1*
// @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(Date.now() / 1000) : _options$id,
_options$insertType = options.insertType,
insertType = _options$insertType === void 0 ? '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() {
// 新页面打开链接
$GM.createElement('style', {
id: 'enjoy_' + "OctagonalShortcuts",
textContent: "a[href*='/']>*{pointer-events: none;}"
});
window.addEventListener('mousedown', function (e) {
var _dom$href, _dom$href$replace, _dom$href$replace$mat;
var dom = e.target;
// 非锚点的a
if (dom.tagName === "A" && (_dom$href = dom.href) !== null && _dom$href !== void 0 && (_dom$href$replace = _dom$href.replace) !== null && _dom$href$replace !== void 0 && (_dom$href$replace = _dom$href$replace.call(_dom$href, location.href, '')) !== null && _dom$href$replace !== void 0 && (_dom$href$replace$mat = _dom$href$replace.match) !== null && _dom$href$replace$mat !== void 0 && _dom$href$replace$mat.call(_dom$href$replace, /^http/)) {
//
dom.removeAttribute('rel');
dom.setAttribute('target', dom.innerText.replace(/\s/g, ''));
}
});
// 禁用右击菜单 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;
// 右击操作
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
};
});
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 = '↑ 下移一屏';
window.scrollBy({
top: window.innerHeight - 80,
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 = '↓ 上移一屏';
window.scrollBy({
top: -window.innerHeight + 80,
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.scrollBy({
top: -100000,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY > 0) {
direction = '向下';
feature = '↓ 上移一屏';
window.scrollBy({
top: -window.innerHeight + 80,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY < 0) {
feature = '↘ 下移到底部';
window.scrollBy({
top: 100000,
behavior: 'smooth'
});
} else if (Math.abs(offsetY / offsetX) > x_y && offsetY < 0) {
direction = '向上';
feature = '↑ 下移一屏';
window.scrollBy({
top: window.innerHeight - 80,
behavior: 'smooth'
});
}
}
console.log("".concat(direction, ":").concat(feature));
createElementTip(feature, e);
} else {
isDisableContextmenu = false;
}
});
function createElementTip(tip, e) {
var tipDom = $GM.createElement('span', {
textContent: tip,
style: "position: fixed;left: ".concat(e.clientX, "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);
}
}
})();
/******/ })()
;