Followy back/close button

Inserts a back + close button that approaches your mouse pointer as you move it.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Followy back/close button
// @namespace    https://greasyfork.org/en/users/1148791-vuccala
// @author       Vuccala
// @icon         https://archive.org/download/backX/backX.png
// @version      1.0
// @description  Inserts a back + close button that approaches your mouse pointer as you move it.
// @match        *://*/*
// @grant        window.close
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';

    const backButton = document.createElement('button');
    backButton.innerHTML = '🔙';
    backButton.style.position = 'fixed';
    backButton.style.zIndex = '9999';
    backButton.style.border = 'none';
    backButton.style.backgroundColor = 'transparent';
    backButton.style.fontSize = '24px';
    backButton.style.cursor = 'pointer';

    const closeButton = document.createElement('button');
    closeButton.innerHTML = '✖️';
    closeButton.style.position = 'fixed';
    closeButton.style.zIndex = '9999';
    closeButton.style.border = 'none';
    closeButton.style.backgroundColor = 'transparent';
    closeButton.style.fontSize = '24px';
    closeButton.style.cursor = 'pointer';

    document.body.appendChild(backButton);
    document.body.appendChild(closeButton);

    // Hides Back button if no history or if about:newtab
    function updateEmoji() {
        if (window.history.length <= 1 || document.referrer === '') {
            backButton.innerHTML = '';
        }
    }

    backButton.addEventListener('click', () => {
        history.back();
    });

    closeButton.addEventListener('click', () => {
        window.close();
    });

    const chasingSpeed = 0.05;
    let emojiX = window.innerWidth / 2;
    let emojiY = window.innerHeight / 2;

    function updateEmojiPosition(event) {
        const emojiSize = 24;
        const targetX = event.clientX - emojiSize / 2;
        const targetY = event.clientY - emojiSize / 2;

        emojiX += (targetX - emojiX) * chasingSpeed;
        emojiY += (targetY - emojiY) * chasingSpeed;

        backButton.style.left = emojiX + -10 + 'px';
        backButton.style.top = emojiY + 'px';
        closeButton.style.left = emojiX + 20 + 'px';
        closeButton.style.top = emojiY + 'px';

    }

    window.addEventListener('popstate', updateEmoji);
    document.addEventListener('mousemove', updateEmojiPosition);

    // Initial emoji update
    updateEmoji();
})();