Furaffinity-Message-Box

Library to hold MessageBox functions for Furaffinity

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

  1. // ==UserScript==
  2. // @name Furaffinity-Message-Box
  3. // @namespace Violentmonkey Scripts
  4. // @require https://update.gf.qytechs.cn/scripts/525666/1549449/Furaffinity-Prototype-Extensions.js
  5. // @grant GM_info
  6. // @version 1.0.1
  7. // @author Midori Dragon
  8. // @description Library to hold MessageBox functions for Furaffinity
  9. // @icon https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png
  10. // @license MIT
  11. // @homepageURL https://gf.qytechs.cn/scripts/528997-furaffinity-message-box
  12. // @supportURL https://gf.qytechs.cn/scripts/528997-furaffinity-message-box/feedback
  13. // ==/UserScript==
  14. // jshint esversion: 8
  15. (() => {
  16. "use strict";
  17. var MessageBoxButtons, MessageBoxIcon, DialogResult, MessageBoxThemes, __webpack_modules__ = {
  18. 978: (module, __webpack_exports__, __webpack_require__) => {
  19. __webpack_require__.d(__webpack_exports__, {
  20. A: () => __WEBPACK_DEFAULT_EXPORT__
  21. });
  22. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601), _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__), _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314), ___CSS_LOADER_EXPORT___ = __webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__)()(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  23. ___CSS_LOADER_EXPORT___.push([ module.id, '/* Base styles */\n.message-box-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n}\n\n/* Dark theme (default) */\n.message-box-container {\n border: 1px solid #444;\n border-radius: 5px;\n padding: 20px;\n max-width: 500px;\n width: 100%;\n font-family: Arial, sans-serif;\n transition: background-color 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;\n}\n\n.message-box-header {\n display: flex;\n align-items: center;\n margin-bottom: 15px;\n}\n\n.message-box-icon-container {\n margin-right: 15px;\n width: 32px;\n height: 32px;\n flex-shrink: 0;\n}\n\n.message-box-title {\n font-size: 18px;\n font-weight: bold;\n margin: 0;\n transition: color 0.3s;\n}\n\n.message-box-content {\n margin-bottom: 20px;\n line-height: 1.5;\n transition: color 0.3s;\n}\n\n.message-box-button-container {\n display: flex;\n justify-content: flex-end;\n gap: 10px;\n}\n\n.message-box-button {\n padding: 8px 16px;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n font-weight: bold;\n background-color: #f1efeb;\n transition: background-color 0.2s, color 0.2s, border-color 0.2s;\n}\n\n.message-box-button:hover {\n background-color: #e0ded8;\n}\n\n/* Theme: Dark */\nbody[class*="theme-dark"] .message-box-container {\n background-color: #353b45;\n border-color: #444;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);\n}\n\nbody[class*="theme-dark"] .message-box-button {\n background-color: #434b5b;\n}\n\nbody[class*="theme-dark"] .message-box-button:hover {\n background-color: #576175;\n}\n\n/* Theme: Aurora */\nbody[class*="theme-aurora"] .message-box-container {\n background-color: #262931;\n border-color: #444;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);\n}\n\nbody[class*="theme-aurora"] .message-box-button {\n background-color: #65707c;\n}\n\nbody[class*="theme-aurora"] .message-box-button:hover {\n background-color: #8692a0;\n}\n\n/* Theme: Retro */\nbody[class*="theme-retro"] .message-box-container {\n background-color: #2e3b41;\n border-color: #444;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);\n}\n\nbody[class*="theme-retro"] .message-box-button {\n background-color: #4c585e;\n}\n\nbody[class*="theme-retro"] .message-box-button:hover {\n background-color: #7b909a;\n}\n\n/* Theme: Slate */\nbody[class*="theme-slate"] .message-box-container {\n background-color: #202225;\n border-color: #444;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);\n}\n\nbody[class*="theme-slate"] .message-box-button {\n background-color: #8c8c8c;\n}\n\nbody[class*="theme-slate"] .message-box-button:hover {\n background-color: #b3b1b1;\n}\n\n/* Theme: Light - already defined in base styles */\nbody[class*="theme-light"] .message-box-container {\n background-color: #f7f7f7;\n border-color: #ccc;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n}\n\nbody[class*="theme-light"] .message-box-button {\n background-color: #f1efeb;\n}\n\nbody[class*="theme-light"] .message-box-button:hover {\n background-color: #f1ede7;\n}\n', "" ]);
  24. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___;
  25. },
  26. 314: module => {
  27. module.exports = function(cssWithMappingToString) {
  28. var list = [];
  29. list.toString = function toString() {
  30. return this.map((function(item) {
  31. var content = "", needLayer = void 0 !== item[5];
  32. if (item[4]) content += "@supports (".concat(item[4], ") {");
  33. if (item[2]) content += "@media ".concat(item[2], " {");
  34. if (needLayer) content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
  35. content += cssWithMappingToString(item);
  36. if (needLayer) content += "}";
  37. if (item[2]) content += "}";
  38. if (item[4]) content += "}";
  39. return content;
  40. })).join("");
  41. };
  42. list.i = function i(modules, media, dedupe, supports, layer) {
  43. if ("string" == typeof modules) modules = [ [ null, modules, void 0 ] ];
  44. var alreadyImportedModules = {};
  45. if (dedupe) for (var k = 0; k < this.length; k++) {
  46. var id = this[k][0];
  47. if (null != id) alreadyImportedModules[id] = true;
  48. }
  49. for (var _k = 0; _k < modules.length; _k++) {
  50. var item = [].concat(modules[_k]);
  51. if (!dedupe || !alreadyImportedModules[item[0]]) {
  52. if (void 0 !== layer) if (void 0 === item[5]) item[5] = layer; else {
  53. item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
  54. item[5] = layer;
  55. }
  56. if (media) if (!item[2]) item[2] = media; else {
  57. item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
  58. item[2] = media;
  59. }
  60. if (supports) if (!item[4]) item[4] = "".concat(supports); else {
  61. item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
  62. item[4] = supports;
  63. }
  64. list.push(item);
  65. }
  66. }
  67. };
  68. return list;
  69. };
  70. },
  71. 601: module => {
  72. module.exports = function(i) {
  73. return i[1];
  74. };
  75. },
  76. 72: module => {
  77. var stylesInDOM = [];
  78. function getIndexByIdentifier(identifier) {
  79. for (var result = -1, i = 0; i < stylesInDOM.length; i++) if (stylesInDOM[i].identifier === identifier) {
  80. result = i;
  81. break;
  82. }
  83. return result;
  84. }
  85. function modulesToDom(list, options) {
  86. for (var idCountMap = {}, identifiers = [], i = 0; i < list.length; i++) {
  87. var item = list[i], id = options.base ? item[0] + options.base : item[0], count = idCountMap[id] || 0, identifier = "".concat(id, " ").concat(count);
  88. idCountMap[id] = count + 1;
  89. var indexByIdentifier = getIndexByIdentifier(identifier), obj = {
  90. css: item[1],
  91. media: item[2],
  92. sourceMap: item[3],
  93. supports: item[4],
  94. layer: item[5]
  95. };
  96. if (-1 !== indexByIdentifier) {
  97. stylesInDOM[indexByIdentifier].references++;
  98. stylesInDOM[indexByIdentifier].updater(obj);
  99. } else {
  100. var updater = addElementStyle(obj, options);
  101. options.byIndex = i;
  102. stylesInDOM.splice(i, 0, {
  103. identifier,
  104. updater,
  105. references: 1
  106. });
  107. }
  108. identifiers.push(identifier);
  109. }
  110. return identifiers;
  111. }
  112. function addElementStyle(obj, options) {
  113. var api = options.domAPI(options);
  114. api.update(obj);
  115. return function updater(newObj) {
  116. if (newObj) {
  117. if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) return;
  118. api.update(obj = newObj);
  119. } else api.remove();
  120. };
  121. }
  122. module.exports = function(list, options) {
  123. var lastIdentifiers = modulesToDom(list = list || [], options = options || {});
  124. return function update(newList) {
  125. newList = newList || [];
  126. for (var i = 0; i < lastIdentifiers.length; i++) {
  127. var index = getIndexByIdentifier(lastIdentifiers[i]);
  128. stylesInDOM[index].references--;
  129. }
  130. for (var newLastIdentifiers = modulesToDom(newList, options), _i = 0; _i < lastIdentifiers.length; _i++) {
  131. var _index = getIndexByIdentifier(lastIdentifiers[_i]);
  132. if (0 === stylesInDOM[_index].references) {
  133. stylesInDOM[_index].updater();
  134. stylesInDOM.splice(_index, 1);
  135. }
  136. }
  137. lastIdentifiers = newLastIdentifiers;
  138. };
  139. };
  140. },
  141. 659: module => {
  142. var memo = {};
  143. module.exports = function insertBySelector(insert, style) {
  144. var target = function getTarget(target) {
  145. if (void 0 === memo[target]) {
  146. var styleTarget = document.querySelector(target);
  147. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) try {
  148. styleTarget = styleTarget.contentDocument.head;
  149. } catch (e) {
  150. styleTarget = null;
  151. }
  152. memo[target] = styleTarget;
  153. }
  154. return memo[target];
  155. }(insert);
  156. if (!target) throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
  157. target.appendChild(style);
  158. };
  159. },
  160. 540: module => {
  161. module.exports = function insertStyleElement(options) {
  162. var element = document.createElement("style");
  163. options.setAttributes(element, options.attributes);
  164. options.insert(element, options.options);
  165. return element;
  166. };
  167. },
  168. 56: (module, __unused_webpack_exports, __webpack_require__) => {
  169. module.exports = function setAttributesWithoutAttributes(styleElement) {
  170. var nonce = true ? __webpack_require__.nc : 0;
  171. if (nonce) styleElement.setAttribute("nonce", nonce);
  172. };
  173. },
  174. 825: module => {
  175. module.exports = function domAPI(options) {
  176. if ("undefined" == typeof document) return {
  177. update: function update() {},
  178. remove: function remove() {}
  179. };
  180. var styleElement = options.insertStyleElement(options);
  181. return {
  182. update: function update(obj) {
  183. !function apply(styleElement, options, obj) {
  184. var css = "";
  185. if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
  186. if (obj.media) css += "@media ".concat(obj.media, " {");
  187. var needLayer = void 0 !== obj.layer;
  188. if (needLayer) css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {");
  189. css += obj.css;
  190. if (needLayer) css += "}";
  191. if (obj.media) css += "}";
  192. if (obj.supports) css += "}";
  193. var sourceMap = obj.sourceMap;
  194. if (sourceMap && "undefined" != typeof btoa) css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */");
  195. options.styleTagTransform(css, styleElement, options.options);
  196. }(styleElement, options, obj);
  197. },
  198. remove: function remove() {
  199. !function removeStyleElement(styleElement) {
  200. if (null === styleElement.parentNode) return false;
  201. styleElement.parentNode.removeChild(styleElement);
  202. }(styleElement);
  203. }
  204. };
  205. };
  206. },
  207. 113: module => {
  208. module.exports = function styleTagTransform(css, styleElement) {
  209. if (styleElement.styleSheet) styleElement.styleSheet.cssText = css; else {
  210. for (;styleElement.firstChild; ) styleElement.removeChild(styleElement.firstChild);
  211. styleElement.appendChild(document.createTextNode(css));
  212. }
  213. };
  214. }
  215. }, __webpack_module_cache__ = {};
  216. function __webpack_require__(moduleId) {
  217. var cachedModule = __webpack_module_cache__[moduleId];
  218. if (void 0 !== cachedModule) return cachedModule.exports;
  219. var module = __webpack_module_cache__[moduleId] = {
  220. id: moduleId,
  221. exports: {}
  222. };
  223. __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  224. return module.exports;
  225. }
  226. __webpack_require__.n = module => {
  227. var getter = module && module.__esModule ? () => module.default : () => module;
  228. __webpack_require__.d(getter, {
  229. a: getter
  230. });
  231. return getter;
  232. };
  233. __webpack_require__.d = (exports, definition) => {
  234. for (var key in definition) if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
  235. enumerable: true,
  236. get: definition[key]
  237. });
  238. };
  239. __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
  240. __webpack_require__.nc = void 0;
  241. !function(MessageBoxButtons) {
  242. MessageBoxButtons[MessageBoxButtons.OK = 0] = "OK";
  243. MessageBoxButtons[MessageBoxButtons.OKCancel = 1] = "OKCancel";
  244. MessageBoxButtons[MessageBoxButtons.AbortRetryIgnore = 2] = "AbortRetryIgnore";
  245. MessageBoxButtons[MessageBoxButtons.YesNoCancel = 3] = "YesNoCancel";
  246. MessageBoxButtons[MessageBoxButtons.YesNo = 4] = "YesNo";
  247. MessageBoxButtons[MessageBoxButtons.RetryCancel = 5] = "RetryCancel";
  248. }(MessageBoxButtons || (MessageBoxButtons = {}));
  249. !function(MessageBoxIcon) {
  250. MessageBoxIcon[MessageBoxIcon.None = 0] = "None";
  251. MessageBoxIcon[MessageBoxIcon.Error = 16] = "Error";
  252. MessageBoxIcon[MessageBoxIcon.Warning = 48] = "Warning";
  253. MessageBoxIcon[MessageBoxIcon.Information = 64] = "Information";
  254. MessageBoxIcon[MessageBoxIcon.Question = 32] = "Question";
  255. }(MessageBoxIcon || (MessageBoxIcon = {}));
  256. !function(DialogResult) {
  257. DialogResult[DialogResult.None = 0] = "None";
  258. DialogResult[DialogResult.OK = 1] = "OK";
  259. DialogResult[DialogResult.Cancel = 2] = "Cancel";
  260. DialogResult[DialogResult.Abort = 3] = "Abort";
  261. DialogResult[DialogResult.Retry = 4] = "Retry";
  262. DialogResult[DialogResult.Ignore = 5] = "Ignore";
  263. DialogResult[DialogResult.Yes = 6] = "Yes";
  264. DialogResult[DialogResult.No = 7] = "No";
  265. }(DialogResult || (DialogResult = {}));
  266. class MessageBoxIcons {
  267. static getIconSvg(icon) {
  268. switch (icon) {
  269. case MessageBoxIcon.Error:
  270. return '<svg xmlns="http://www.w3.org/2000/svg" height="32px" viewBox="0 -960 960 960" width="32px" fill="#ff0000"><path d="M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm-40-160h80v-240h-80v240Zm40 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>';
  271.  
  272. case MessageBoxIcon.Warning:
  273. return '<svg xmlns="http://www.w3.org/2000/svg" height="32px" viewBox="0 -960 960 960" width="32px" fill="#ffcc4d"><path d="m40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z"/></svg>';
  274.  
  275. case MessageBoxIcon.Information:
  276. return '<svg xmlns="http://www.w3.org/2000/svg" height="32px" viewBox="0 -960 960 960" width="32px" fill="#2196f3"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>';
  277.  
  278. case MessageBoxIcon.Question:
  279. return '<svg xmlns="http://www.w3.org/2000/svg" height="32px" viewBox="0 -960 960 960" width="32px" fill="#2196f3"><path d="M478-240q21 0 35.5-14.5T528-290q0-21-14.5-35.5T478-340q-21 0-35.5 14.5T428-290q0 21 14.5 35.5T478-240Zm-36-154h74q0-33 7.5-52t42.5-52q26-26 41-49.5t15-56.5q0-56-41-86t-97-30q-57 0-92.5 30T342-618l66 26q5-18 22.5-39t53.5-21q32 0 48 17.5t16 38.5q0 20-12 37.5T506-526q-44 39-54 59t-10 73Zm38 314q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>';
  280.  
  281. case MessageBoxIcon.None:
  282. default:
  283. return "";
  284. }
  285. }
  286. }
  287. !function(MessageBoxThemes) {
  288. MessageBoxThemes.Dark = "dark";
  289. MessageBoxThemes.Aurora = "aurora";
  290. MessageBoxThemes.Retro = "retro";
  291. MessageBoxThemes.Slate = "slate";
  292. MessageBoxThemes.Light = "light";
  293. }(MessageBoxThemes || (MessageBoxThemes = {}));
  294. var injectStylesIntoStyleTag = __webpack_require__(72), injectStylesIntoStyleTag_default = __webpack_require__.n(injectStylesIntoStyleTag), styleDomAPI = __webpack_require__(825), styleDomAPI_default = __webpack_require__.n(styleDomAPI), insertBySelector = __webpack_require__(659), insertBySelector_default = __webpack_require__.n(insertBySelector), setAttributesWithoutAttributes = __webpack_require__(56), setAttributesWithoutAttributes_default = __webpack_require__.n(setAttributesWithoutAttributes), insertStyleElement = __webpack_require__(540), insertStyleElement_default = __webpack_require__.n(insertStyleElement), styleTagTransform = __webpack_require__(113), styleTagTransform_default = __webpack_require__.n(styleTagTransform), Style = __webpack_require__(978), options = {};
  295. options.styleTagTransform = styleTagTransform_default();
  296. options.setAttributes = setAttributesWithoutAttributes_default();
  297. options.insert = insertBySelector_default().bind(null, "head");
  298. options.domAPI = styleDomAPI_default();
  299. options.insertStyleElement = insertStyleElement_default();
  300. injectStylesIntoStyleTag_default()(Style.A, options);
  301. Style.A && Style.A.locals && Style.A.locals;
  302. const string = class {
  303. static isNullOrWhitespace(str) {
  304. return null == str || "" === str.trim();
  305. }
  306. static isNullOrEmpty(str) {
  307. return null == str || "" === str;
  308. }
  309. };
  310. var _a, _b, _c, __awaiter = function(thisArg, _arguments, P, generator) {
  311. return new (P || (P = Promise))((function(resolve, reject) {
  312. function fulfilled(value) {
  313. try {
  314. step(generator.next(value));
  315. } catch (e) {
  316. reject(e);
  317. }
  318. }
  319. function rejected(value) {
  320. try {
  321. step(generator.throw(value));
  322. } catch (e) {
  323. reject(e);
  324. }
  325. }
  326. function step(result) {
  327. result.done ? resolve(result.value) : function adopt(value) {
  328. return value instanceof P ? value : new P((function(resolve) {
  329. resolve(value);
  330. }));
  331. }(result.value).then(fulfilled, rejected);
  332. }
  333. step((generator = generator.apply(thisArg, _arguments || [])).next());
  334. }));
  335. };
  336. class MessageBox {
  337. static getTheme() {
  338. return this.currentTheme;
  339. }
  340. static show(text_1) {
  341. return __awaiter(this, arguments, void 0, (function*(text, caption = "", buttons = MessageBoxButtons.OK, icon = MessageBoxIcon.None) {
  342. return new Promise((resolve => {
  343. this.resolvePromise = resolve;
  344. this.createMessageBox(text, caption, buttons, icon);
  345. }));
  346. }));
  347. }
  348. static createMessageBox(text, caption, buttons, icon) {
  349. this.overlay = document.createElement("div");
  350. this.overlay.className = "message-box-overlay";
  351. this.container = document.createElement("div");
  352. this.container.className = "message-box-container";
  353. const header = document.createElement("div");
  354. header.className = "message-box-header";
  355. if (icon !== MessageBoxIcon.None) {
  356. const iconContainer = document.createElement("div");
  357. iconContainer.className = "message-box-icon-container";
  358. iconContainer.innerHTML = MessageBoxIcons.getIconSvg(icon);
  359. header.appendChild(iconContainer);
  360. }
  361. if (!string.isNullOrWhitespace(caption)) {
  362. const title = document.createElement("h3");
  363. title.className = "message-box-title";
  364. title.textContent = caption;
  365. header.appendChild(title);
  366. }
  367. if (0 !== header.children.length) this.container.appendChild(header);
  368. const content = document.createElement("div");
  369. content.className = "message-box-content";
  370. content.textContent = text;
  371. this.container.appendChild(content);
  372. const buttonContainer = document.createElement("div");
  373. buttonContainer.className = "message-box-button-container";
  374. this.addButtons(buttonContainer, buttons);
  375. this.container.appendChild(buttonContainer);
  376. this.overlay.appendChild(this.container);
  377. document.body.appendChild(this.overlay);
  378. }
  379. static addButtons(buttonContainer, buttons) {
  380. switch (buttons) {
  381. case MessageBoxButtons.OK:
  382. this.createButton(buttonContainer, "OK", DialogResult.OK);
  383. break;
  384.  
  385. case MessageBoxButtons.OKCancel:
  386. this.createButton(buttonContainer, "OK", DialogResult.OK);
  387. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  388. break;
  389.  
  390. case MessageBoxButtons.AbortRetryIgnore:
  391. this.createButton(buttonContainer, "Abort", DialogResult.Abort);
  392. this.createButton(buttonContainer, "Retry", DialogResult.Retry);
  393. this.createButton(buttonContainer, "Ignore", DialogResult.Ignore);
  394. break;
  395.  
  396. case MessageBoxButtons.YesNoCancel:
  397. this.createButton(buttonContainer, "Yes", DialogResult.Yes);
  398. this.createButton(buttonContainer, "No", DialogResult.No);
  399. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  400. break;
  401.  
  402. case MessageBoxButtons.YesNo:
  403. this.createButton(buttonContainer, "Yes", DialogResult.Yes);
  404. this.createButton(buttonContainer, "No", DialogResult.No);
  405. break;
  406.  
  407. case MessageBoxButtons.RetryCancel:
  408. this.createButton(buttonContainer, "Retry", DialogResult.Retry);
  409. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  410. }
  411. }
  412. static createButton(container, text, result) {
  413. const button = document.createElement("button");
  414. button.className = "message-box-button";
  415. button.textContent = text;
  416. button.addEventListener("click", (() => {
  417. this.close(result);
  418. }));
  419. container.appendChild(button);
  420. }
  421. static close(result) {
  422. this.result = result;
  423. if (null != this.overlay) {
  424. document.body.removeChild(this.overlay);
  425. this.overlay = null;
  426. this.container = null;
  427. }
  428. if (null != this.resolvePromise) {
  429. this.resolvePromise(result);
  430. this.resolvePromise = null;
  431. }
  432. }
  433. }
  434. MessageBox.overlay = null;
  435. MessageBox.container = null;
  436. MessageBox.result = DialogResult.None;
  437. MessageBox.resolvePromise = null;
  438. MessageBox.currentTheme = MessageBoxThemes.Light;
  439. Object.defineProperties(window, {
  440. FAMessageBox: {
  441. get: () => MessageBox
  442. },
  443. FAMessageBoxButtons: {
  444. get: () => MessageBoxButtons
  445. },
  446. FAMessageBoxIcon: {
  447. get: () => MessageBoxIcon
  448. },
  449. FADialogResult: {
  450. get: () => DialogResult
  451. }
  452. });
  453. let themeClassName = "dark";
  454. const themeStylesheets = null !== (_a = document.head.querySelectorAll('link[rel="stylesheet"][href]')) && void 0 !== _a ? _a : [];
  455. for (const themeStylesheet of Array.from(themeStylesheets)) {
  456. const themePath = null !== (_c = null === (_b = themeStylesheet.getAttribute("href")) || void 0 === _b ? void 0 : _b.toLowerCase()) && void 0 !== _c ? _c : "";
  457. if (themePath.includes("dark")) themeClassName = "dark"; else if (themePath.includes("aurora")) themeClassName = "aurora"; else if (themePath.includes("retro")) themeClassName = "retro"; else if (themePath.includes("slate")) themeClassName = "slate"; else if (themePath.includes("light")) themeClassName = "light";
  458. }
  459. document.body.classList.add(`theme-${themeClassName}`);
  460. })();

QingJ © 2025

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