elegant alert()库

Customized alert box at the top right corner, auto close in a few seconds. Click on the alert box will close it immediately and copy the alert message to clipboard.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/425166/957828/elegant%20alert%28%29%E5%BA%93.js

  1. // ==UserScript==
  2. // @name elegant alert()库
  3. // @name:zh-CN 优雅的 alert()库,基于Evan Tseng修改,权利归原作者所有,作者链接https://gf.qytechs.cn/zh-CN/scripts/391736-elegant-alert
  4. // @namespace https://gf.qytechs.cn/zh-TW/users/393133-evan-tseng
  5. // @author Evan Tseng
  6. // @version 1.07
  7. // @include *://*
  8. // @run-at document-start
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. var alertWrap = null;
  14. const ElegantAlertBox = function(msg){
  15. const boxFont = '400 14pt sans-serif',
  16. boxFontColor = '#220',
  17. boxColor = 'rgba(240,240,210,.85)',
  18. boxHoverColor = 'rgba(255,255,255,.85)',
  19. popFontColor = '#8FF',
  20. popBgColor = '#b00',
  21. countdownColor = 'rgba(0,0,255,.1)',
  22. duration = '6100';
  23.  
  24. if(!alertWrap) {
  25. const css = '@media screen and (max-width: 600pt) { .elegantAlertBoxWrapper>div { max-width:75vw } }'+
  26. '@media screen and (min-width: 600pt) { .elegantAlertBoxWrapper>div { max-width:450pt } }'+
  27. '.elegantAlertBoxWrapper { position:fixed; top:3mm; right:2mm; padding:5mm; max-height:calc(100vh - 13mm); z-index:2147483647; -webkit-user-select:none; user-select:none; }'+
  28. '.elegantAlertBoxWrapper>div { position:relative; float:right; clear:right; font:'+ boxFont +'; line-height:1.25; color:'+ popFontColor +'; background:'+ popBgColor +'; min-height:1.25em; padding:2px 2mm; margin-bottom:1.5mm; overflow:auto; border-radius:5px; opacity:0; cursor:pointer; box-shadow:inset 0 0 0 1px rgba(255,255,255,.8), 0 1px 2mm rgba(0,0,0,.7); backdrop-filter:blur(2px); -webkit-backdrop-filter:blur(2px); }'+
  29. '.elegantAlertBoxWrapper>div>.eaBar { position: absolute; left:0; top:0; width:100%; height:100%; background:'+ countdownColor +'; border-radius: 3px }'+
  30. '.elegantAlertBoxWrapper>.pop { color:'+ boxFontColor +'; background:'+ boxColor +'; opacity:1; max-height:10em; animation: pulse1 .3s 1 }'+
  31. '.elegantAlertBoxWrapper>.eaNormal { color:'+ boxFontColor +'; background:'+ boxColor +'; opacity:1; max-height:10em; }'+
  32. '.elegantAlertBoxWrapper>.eaNormal>.eaBar, .elegantAlertBoxWrapper>.eaClose>.eaBar { width:0; transition:' + duration + 'ms linear}'+
  33. '.elegantAlertBoxWrapper>.eaClose { background:'+ boxColor +'; opacity:0; min-height:0; max-height:0; padding:0 2mm; margin:0; transition: .6s linear }'+
  34. '.elegantAlertBoxWrapper>.eaNormal:hover { font-weight:600; background:'+ boxHoverColor +'; z-index:2; box-shadow:inset 0 0 0 1px rgba(255,255,255,.8), 0 1px 2mm rgba(0,0,0,.8); animation: pulse2 .2s 1 }'+
  35. '.elegantAlertBoxWrapper>.eaNormal:active { box-shadow:0 0 0 1px #777, inset 0 1px 2px #555; transform:scale(0.97); transition: .1s }'+
  36. '@keyframes pulse1 { 0% { opacity:0.5 } 12% { color: ' + popFontColor + '; background: ' + popBgColor + '; transform: scale(1.1) } 50% { transform: scale(1.02) } 100% { opacity:1; } }'+
  37. '@keyframes pulse2 { 0% { } 30% { left: -2px; } 70% { left: 1px } 100% { } }',
  38.  
  39. cssStyle = document.createElement('style');
  40. if(cssStyle.styleSheet) cssStyle.styleSheet.cssText = css;
  41. else cssStyle.appendChild(document.createTextNode(css));
  42. document.querySelector('head').appendChild(cssStyle);
  43.  
  44. alertWrap = document.createElement('div');
  45. alertWrap.setAttribute("class", "elegantAlertBoxWrapper");
  46. document.body.appendChild(alertWrap);
  47. }
  48.  
  49. this.exist = true;
  50. this.createBox = function(text){
  51. var box = this,
  52. alBox = document.createElement('div');
  53. alertWrap.appendChild(alBox);
  54. alBox.innerHTML = '<div class="eaBar"></div>' + text;
  55. alBox.setAttribute("class", "pop");
  56. alBox.onclick = function(){
  57. let tmp = document.createElement('textArea');
  58. tmp.value = text;
  59. document.body.appendChild(tmp);
  60. tmp.select();
  61. document.execCommand('copy');
  62. tmp.remove();
  63. box.close();
  64. };
  65. return alBox;
  66. };
  67. this.show = function(){
  68. var box = this;
  69. setTimeout(function(){
  70. box.elm.setAttribute("class", "eaNormal");
  71. setTimeout(function(){
  72. if(box.exist) box.close();
  73. }, duration);
  74. }, 500);
  75. };
  76. this.close = function(){
  77. var box = this;
  78. box.elm.setAttribute("class", "eaClose");
  79. setTimeout(function(){
  80. if(box.exist) {
  81. box.elm.remove();
  82. if(!alertWrap.hasChildNodes()) {
  83. alertWrap.remove();
  84. alertWrap = null
  85. }
  86. box.elm = null;
  87. box.exist = false;
  88. }
  89. }, 1000);
  90. };
  91. this.elm = this.createBox(msg);
  92. this.show();
  93. };

QingJ © 2025

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