Toastnew

Toast1

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

  1. function Toast(msg, duration = 3000, backgroundColor = 'rgba(0, 0, 0, 0.7)', textColor = 'rgb(255, 255, 255)', position = 'bottom-right') {
  2. const toast = document.createElement('div');
  3. toast.className = 'toast';
  4. toast.innerHTML = msg;
  5. toast.style.cssText = `
  6. max-width: 80%;
  7. min-width: 150px;
  8. padding: 0 14px;
  9. height: auto;
  10. color: ${textColor};
  11. line-height: 1.5;
  12. text-align: center;
  13. border-radius: 12px;
  14. position: fixed;
  15. z-index: 2147483647;
  16. background: ${backgroundColor};
  17. font-size: 16px;
  18. transition: opacity 0.5s ease-in, transform 0.5s ease-in;
  19. word-wrap: break-word;
  20. `;
  21.  
  22. // 使用位置参数设置位置样式
  23. const positions = {
  24. 'top': 'top: 50%; left: 50%; transform: translate(-50%, 0);',
  25. 'bottom': 'bottom: 10%; left: 50%; transform: translate(-50%, 0);',
  26. 'left': 'top: 50%; left: 10%; transform: translate(0, -50%);',
  27. 'right': 'top: 50%; right: 10%; transform: translate(0, -50%);',
  28. 'top-left': 'top: 10%; left: 10%; transform: translate(0, 0);',
  29. 'top-right': 'top: 10%; right: 10%; transform: translate(0, 0);',
  30. 'bottom-left': 'bottom: 10%; left: 10%; transform: translate(0, 0);',
  31. 'bottom-right': 'bottom: 10%; right: 10%; transform: translate(0, 0);',
  32. 'center': 'top: 50%; left: 50%; transform: translate(-50%, -50%);',
  33. };
  34.  
  35. toast.style.cssText += positions[position] || positions['bottom-right'];
  36.  
  37. document.body.appendChild(toast);
  38.  
  39. setTimeout(() => {
  40. toast.style.opacity = '0';
  41. setTimeout(() => document.body.removeChild(toast), 500);
  42. }, duration);
  43.  
  44. // 增加媒体查询来优化移动设备上的样式
  45. const mediaQuery = `
  46. @media only screen and (max-width: 600px) {
  47. .toast {
  48. font-size: 14px;
  49. padding: 10px;
  50. max-width: 90%;
  51. min-width: 0;
  52. }
  53. }
  54. `;
  55. const style = document.createElement('style');
  56. style.textContent = mediaQuery;
  57. document.head.appendChild(style);
  58. }

QingJ © 2025

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