Furaffinity-Message-Box

Library to hold MessageBox functions for Furaffinity

目前为 2025-03-06 提交的版本。查看 最新版本

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

  1. // ==UserScript==
  2. // @name Furaffinity-Message-Box
  3. // @namespace Violentmonkey Scripts
  4. // @require https://update.greasyfork.org/scripts/525666/1530872/Furaffinity-Prototype-Extensions.js
  5. // @grant GM_info
  6. // @version 1.0.0
  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. // ==/UserScript==
  12. // jshint esversion: 8
  13. (() => {
  14. "use strict";
  15. var MessageBoxButtons, MessageBoxIcon, DialogResult, MessageBoxThemes, __webpack_modules__ = {
  16. 978: (module, __webpack_exports__, __webpack_require__) => {
  17. __webpack_require__.d(__webpack_exports__, {
  18. A: () => __WEBPACK_DEFAULT_EXPORT__
  19. });
  20. 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());
  21. ___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', "" ]);
  22. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___;
  23. },
  24. 314: module => {
  25. module.exports = function(cssWithMappingToString) {
  26. var list = [];
  27. list.toString = function toString() {
  28. return this.map((function(item) {
  29. var content = "", needLayer = void 0 !== item[5];
  30. if (item[4]) content += "@supports (".concat(item[4], ") {");
  31. if (item[2]) content += "@media ".concat(item[2], " {");
  32. if (needLayer) content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
  33. content += cssWithMappingToString(item);
  34. if (needLayer) content += "}";
  35. if (item[2]) content += "}";
  36. if (item[4]) content += "}";
  37. return content;
  38. })).join("");
  39. };
  40. list.i = function i(modules, media, dedupe, supports, layer) {
  41. if ("string" == typeof modules) modules = [ [ null, modules, void 0 ] ];
  42. var alreadyImportedModules = {};
  43. if (dedupe) for (var k = 0; k < this.length; k++) {
  44. var id = this[k][0];
  45. if (null != id) alreadyImportedModules[id] = true;
  46. }
  47. for (var _k = 0; _k < modules.length; _k++) {
  48. var item = [].concat(modules[_k]);
  49. if (!dedupe || !alreadyImportedModules[item[0]]) {
  50. if (void 0 !== layer) if (void 0 === item[5]) item[5] = layer; else {
  51. item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
  52. item[5] = layer;
  53. }
  54. if (media) if (!item[2]) item[2] = media; else {
  55. item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
  56. item[2] = media;
  57. }
  58. if (supports) if (!item[4]) item[4] = "".concat(supports); else {
  59. item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
  60. item[4] = supports;
  61. }
  62. list.push(item);
  63. }
  64. }
  65. };
  66. return list;
  67. };
  68. },
  69. 601: module => {
  70. module.exports = function(i) {
  71. return i[1];
  72. };
  73. },
  74. 72: module => {
  75. var stylesInDOM = [];
  76. function getIndexByIdentifier(identifier) {
  77. for (var result = -1, i = 0; i < stylesInDOM.length; i++) if (stylesInDOM[i].identifier === identifier) {
  78. result = i;
  79. break;
  80. }
  81. return result;
  82. }
  83. function modulesToDom(list, options) {
  84. for (var idCountMap = {}, identifiers = [], i = 0; i < list.length; i++) {
  85. var item = list[i], id = options.base ? item[0] + options.base : item[0], count = idCountMap[id] || 0, identifier = "".concat(id, " ").concat(count);
  86. idCountMap[id] = count + 1;
  87. var indexByIdentifier = getIndexByIdentifier(identifier), obj = {
  88. css: item[1],
  89. media: item[2],
  90. sourceMap: item[3],
  91. supports: item[4],
  92. layer: item[5]
  93. };
  94. if (-1 !== indexByIdentifier) {
  95. stylesInDOM[indexByIdentifier].references++;
  96. stylesInDOM[indexByIdentifier].updater(obj);
  97. } else {
  98. var updater = addElementStyle(obj, options);
  99. options.byIndex = i;
  100. stylesInDOM.splice(i, 0, {
  101. identifier,
  102. updater,
  103. references: 1
  104. });
  105. }
  106. identifiers.push(identifier);
  107. }
  108. return identifiers;
  109. }
  110. function addElementStyle(obj, options) {
  111. var api = options.domAPI(options);
  112. api.update(obj);
  113. return function updater(newObj) {
  114. if (newObj) {
  115. if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) return;
  116. api.update(obj = newObj);
  117. } else api.remove();
  118. };
  119. }
  120. module.exports = function(list, options) {
  121. var lastIdentifiers = modulesToDom(list = list || [], options = options || {});
  122. return function update(newList) {
  123. newList = newList || [];
  124. for (var i = 0; i < lastIdentifiers.length; i++) {
  125. var index = getIndexByIdentifier(lastIdentifiers[i]);
  126. stylesInDOM[index].references--;
  127. }
  128. for (var newLastIdentifiers = modulesToDom(newList, options), _i = 0; _i < lastIdentifiers.length; _i++) {
  129. var _index = getIndexByIdentifier(lastIdentifiers[_i]);
  130. if (0 === stylesInDOM[_index].references) {
  131. stylesInDOM[_index].updater();
  132. stylesInDOM.splice(_index, 1);
  133. }
  134. }
  135. lastIdentifiers = newLastIdentifiers;
  136. };
  137. };
  138. },
  139. 659: module => {
  140. var memo = {};
  141. module.exports = function insertBySelector(insert, style) {
  142. var target = function getTarget(target) {
  143. if (void 0 === memo[target]) {
  144. var styleTarget = document.querySelector(target);
  145. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) try {
  146. styleTarget = styleTarget.contentDocument.head;
  147. } catch (e) {
  148. styleTarget = null;
  149. }
  150. memo[target] = styleTarget;
  151. }
  152. return memo[target];
  153. }(insert);
  154. if (!target) throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
  155. target.appendChild(style);
  156. };
  157. },
  158. 540: module => {
  159. module.exports = function insertStyleElement(options) {
  160. var element = document.createElement("style");
  161. options.setAttributes(element, options.attributes);
  162. options.insert(element, options.options);
  163. return element;
  164. };
  165. },
  166. 56: (module, __unused_webpack_exports, __webpack_require__) => {
  167. module.exports = function setAttributesWithoutAttributes(styleElement) {
  168. var nonce = true ? __webpack_require__.nc : 0;
  169. if (nonce) styleElement.setAttribute("nonce", nonce);
  170. };
  171. },
  172. 825: module => {
  173. module.exports = function domAPI(options) {
  174. if ("undefined" == typeof document) return {
  175. update: function update() {},
  176. remove: function remove() {}
  177. };
  178. var styleElement = options.insertStyleElement(options);
  179. return {
  180. update: function update(obj) {
  181. !function apply(styleElement, options, obj) {
  182. var css = "";
  183. if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
  184. if (obj.media) css += "@media ".concat(obj.media, " {");
  185. var needLayer = void 0 !== obj.layer;
  186. if (needLayer) css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {");
  187. css += obj.css;
  188. if (needLayer) css += "}";
  189. if (obj.media) css += "}";
  190. if (obj.supports) css += "}";
  191. var sourceMap = obj.sourceMap;
  192. if (sourceMap && "undefined" != typeof btoa) css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */");
  193. options.styleTagTransform(css, styleElement, options.options);
  194. }(styleElement, options, obj);
  195. },
  196. remove: function remove() {
  197. !function removeStyleElement(styleElement) {
  198. if (null === styleElement.parentNode) return false;
  199. styleElement.parentNode.removeChild(styleElement);
  200. }(styleElement);
  201. }
  202. };
  203. };
  204. },
  205. 113: module => {
  206. module.exports = function styleTagTransform(css, styleElement) {
  207. if (styleElement.styleSheet) styleElement.styleSheet.cssText = css; else {
  208. for (;styleElement.firstChild; ) styleElement.removeChild(styleElement.firstChild);
  209. styleElement.appendChild(document.createTextNode(css));
  210. }
  211. };
  212. }
  213. }, __webpack_module_cache__ = {};
  214. function __webpack_require__(moduleId) {
  215. var cachedModule = __webpack_module_cache__[moduleId];
  216. if (void 0 !== cachedModule) return cachedModule.exports;
  217. var module = __webpack_module_cache__[moduleId] = {
  218. id: moduleId,
  219. exports: {}
  220. };
  221. __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  222. return module.exports;
  223. }
  224. __webpack_require__.n = module => {
  225. var getter = module && module.__esModule ? () => module.default : () => module;
  226. __webpack_require__.d(getter, {
  227. a: getter
  228. });
  229. return getter;
  230. };
  231. __webpack_require__.d = (exports, definition) => {
  232. for (var key in definition) if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
  233. enumerable: true,
  234. get: definition[key]
  235. });
  236. };
  237. __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
  238. __webpack_require__.nc = void 0;
  239. !function(MessageBoxButtons) {
  240. MessageBoxButtons[MessageBoxButtons.OK = 0] = "OK";
  241. MessageBoxButtons[MessageBoxButtons.OKCancel = 1] = "OKCancel";
  242. MessageBoxButtons[MessageBoxButtons.AbortRetryIgnore = 2] = "AbortRetryIgnore";
  243. MessageBoxButtons[MessageBoxButtons.YesNoCancel = 3] = "YesNoCancel";
  244. MessageBoxButtons[MessageBoxButtons.YesNo = 4] = "YesNo";
  245. MessageBoxButtons[MessageBoxButtons.RetryCancel = 5] = "RetryCancel";
  246. }(MessageBoxButtons || (MessageBoxButtons = {}));
  247. !function(MessageBoxIcon) {
  248. MessageBoxIcon[MessageBoxIcon.None = 0] = "None";
  249. MessageBoxIcon[MessageBoxIcon.Error = 16] = "Error";
  250. MessageBoxIcon[MessageBoxIcon.Warning = 48] = "Warning";
  251. MessageBoxIcon[MessageBoxIcon.Information = 64] = "Information";
  252. MessageBoxIcon[MessageBoxIcon.Question = 32] = "Question";
  253. }(MessageBoxIcon || (MessageBoxIcon = {}));
  254. !function(DialogResult) {
  255. DialogResult[DialogResult.None = 0] = "None";
  256. DialogResult[DialogResult.OK = 1] = "OK";
  257. DialogResult[DialogResult.Cancel = 2] = "Cancel";
  258. DialogResult[DialogResult.Abort = 3] = "Abort";
  259. DialogResult[DialogResult.Retry = 4] = "Retry";
  260. DialogResult[DialogResult.Ignore = 5] = "Ignore";
  261. DialogResult[DialogResult.Yes = 6] = "Yes";
  262. DialogResult[DialogResult.No = 7] = "No";
  263. }(DialogResult || (DialogResult = {}));
  264. class MessageBoxIcons {
  265. static getIconSvg(icon) {
  266. switch (icon) {
  267. case MessageBoxIcon.Error:
  268. 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>';
  269.  
  270. case MessageBoxIcon.Warning:
  271. 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>';
  272.  
  273. case MessageBoxIcon.Information:
  274. 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>';
  275.  
  276. case MessageBoxIcon.Question:
  277. 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>';
  278.  
  279. case MessageBoxIcon.None:
  280. default:
  281. return "";
  282. }
  283. }
  284. }
  285. !function(MessageBoxThemes) {
  286. MessageBoxThemes.Dark = "dark";
  287. MessageBoxThemes.Aurora = "aurora";
  288. MessageBoxThemes.Retro = "retro";
  289. MessageBoxThemes.Slate = "slate";
  290. MessageBoxThemes.Light = "light";
  291. }(MessageBoxThemes || (MessageBoxThemes = {}));
  292. 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 = {};
  293. options.styleTagTransform = styleTagTransform_default();
  294. options.setAttributes = setAttributesWithoutAttributes_default();
  295. options.insert = insertBySelector_default().bind(null, "head");
  296. options.domAPI = styleDomAPI_default();
  297. options.insertStyleElement = insertStyleElement_default();
  298. injectStylesIntoStyleTag_default()(Style.A, options);
  299. Style.A && Style.A.locals && Style.A.locals;
  300. const string = class {
  301. static isNullOrWhitespace(str) {
  302. return null == str || "" === str.trim();
  303. }
  304. static isNullOrEmpty(str) {
  305. return null == str || "" === str;
  306. }
  307. };
  308. var _a, _b, _c, __awaiter = function(thisArg, _arguments, P, generator) {
  309. return new (P || (P = Promise))((function(resolve, reject) {
  310. function fulfilled(value) {
  311. try {
  312. step(generator.next(value));
  313. } catch (e) {
  314. reject(e);
  315. }
  316. }
  317. function rejected(value) {
  318. try {
  319. step(generator.throw(value));
  320. } catch (e) {
  321. reject(e);
  322. }
  323. }
  324. function step(result) {
  325. result.done ? resolve(result.value) : function adopt(value) {
  326. return value instanceof P ? value : new P((function(resolve) {
  327. resolve(value);
  328. }));
  329. }(result.value).then(fulfilled, rejected);
  330. }
  331. step((generator = generator.apply(thisArg, _arguments || [])).next());
  332. }));
  333. };
  334. class MessageBox {
  335. static getTheme() {
  336. return this.currentTheme;
  337. }
  338. static show(text_1) {
  339. return __awaiter(this, arguments, void 0, (function*(text, caption = "", buttons = MessageBoxButtons.OK, icon = MessageBoxIcon.None) {
  340. return new Promise((resolve => {
  341. this.resolvePromise = resolve;
  342. this.createMessageBox(text, caption, buttons, icon);
  343. }));
  344. }));
  345. }
  346. static createMessageBox(text, caption, buttons, icon) {
  347. this.overlay = document.createElement("div");
  348. this.overlay.className = "message-box-overlay";
  349. this.container = document.createElement("div");
  350. this.container.className = "message-box-container";
  351. const header = document.createElement("div");
  352. header.className = "message-box-header";
  353. if (icon !== MessageBoxIcon.None) {
  354. const iconContainer = document.createElement("div");
  355. iconContainer.className = "message-box-icon-container";
  356. iconContainer.innerHTML = MessageBoxIcons.getIconSvg(icon);
  357. header.appendChild(iconContainer);
  358. }
  359. if (!string.isNullOrWhitespace(caption)) {
  360. const title = document.createElement("h3");
  361. title.className = "message-box-title";
  362. title.textContent = caption;
  363. header.appendChild(title);
  364. }
  365. if (0 !== header.children.length) this.container.appendChild(header);
  366. const content = document.createElement("div");
  367. content.className = "message-box-content";
  368. content.textContent = text;
  369. this.container.appendChild(content);
  370. const buttonContainer = document.createElement("div");
  371. buttonContainer.className = "message-box-button-container";
  372. this.addButtons(buttonContainer, buttons);
  373. this.container.appendChild(buttonContainer);
  374. this.overlay.appendChild(this.container);
  375. document.body.appendChild(this.overlay);
  376. }
  377. static addButtons(buttonContainer, buttons) {
  378. switch (buttons) {
  379. case MessageBoxButtons.OK:
  380. this.createButton(buttonContainer, "OK", DialogResult.OK);
  381. break;
  382.  
  383. case MessageBoxButtons.OKCancel:
  384. this.createButton(buttonContainer, "OK", DialogResult.OK);
  385. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  386. break;
  387.  
  388. case MessageBoxButtons.AbortRetryIgnore:
  389. this.createButton(buttonContainer, "Abort", DialogResult.Abort);
  390. this.createButton(buttonContainer, "Retry", DialogResult.Retry);
  391. this.createButton(buttonContainer, "Ignore", DialogResult.Ignore);
  392. break;
  393.  
  394. case MessageBoxButtons.YesNoCancel:
  395. this.createButton(buttonContainer, "Yes", DialogResult.Yes);
  396. this.createButton(buttonContainer, "No", DialogResult.No);
  397. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  398. break;
  399.  
  400. case MessageBoxButtons.YesNo:
  401. this.createButton(buttonContainer, "Yes", DialogResult.Yes);
  402. this.createButton(buttonContainer, "No", DialogResult.No);
  403. break;
  404.  
  405. case MessageBoxButtons.RetryCancel:
  406. this.createButton(buttonContainer, "Retry", DialogResult.Retry);
  407. this.createButton(buttonContainer, "Cancel", DialogResult.Cancel);
  408. }
  409. }
  410. static createButton(container, text, result) {
  411. const button = document.createElement("button");
  412. button.className = "message-box-button";
  413. button.textContent = text;
  414. button.addEventListener("click", (() => {
  415. this.close(result);
  416. }));
  417. container.appendChild(button);
  418. }
  419. static close(result) {
  420. this.result = result;
  421. if (null != this.overlay) {
  422. document.body.removeChild(this.overlay);
  423. this.overlay = null;
  424. this.container = null;
  425. }
  426. if (null != this.resolvePromise) {
  427. this.resolvePromise(result);
  428. this.resolvePromise = null;
  429. }
  430. }
  431. }
  432. MessageBox.overlay = null;
  433. MessageBox.container = null;
  434. MessageBox.result = DialogResult.None;
  435. MessageBox.resolvePromise = null;
  436. MessageBox.currentTheme = MessageBoxThemes.Light;
  437. Object.defineProperties(window, {
  438. FAMessageBox: {
  439. get: () => MessageBox
  440. },
  441. FAMessageBoxButtons: {
  442. get: () => MessageBoxButtons
  443. },
  444. FAMessageBoxIcon: {
  445. get: () => MessageBoxIcon
  446. },
  447. FAMessageBoxResult: {
  448. get: () => DialogResult
  449. }
  450. });
  451. let themeClassName = "dark";
  452. const themeStylesheets = null !== (_a = document.head.querySelectorAll('link[rel="stylesheet"][href]')) && void 0 !== _a ? _a : [];
  453. for (const themeStylesheet of Array.from(themeStylesheets)) {
  454. const themePath = null !== (_c = null === (_b = themeStylesheet.getAttribute("href")) || void 0 === _b ? void 0 : _b.toLowerCase()) && void 0 !== _c ? _c : "";
  455. 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";
  456. }
  457. document.body.classList.add(`theme-${themeClassName}`);
  458. })();