八边形快捷方式

1、通过按下鼠标右键拖动,分别实现的【← 后退上页】、【→ 前进下页】、【↑ 上移一屏】、【↓ 下移一屏】、【↗ 移到底部】、【↘ 移到顶部】、【↖ 关闭页面】、【↙ 刷新页面】当前标签页的八大功能;

当前为 2023-08-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         八边形快捷方式
// @namespace    http://tampermonkey.net/
// @version      0.4.2
// @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__ = ({

/***/ 930:
/***/ ((__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 */
// $GM.createElement
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 idPrefix = "enjoy_".concat("OctagonalShortcuts", "_").concat(tag);
    var _options$el = options.el,
      el = _options$el === void 0 ? "html" : _options$el,
      _options$autoInsert = options.autoInsert,
      autoInsert = _options$autoInsert === void 0 ? true : _options$autoInsert,
      _options$modeType = options.modeType,
      modeType = _options$modeType === void 0 ? 'single' : _options$modeType,
      _options$id = options.id,
      id = _options$id === void 0 ? '' : _options$id,
      _options$addPrefix = options.addPrefix,
      addPrefix = _options$addPrefix === void 0 ? true : _options$addPrefix,
      _options$insertType = options.insertType,
      insertType = _options$insertType === void 0 ? tag === "style" ? "appendChild" : "prepend" : _options$insertType;
    if (addPrefix) {
      id = "".concat(idPrefix, "_").concat(id);
    }
    if (modeType !== 'single') {
      id = "".concat(id, "_").concat(Math.floor(Math.random() * 1000));
    }
    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 (autoInsert) {
      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() {
  return document.querySelector('meta[charset="UTF-8"]') || createElement("meta", {
    charset: "utf-8"
  });
  ;
}

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// 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__(930);

run();
function run() {
  // 禁用右击菜单 document.oncontextmenu=function(){return false }
  var isDisableContextmenu = false;
  document.addEventListener("contextmenu", function (e) {
    if (isDisableContextmenu) {
      e.preventDefault();
    }
  });
  var setTimeoutStep = 0.6 * 1000;
  var setTimeoutStamp = 0;
  var timestamp = 0;
  var ops = null;
  var winSize = null;
  var offsetValue = 150;
  // 右击操作
  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
    };
  });
  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 > setTimeoutStep) 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.scrollTo({ top: 0,behavior: 'smooth' })
        window.scrollTo({ top: document.documentElement.scrollHeight,behavior: 'smooth' })
        */
    // ↑↓←→↖↗↙↘

    if (Math.abs(offsetX) >= 10 || Math.abs(offsetY) >= 10) {
      isDisableContextmenu = true;
      createHrByclass();
      var feature = "";
      if (offsetX < 0) {
        //X轴左方
        if (Math.abs(offsetY / offsetX) < y_x) {
          direction = "向左";
          feature = "← 后退上页";
          setTimeout(function () {
            return window.history.back();
          }, setTimeoutStep);
        } else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY < 0) {
          direction = "向左上";
          feature = "↖ 关闭页面";
          setTimeout(function () {
            return window.close();
          }, setTimeoutStep);
        } else if (Math.abs(offsetY / offsetX) > x_y && offsetY < 0) {
          direction = "向上";
          feature = "↑ 上移一屏";
          window.scrollBy({
            top: window.innerHeight - offsetValue,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? createHrByclass(true) : feature = "已到底部";
          });
        } else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY > 0) {
          direction = "向左下";
          feature = "↙ 刷新页面";
          setTimeout(function () {
            return location.reload();
          }, setTimeoutStep);
        } else if (Math.abs(offsetY / offsetX) > x_y && offsetY > 0) {
          direction = "向下";
          feature = "↓ 下移一屏";
          window.scrollBy({
            top: -window.innerHeight + offsetValue,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? createHrByclass(true) : feature = "已到顶部";
          });
        }
      } else if (offsetX >= 0) {
        //X轴右方
        if (Math.abs(offsetY / offsetX) < y_x) {
          direction = "向右";
          feature = "→ 前进下页";
          setTimeout(function () {
            return window.history.forward();
          }, setTimeoutStep);
        } else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY > 0) {
          direction = "向右下";
          feature = "↘ 移到顶部";
          window.scrollTo({
            top: 0,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? undefined : feature = "已到顶部";
          });
        } else if (Math.abs(offsetY / offsetX) > x_y && offsetY > 0) {
          direction = "向下";
          feature = "↓ 下移一屏";
          window.scrollBy({
            top: -window.innerHeight + offsetValue,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? createHrByclass(true) : feature = "已到顶部";
          });
        } else if (Math.abs(offsetY / offsetX) > y_x && Math.abs(offsetY / offsetX) < x_y && offsetY < 0) {
          direction = "向右上";
          feature = "↗ 移到底部";
          window.scrollTo({
            top: document.documentElement.scrollHeight,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? undefined : feature = "已到底部";
          });
        } else if (Math.abs(offsetY / offsetX) > x_y && offsetY < 0) {
          direction = "向上";
          feature = "↑ 上移一屏";
          window.scrollBy({
            top: window.innerHeight - offsetValue,
            behavior: "smooth"
          }, function (isEnableScroll) {
            return isEnableScroll ? createHrByclass(true) : feature = "已到底部";
          });
        }
      }
      createElementTip(feature, e);
    } else {
      isDisableContextmenu = false;
    }
  });
  function createElementTip(tip, e) {
    if (!tip) return;
    console.log("tip => %O ", tip);
    clearTimeout(setTimeoutStamp);
    var tipDom = $GM.createElement("span", {
      id: "createElementTip",
      innerText: tip,
      style: "font-size:16px;font-weight:800;color:#ff0000;position: fixed;left: ".concat(e.clientX - 46, "px;top: ").concat(e.clientY - 25, "px;background: #ffff00;opacity: 0.5;border-radius: 4px;padding: 2px 4px;z-index:").concat((Math.floor(Date.now() / 1000) + "").slice(-2))
    });
    setTimeoutStamp = setTimeout(function () {
      tipDom.remove();
    }, setTimeoutStep);
  }
  $GM.createElement("style", {
    id: "OctagonalShortcuts",
    innerHTML: "\n    body.OctagonalShortcuts-horizontal::after {\n      content: '\uD83D\uDC49';\n      display: flex;\n      width:100vw;\n      height:4px;\n      background:#ff0000;\n      position: fixed;\n      z-index: 999;\n      top: ".concat(offsetValue, "px;\n      left:10px;\n      opacity:0.2;\n    }\n    ")
  });
  var setTimeoutStamp2 = 0;
  function createHrByclass(isAdd) {
    var className2 = "OctagonalShortcuts-horizontal";
    clearTimeout(setTimeoutStamp2);
    if (isAdd) {
      document.body.classList.add(className2);
      setTimeoutStamp2 = setTimeout(function () {
        document.body.classList.remove(className2);
      }, 1 * 1000);
    } else {
      document.body.classList.remove(className2);
    }
  }
  function overrideScrollFnOfWindow() {
    var fnName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "scrollBy";
    var nativeFn = window[fnName] || function () {
      return null;
    };
    window[fnName] = function overrideNativeFn(options, callback) {
      var isEnableScroll = isScrolled(options);
      console.log("可以滚动", isEnableScroll);
      callback === null || callback === void 0 ? void 0 : callback(isEnableScroll);
      if (isEnableScroll) {
        return nativeFn(options);
      }
    };
  }
  overrideScrollFnOfWindow("scrollBy");
  overrideScrollFnOfWindow("scrollTo");
  function isScrolled(options) {
    if (!options) return false;
    var top = options.top;
    var scrollTop = document.documentElement.scrollTop;
    if (top > 0 && scrollTop === document.documentElement.scrollHeight - window.innerHeight) {
      return false;
    } else if (top <= 0 && scrollTop === 0) {
      return false;
    }
    return true;
  }
}
})();

/******/ })()
;