Mini_Toast

轻提示,友好提示

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

  1. // ==UserScript==
  2. // @name Mini_Toast
  3. // @version 1.0.6
  4. // @description 轻提示,友好提示
  5. // @author Zosah
  6. // ==/UserScript==
  7.  
  8. class ToastHandler {
  9. // 单例模式
  10. constructor() {
  11. if (ToastHandler.instance) {
  12. ToastHandler.instance = this;
  13. }
  14. this.create();
  15. return ToastHandler.instance;
  16. }
  17.  
  18. create() {
  19. let style = document.createElement('style');
  20. style.innerHTML = `
  21. @keyframes show {
  22. 0% {
  23. opacity: 0;
  24. }
  25. 100% {
  26. opacity: 1;
  27. }
  28. }
  29. @keyframes hide {
  30. 0% {
  31. opacity: 1;
  32. }
  33. 100% {
  34. opacity: 0;
  35. }
  36. }
  37. .toast_box {
  38. position: fixed;
  39. bottom: 50%;
  40. left: 50%;
  41. z-index: 9999;
  42. transform: translate(-50%, -50%);
  43. display: none;
  44. }
  45. .toast_box p {
  46. box-sizing: border-box;
  47. padding: 10px 20px;
  48. width: max-content;
  49. background: #707070;
  50. color: #fff;
  51. font-size: 16px;
  52. text-align: center;
  53. border-radius: 6px;
  54. opacity: 0.8;
  55. }
  56. .toliet {
  57. margin: 0 auto;
  58. }`;
  59.  
  60. // 将样式添加到 head 元素中
  61. document.head.appendChild(style);
  62.  
  63. // 创建提示框
  64. let toastBox = document.createElement('div');
  65. toastBox.className = 'toast_box';
  66. toastBox.style.display = 'none';
  67.  
  68. let toastText = document.createElement('p');
  69. toastText.id = 'toast';
  70. toastBox.appendChild(toastText);
  71.  
  72. // 将提示框添加到 body 元素中
  73. document.body.appendChild(toastBox);
  74. }
  75. showToast(text, time) {
  76. let toast = document.getElementById('toast');
  77. let toastBox = document.getElementsByClassName('toast_box')[0];
  78. toast.innerHTML = text;
  79. toastBox.style.animation = 'show 0.5s';
  80. toastBox.style.display = 'inline-block';
  81. setTimeout(function () {
  82. toastBox.style.animation = 'hide 1s';
  83. setTimeout(function () {
  84. toastBox.style.display = 'none';
  85. }, 800);
  86. }, time);
  87. }
  88. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址