Mini_Toast

轻提示,友好提示

当前为 2024-03-20 提交的版本,查看 最新版本

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

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

QingJ © 2025

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