Private Simple Toast

Simple Toast

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

  1. // 토스트 메시지 유틸리티
  2. const Toast = {
  3. // 토스트 컨테이너 생성
  4. createContainer: function() {
  5. if (document.getElementById('toast-container')) return;
  6. const container = document.createElement('div');
  7. container.id = 'toast-container';
  8. container.style.position = 'fixed';
  9. container.style.bottom = '20px';
  10. container.style.right = '20px';
  11. container.style.zIndex = '9999';
  12. container.style.display = 'flex';
  13. container.style.flexDirection = 'column';
  14. container.style.gap = '10px';
  15. document.body.appendChild(container);
  16. },
  17. // 토스트 메시지 표시
  18. show: function(message, type = 'info', duration = 3000) {
  19. this.createContainer();
  20. const container = document.getElementById('toast-container');
  21. // 토스트 요소 생성
  22. const toast = document.createElement('div');
  23. toast.style.minWidth = '250px';
  24. toast.style.padding = '12px 16px';
  25. toast.style.borderRadius = '4px';
  26. toast.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.15)';
  27. toast.style.display = 'flex';
  28. toast.style.alignItems = 'center';
  29. toast.style.animation = 'toast-in 0.3s ease-out forwards';
  30. toast.style.transition = 'all 0.3s ease';
  31. toast.style.overflow = 'hidden';
  32. // 타입에 따른 스타일 설정
  33. switch(type) {
  34. case 'success':
  35. toast.style.backgroundColor = '#52c41a';
  36. toast.style.color = 'white';
  37. break;
  38. case 'error':
  39. toast.style.backgroundColor = '#ff4d4f';
  40. toast.style.color = 'white';
  41. break;
  42. case 'warning':
  43. toast.style.backgroundColor = '#faad14';
  44. toast.style.color = 'white';
  45. break;
  46. default: // info
  47. toast.style.backgroundColor = '#1890ff';
  48. toast.style.color = 'white';
  49. }
  50. // 메시지 설정
  51. toast.textContent = message;
  52. // 컨테이너에 추가
  53. container.appendChild(toast);
  54. // 애니메이션 스타일 추가
  55. if (!document.getElementById('toast-style')) {
  56. const style = document.createElement('style');
  57. style.id = 'toast-style';
  58. style.textContent = `
  59. @keyframes toast-in {
  60. from {
  61. transform: translateY(100%);
  62. opacity: 0;
  63. }
  64. to {
  65. transform: translateY(0);
  66. opacity: 1;
  67. }
  68. }
  69. @keyframes toast-out {
  70. from {
  71. transform: translateY(0);
  72. opacity: 1;
  73. }
  74. to {
  75. transform: translateY(-100%);
  76. opacity: 0;
  77. }
  78. }
  79. `;
  80. document.head.appendChild(style);
  81. }
  82. // 지정된 시간 후 제거
  83. setTimeout(() => {
  84. toast.style.animation = 'toast-out 0.3s ease forwards';
  85. setTimeout(() => {
  86. container.removeChild(toast);
  87. }, 300);
  88. }, duration);
  89. return toast;
  90. },
  91. // 성공 메시지
  92. success: function(message, duration = 3000) {
  93. return this.show(message, 'success', duration);
  94. },
  95. // 에러 메시지
  96. error: function(message, duration = 3000) {
  97. return this.show(message, 'error', duration);
  98. },
  99. // 경고 메시지
  100. warning: function(message, duration = 3000) {
  101. return this.show(message, 'warning', duration);
  102. },
  103. // 정보 메시지
  104. info: function(message, duration = 3000) {
  105. return this.show(message, 'info', duration);
  106. }
  107. };

QingJ © 2025

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