Mini_Toast

轻提示,友好提示

目前为 2024-03-25 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/490343/1348831/Mini_Toast.js

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