/* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./src/discover/ext.isekai.discover.js": /*!*********************************************!*\ !*** ./src/discover/ext.isekai.discover.js ***! \*********************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _moduleRegister__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../moduleRegister */ \"./src/moduleRegister.js\");\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }, _typeof(obj); }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\n\nvar DiscoverWidget = /*#__PURE__*/function () {\n function DiscoverWidget(dom) {\n _classCallCheck(this, DiscoverWidget);\n this.baseDom = dom;\n this.pageUrl = null;\n this.api = new mw.Api();\n this.initDom();\n this.refreshPage();\n }\n _createClass(DiscoverWidget, [{\n key: \"initDom\",\n value: function initDom() {\n this.reloadButton = new OO.ui.ButtonWidget({\n icon: 'reload',\n label: mw.message('isekai-discover-change-btn').parse()\n });\n this.reloadButton.on('click', this.refreshPage.bind(this));\n this.readMoreButton = new OO.ui.ButtonWidget({\n icon: 'ellipsis',\n label: mw.message('isekai-discover-readmore-btn').parse(),\n flags: ['primary', 'progressive']\n });\n this.readMoreButton.on('click', this.showMore.bind(this));\n this.loadingBar = new OO.ui.ProgressBarWidget({\n progress: false\n });\n this.baseDom.find('.card-body .loading .spinner').append(this.loadingBar.$element);\n this.buttonGroup = new OO.ui.ButtonGroupWidget({\n items: [this.reloadButton, this.readMoreButton]\n });\n this.baseDom.find('.card-header .card-header-buttons').append(this.buttonGroup.$element);\n this.loading = this.baseDom.find('.card-body .loading');\n this.title = this.baseDom.find('.card-body .card-title');\n this.contentContainer = this.baseDom.find('.card-body .card-content');\n }\n }, {\n key: \"showMore\",\n value: function showMore() {\n if (this.pageUrl) {\n //页面存在就跳转\n window.open(this.pageUrl);\n }\n }\n }, {\n key: \"refreshPage\",\n value: function refreshPage() {\n var _this = this;\n this.pageUrl = null;\n this.clearContent();\n this.showLoading();\n this.getRandomPage().then(function (title) {\n _this.loadPage(title);\n });\n }\n }, {\n key: \"setTitle\",\n value: function setTitle(title) {\n this.title.text(title);\n }\n }, {\n key: \"showLoading\",\n value: function showLoading() {\n this.loading.show();\n this.contentContainer.hide();\n }\n }, {\n key: \"hideLoading\",\n value: function hideLoading() {\n this.loading.hide();\n this.contentContainer.show();\n }\n }, {\n key: \"clearContent\",\n value: function clearContent() {\n this.contentContainer.children().remove();\n }\n }, {\n key: \"setContent\",\n value: function setContent(dom) {\n this.hideLoading();\n this.clearContent();\n this.contentContainer.append(dom);\n }\n }, {\n key: \"showError\",\n value: function showError(msg) {\n var errorMsg = new OO.ui.MessageWidget({\n type: 'error',\n label: msg\n });\n this.setContent(errorMsg.$element);\n }\n }, {\n key: \"getRandomPage\",\n value: function getRandomPage() {\n var _this2 = this;\n return new Promise(function (resolve, reject) {\n _this2.api.get({\n action: 'query',\n list: 'random',\n rnlimit: 1,\n rnnamespace: 0\n }).done(function (data) {\n if (data.query && data.query.random && data.query.random.length > 0) {\n var title = data.query.random[0].title;\n _this2.setTitle(title);\n resolve(title);\n } else if (data.error) {\n _this2.showError(data.error.info);\n } else {\n _this2.showError(mw.message('isekai-discover-error-cannotload').parse());\n }\n });\n });\n }\n }, {\n key: \"parseHTMLString\",\n value: function parseHTMLString(txt) {\n try {\n var parser = new DOMParser();\n var xmlDoc = parser.parseFromString(txt, \"text/html\");\n return xmlDoc;\n } catch (e) {\n console.error(e.message);\n }\n return null;\n }\n }, {\n key: \"loadPage\",\n value: function loadPage(title) {\n var _this3 = this;\n var url = mw.util.getUrl(title);\n this.pageUrl = url;\n if (url.indexOf('?') >= 0) {\n url += '&';\n } else {\n url += '?';\n }\n url += 'action=render';\n $.get(url, function (str) {\n var dom = $(_this3.parseHTMLString(str));\n var content = dom.find('.mw-parser-output');\n if (content.length > 0) {\n //删除目录\n content.find('.toc').remove();\n _this3.setContent(content);\n }\n }, 'html');\n }\n }]);\n return DiscoverWidget;\n}();\n(0,_moduleRegister__WEBPACK_IMPORTED_MODULE_0__.registerModule)('ui.DiscoverWidget', DiscoverWidget);\n\n//# sourceURL=webpack://isekai-widgets/./src/discover/ext.isekai.discover.js?"); /***/ }), /***/ "./src/moduleRegister.js": /*!*******************************!*\ !*** ./src/moduleRegister.js ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"registerModule\": () => (/* binding */ registerModule)\n/* harmony export */ });\nfunction registerModule(namespace, func) {\n var nsList = namespace.split('.');\n if (!('isekai' in window)) {\n window.isekai = {};\n }\n var obj = window.isekai;\n for (var i = 0; i < nsList.length - 1; i++) {\n var ns = nsList[i];\n if (!(ns in obj)) {\n obj[ns] = {};\n }\n obj = obj[ns];\n }\n obj[nsList[i]] = func;\n}\n\n//# sourceURL=webpack://isekai-widgets/./src/moduleRegister.js?"); /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module can't be inlined because the eval devtool is used. /******/ var __webpack_exports__ = __webpack_require__("./src/discover/ext.isekai.discover.js"); /******/ /******/ })() ;