You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
14 KiB
JavaScript

(()=>{"use strict";function t(t,e){var n=t.split(".");"isekai"in window||(window.isekai={});for(var o=window.isekai,i=0;i<n.length-1;i++){var r=n[i];r in o||(o[r]={}),o=o[r]}o[n[i]]=e}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,n){for(var o=0;o<n.length;o++){var i=n[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(void 0,r=function(t,n){if("object"!==e(t)||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,"string");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(i.key),"symbol"===e(r)?r:String(r)),i)}var r}function o(){o=function(t,e){return new r(t,void 0,e)};var t=RegExp.prototype,n=new WeakMap;function r(t,e,o){var a=new RegExp(t,e);return n.set(a,o||n.get(t)),i(a,r.prototype)}function a(t,e){var o=n.get(e);return Object.keys(o).reduce((function(e,n){var i=o[n];if("number"==typeof i)e[n]=t[i];else{for(var r=0;void 0===t[i[r]]&&r+1<i.length;)r++;e[n]=t[i[r]]}return e}),Object.create(null))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(r,RegExp),r.prototype.exec=function(e){var n=t.exec.call(this,e);if(n){n.groups=a(n,this);var o=n.indices;o&&(o.groups=a(o,this))}return n},r.prototype[Symbol.replace]=function(o,i){if("string"==typeof i){var r=n.get(this);return t[Symbol.replace].call(this,o,i.replace(/\$<([^>]+)>/g,(function(t,e){var n=r[e];return"$"+(Array.isArray(n)?n.join("$"):n)})))}if("function"==typeof i){var l=this;return t[Symbol.replace].call(this,o,(function(){var t=arguments;return"object"!=e(t[t.length-1])&&(t=[].slice.call(t)).push(a(t,l)),i.apply(this,t)}))}return t[Symbol.replace].call(this,o,i)},o.apply(this,arguments)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}var r,a=!(!(r=navigator.userAgent.match(o(/Version\/(\S+) Mobile\/\S+/,{version:1})))||!r.groups.version),l=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.menuItems=[],this.menuItemsUpdated=!0,this.initDom()}var e,o;return e=t,o=[{key:"initDom",value:function(){var t=this,e=document.createElement("div");e.id="iseai-contextmenu",e.className="oo-ui-toolGroup-tools oo-ui-popupToolGroup-tools oo-ui-listToolGroup-tools oo-ui-toolGroup-enabled-tools oo-ui-popupToolGroup-active-tools",e.style.minWidth="unset",e.style.display="none",this.menuContainer=e;var n=document.createElement("div");n.className="isekai-contextmenu-cover",n.style.display="none",n.addEventListener("click",(function(){t.hide()})),this.menuCover=n,document.body.appendChild(e),document.body.appendChild(n)}},{key:"setMenuItem",value:function(t){this.menuItems=t,this.menuItemsUpdated=!0}},{key:"updateMenuItemDom",value:function(){var t=this;this.menuItemsUpdated&&(this.menuContainer.innerHTML="",this.menuItems.sort((function(t,e){var n,o;return(null!==(n=e.priority)&&void 0!==n?n:0)-(null!==(o=t.priority)&&void 0!==o?o:0)})).forEach((function(e){var n=document.createElement("span");n.className="oo-ui-widget oo-ui-widget-enabled oo-ui-tool";var o=document.createElement("a");o.className="oo-ui-tool-link",o.tabIndex=0,o.role="button",o.addEventListener("click",(function(n){var o;n.preventDefault(),null===(o=e.onClick)||void 0===o||o.call(e),t.hide()}));var i=document.createElement("span");i.className="oo-ui-tool-title",i.innerText=e.label,o.appendChild(i),n.appendChild(o),t.menuContainer.appendChild(n)})),this.menuItemsUpdated=!1)}},{key:"show",value:function(){for(var t=0,e=0,n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];if(o[0]instanceof MouseEvent)t=o[0].clientX,e=o[0].clientY;else if(o[0]instanceof Element){var r=o[0].getBoundingClientRect();t=r.left,e=r.top}else 2===o.length&&"number"==typeof o[0]&&"number"==typeof o[1]&&(t=o[0],e=o[1]);this.menuItemsUpdated&&this.updateMenuItemDom(),this.menuContainer.style.display="block",this.menuCover.style.display="block";var a=this.menuContainer.clientWidth,l=this.menuContainer.clientHeight;t+a>window.innerWidth&&(t-=a),e+l>window.innerHeight&&(e-=l),this.menuContainer.style.left=t+"px",this.menuContainer.style.top=e+"px"}},{key:"hide",value:function(){this.menuContainer.style.display="none",this.menuCover.style.display="none"}},{key:"bindToDom",value:function(t){var e,n=this;t.addEventListener("contextmenu",(function(t){t.preventDefault(),n.show(t)})),a&&(t.addEventListener("touchstart",(function(t){document.body.classList.add("isekai-contextmenu-ios-longpress"),e=setTimeout((function(){t.preventDefault(),n.show({x:t.pageX-window.scrollX,y:t.pageY-window.scrollY})}),200)})),t.addEventListener("touchend",(function(t){document.body.classList.remove("isekai-contextmenu-ios-longpress"),e&&clearInterval(e)})))}}],o&&n(e.prototype,o),Object.defineProperty(e,"prototype",{writable:!1}),t}();function s(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function c(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function f(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?c(Object(n),!0).forEach((function(e){m(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function d(t){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},d(t)}function p(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,b(o.key),o)}}function m(t,e,n){return(e=b(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function b(t){var e=function(t,e){if("object"!==d(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==d(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===d(e)?e:String(e)}var y=function(){function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),m(this,"_onContextMenu",(function(t){t.preventDefault(),document.body.removeEventListener("contextmenu",e._onContextMenu),e.show()})),this.domCreated=!1,this.btnList=[],this.hidden=!1}var e,n;return e=t,(n=[{key:"initDom",value:function(){var t=this;if(!this.domCreated){var e=document.querySelector("#isekai-fab-container");if(e)this.fabContainer=e;else{(e=document.createElement("div")).id="isekai-fab-container",e.className="isekai-fab-group",this.fabContainer=e,document.body.appendChild(e);var n=[{label:mw.msg("isekai-fab-hide-fab-button"),onClick:function(){t.hide(),mw.notify(mw.msg("isekai-fab-hide-fab-button-success"))}}],o=new isekai.ui.ContextMenuWidget;o.setMenuItem(n),o.bindToDom(e),this.contextMenu=o}this.domCreated=!0}}},{key:"addButton",value:function(t){var e;this.domCreated||this.initDom();var n=document.createElement("a");if(n.role="button",n.href="javascript:void(0);",n.className="isekai-fab-btn",n.dataset.id=t.id,t.icon){var o=document.createElement("span");o.className="isekai-fab-btn-icon","string"==typeof t.icon?o.innerHTML=t.icon:"object"===d(t.icon)&&o.appendChild(t.icon),n.appendChild(o)}t.label&&(n.title=t.label,n.setAttribute("aria-label",t.label)),t.onClick&&n.addEventListener("click",t.onClick);var i=f(f({},t),{},{element:n,proiorty:null!==(e=t.priority)&&void 0!==e?e:0}),r=null,a=0;return this.btnList.forEach((function(t,e){t.priority<i.priority&&(r=t.element,a=e)})),r?(this.fabContainer.insertBefore(n,r),this.btnList=[].concat(s(this.btnList.slice(0,a)),[i],s(this.btnList.slice(a)))):(this.fabContainer.appendChild(n),this.btnList.push(i)),n}},{key:"removeButton",value:function(t){var e="";"string"==typeof t?e=t:"object"===d(t)&&(e=t.id);var n=this.fabContainer.querySelector('.isekai-fab-btn[data-id="'.concat(e,'"]'));n&&n.remove()}},{key:"hide",value:function(){this.fabContainer.classList.add("isekai-fab-hidden"),this.hidden=!0,document.body.addEventListener("contextmenu",this._onContextMenu)}},{key:"show",value:function(){this.fabContainer.classList.remove("isekai-fab-hidden"),this.hidden=!1}}])&&p(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function v(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function h(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?v(Object(n),!0).forEach((function(e){g(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):v(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function g(t,e,n){return(e=O(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function w(t){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w(t)}function k(t){return function(t){if(Array.isArray(t))return C(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return C(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function j(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,O(o.key),o)}}function O(t){var e=function(t,e){if("object"!==w(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==w(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===w(e)?e:String(e)}var S=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.domCreated=!1,this.btnList=[]}var e,n;return e=t,(n=[{key:"initDom",value:function(){if(!this.domCreated){var t=document.querySelector("#isekai-bottom-nav");if(t)this.bottomNavContainer=t,this.bottomNavElem=t.querySelector(".isekai-bottom-nav");else{(t=document.createElement("nav")).id="isekai-bottom-nav",t.className="isekai-bottom-nav-container",this.bottomNavContainer=t;var e=document.createElement("div");e.className="isekai-bottom-nav",this.bottomNavElem=e;var n=document.createElement("div");n.id="isekai-bottom-nav-placeholder",n.className="isekai-bottom-nav-placeholder",t.appendChild(e),document.body.appendChild(t),document.body.appendChild(n),document.body.classList.add("use-isekai-bottom-nav")}}}},{key:"addButton",value:function(t){var e;this.domCreated||this.initDom();var n,o=document.createElement("a");if(o.role="button",o.href="javascript:void(0);",o.classList.add("isekai-bottom-nav-btn"),o.dataset.id=t.id,t.className&&(n=o.classList).add.apply(n,k(t.className.split(" "))),t.icon){var i=document.createElement("span");i.className="isekai-bottom-nav-btn-icon","string"==typeof t.icon?i.innerHTML=t.icon:"object"===w(t.icon)&&i.appendChild(t.icon),o.appendChild(i)}if(t.label&&(o.title=t.label,o.setAttribute("aria-label",t.label)),t.expand){var r;o.classList.add("isekai-bottom-nav-btn-expand");var a=document.createElement("span");a.className="isekai-bottom-nav-btn-label",a.innerText=null!==(r=t.label)&&void 0!==r?r:"",o.appendChild(a)}t.onClick&&o.addEventListener("click",t.onClick);for(var l=h(h({},t),{},{element:o,proiorty:null!==(e=t.priority)&&void 0!==e?e:0}),s=null,u=0,c=this.btnList.length-1;c>=0&&l.priority<this.btnList[c].priority;c--)s=this.btnList[c].element,u=c;return s?(this.bottomNavElem.insertBefore(o,s),this.btnList=[].concat(k(this.btnList.slice(0,u)),[l],k(this.btnList.slice(u)))):(this.bottomNavElem.append(o),this.btnList.push(l)),o}},{key:"removeButton",value:function(t){var e="";"string"==typeof t?e=t:"object"===w(t)&&(e=t.id);var n=this.bottomNavElem.querySelector('.isekai-bottom-nav-btn[data-id="'.concat(e,'"]'));n&&n.remove()}}])&&j(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();t("ui.ContextMenuWidget",l),t("ui.FabWidget",y),t("ui.BottomNavWidget",S),t("fab",new y),t("bottomNav",new S)})();