Greasy Fork

来自缓存

Greasy Fork is available in English.

彩色滑动特效

连续按三次ctrl键,移动鼠标即可看到效果

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      // ==UserScript==
      // @name        彩色滑动特效
      // @namespace    http://tampermonkey.net/
      // @version      0.7
      // @description  连续按三次ctrl键,移动鼠标即可看到效果
      // @author       wuyupei
      // @match         *://*/*
      // @icon         https://www.google.com/s2/favicons?domain=greasyfork.org
      // @grant        none
      // ==/UserScript==

      (function () {
        const mydiv = document.createElement('div');
        mydiv.style.width = 100 + 'vw';
        mydiv.style.height = 100 + 'vh';
        mydiv.style.position = 'fixed';
        mydiv.style.top = 0 + 'px';
        mydiv.style.left = 0 + 'px';
        mydiv.style.right = 0 + 'px';
        mydiv.style.bottom = 0 + 'px';
        mydiv.style.pointerEvents = 'none';
        mydiv.style.zIndex = '999999999999';
        document.body.appendChild(mydiv);

        const canvas = document.createElement('canvas');
        canvas.className = 'canvas';
        canvas.setAttribute('width', window.innerWidth);
        canvas.setAttribute('height', window.innerHeight);
        canvas.style.position = 'absolute';
        canvas.style.top = 0 + 'px';
        canvas.style.left = 0 + 'px';
        canvas.style.right = 0 + 'px';
        canvas.style.bottom = 0 + 'px';
        canvas.style.zIndex = '2000';
        canvas.style.pointerEvents = 'none';
        mydiv.appendChild(canvas);

        var flag = false;
        var arr = [];
        const ctx = canvas.getContext('2d');

        // 关闭指令 双击ctrl
        const target = [17, 17];
        let index = 0;
        document.addEventListener('keydown', (e) => {
          console.log(e);
          if (e.keyCode == target[index]) {
            index++;
            if (index == target.length) {
              flag = !flag
              if (flag) {
                document.addEventListener('mousemove', begindrow);
              } else {
                document.removeEventListener('mousemove', begindrow);
              }
            }
          } else {
            index = 0;
          }
        });

        const startTimer = setInterval(() => {
          ctx.clearRect(0, 0, canvas.width, canvas.height);
          for (var i = 0; i < arr.length; i++) {
            arr[i].render();
            arr[i].update();
            arr[i].remove();
          }
        }, 20);

        function begindrow(e) {
          new dot(e.clientX, e.clientY, 2, 0, -1);
          new dot(e.clientX, e.clientY, 2, 0, 1)
          // new dot(e.clientX, e.clientY, 2, 1, 0)
          // new dot(e.clientX, e.clientY, 2, -1, 0)
        }

        function getColor() {
          var colorarr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'];
          var color = '#';
          for (var i = 0; i < 6; i++) {
            color += colorarr[Math.floor(Math.random() * colorarr.length)];
          }
          return color;
        }

        class dot {
          constructor(x, y, r, dx, dy) {
            this.x = x;
            this.y = y;
            this.r = r;
            this.dx = dx;
            this.dy = dy;
            this._x = x;
            this._y = y;
            this.color = getColor();
            arr.push(this);
          }
        }
        dot.prototype.render = function () {
          ctx.beginPath();
          ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
          ctx.fillStyle = this.color;
          ctx.fill();
        };

        dot.prototype.update = function () {
          this.x += this.dx;
          this.y += this.dy;
        };

        dot.prototype.remove = function () {
          if (
            this.x - this._x >= 25 ||
            this.x - this.x <= -25 ||
            this.y - this._y >= 25 ||
            this.y - this._y <= -25
          ) {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
          }
        };
      })(document);