Greasy Fork

Greasy Fork is available in English.

Mini_Toast

轻提示,友好提示

当前为 2024-04-05 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/490343/1354715/Mini_Toast.js

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Mini_Toast
// @version      1.0.5
// @description  轻提示,友好提示
// @author       Zosah
// ==/UserScript==

const toastHandler = {
    create: function () {
        var style = document.createElement('style');
        style.innerHTML = `
        @keyframes show {
            0% {
                opacity: 0;
            }
            100% {
                opacity: 1;
            }
        }
        
        @keyframes hide {
            0% {
                opacity: 1;
            }
            100% {
                opacity: 0;
            }
        }
        
        .toast_box {
            position: absolute;
            bottom: 50%;
            left: 50%;
            z-index: 10;
            transform: translate(-50%, -50%);
            display: none;
        }
        
        .toast_box p {
            box-sizing: border-box;
            padding: 10px 20px;
            width: max-content;
            background: #707070;
            color: #fff;
            font-size: 16px;
            text-align: center;
            border-radius: 6px;
            opacity: 0.8;
        }
        
        .toliet {
            margin: 0 auto;
        }`;

        // 将样式添加到 head 元素中
        document.head.appendChild(style);

        // 创建提示框
        var toastBox = document.createElement('div');
        toastBox.className = 'toast_box';
        toastBox.style.display = 'none';

        var toastText = document.createElement('p');
        toastText.id = 'toast';
        toastBox.appendChild(toastText);

        // 将提示框添加到 body 元素中
        document.body.appendChild(toastBox);
    },
    showToast: function (text, time) {
        var toast = document.getElementById('toast');
        var toastBox = document.getElementsByClassName('toast_box')[0];
        toast.innerHTML = text;
        toastBox.style.animation = 'show 0.5s';
        toastBox.style.display = 'inline-block';
        setTimeout(function () {
            toastBox.style.animation = 'hide 1s';
            setTimeout(function () {
                toastBox.style.display = 'none';
            }, 800);
        }, time);
    }
}