(
title = "KeepChatGPT",
content = "",
buttonvalue = "OK",
buttonfun = function (t) {
return t;
},
inputtype = "br",
inputvalue = "",
)
| 547 | |
| 548 | // 通用弹窗:用于输入配置、显示更新信息、展示赞赏二维码等。 |
| 549 | const ndialog = function ( |
| 550 | title = "KeepChatGPT", |
| 551 | content = "", |
| 552 | buttonvalue = "OK", |
| 553 | buttonfun = function (t) { |
| 554 | return t; |
| 555 | }, |
| 556 | inputtype = "br", |
| 557 | inputvalue = "", |
| 558 | ) { |
| 559 | const ndivalert = document.createElement("div"); |
| 560 | ndivalert.setAttribute("class", "kdialog-overlay"); |
| 561 | ndivalert.innerHTML = ` |
| 562 | <div class="kdialog-shell" role="dialog" aria-modal="true" aria-label="${title}"> |
| 563 | <div class="kdialog-head"> |
| 564 | <h2>${title}</h2> |
| 565 | </div> |
| 566 | <div class="kdialog-body"> |
| 567 | <p class="kdialogcontent">${content}</p> |
| 568 | <${inputtype} class="kdialoginput"></${inputtype}> |
| 569 | <div class="kdialog-actions"> |
| 570 | <button type="button" class="kdialogbtn">${buttonvalue}</button> |
| 571 | <button type="button" class="kdialogclose">Cancel</button> |
| 572 | </div> |
| 573 | </div> |
| 574 | </div> |
| 575 | `; |
| 576 | |
| 577 | if (inputtype === "br") { |
| 578 | $(".kdialoginput", ndivalert).style = `display: none`; |
| 579 | $(".kdialogcontent", ndivalert).style = `line-height: 2.2;`; |
| 580 | } else if (inputtype === "img") { |
| 581 | $(".kdialoginput", ndivalert).src = inputvalue; |
| 582 | $(".kdialoginput", ndivalert).style = |
| 583 | `max-height: 25rem; height: unset; width: unset; margin: 0 auto;`; |
| 584 | } else if (inputtype === "textarea") { |
| 585 | $(".kdialoginput", ndivalert).value = inputvalue; |
| 586 | $(".kdialoginput", ndivalert).style = `height: 10rem;`; |
| 587 | } else { |
| 588 | $(".kdialoginput", ndivalert).value = inputvalue; |
| 589 | } |
| 590 | |
| 591 | // 统一关闭逻辑,保证点击遮罩和取消按钮行为一致。 |
| 592 | const closeDialog = function () { |
| 593 | ndivalert.remove(); |
| 594 | document.removeEventListener("keydown", onEsc); |
| 595 | }; |
| 596 | const onEsc = function (event) { |
| 597 | if (event.key === "Escape") { |
| 598 | closeDialog(); |
| 599 | } |
| 600 | }; |
| 601 | |
| 602 | $(".kdialogclose", ndivalert).onclick = closeDialog; |
| 603 | $(".kdialogbtn", ndivalert).onclick = function () { |
| 604 | buttonfun(ndivalert); |
| 605 | closeDialog(); |
| 606 | }; |
no test coverage detected