八边形快捷方式

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         八边形快捷方式
// @namespace    http://tampermonkey.net/
// @version      0.2.18
// @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: "font-size:16px;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;
    //  console.log(`e.target => %O `,e,e.target,e.target.innerHTML ,e.offsetY);

    target = target.tagName === "IMG" ? target.parentElement : target;

    //  e.offsetY 修复放入容器后的偏差
    var calcVal = "calc(".concat(window.innerHeight, "px - ").concat(e.clientY, "px + ").concat(e.offsetY, "px)");
    if (!isUp) {
      calcVal = "calc(-".concat(e.clientY, "px + ").concat(e.offsetY, "px)");
    }
    console.log("calcVal => %O ", calcVal);
    var tipDom = $GM.createElement('span', {
      el: target,
      style: "font-size:16px;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();
    }, 2 * 1000);
  }
}
})();

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