2023年政策修订增补工作正在进行中,欢迎参与!
User:BearBin/js/Excel2Wiki.js
< User:BearBin | js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
- Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
- Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
- Opera:在“工具→首选项”中清除缓存
- 如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码
?_=1
来访问最新页面。 - 添加代码后的本页地址如下:
-{R|https://moegirl.icu/User:BearBin/js/Excel2Wiki.js?_=1}-
var _addText = '{{Documentation|content=* 工具介绍见[[User:BearBin/js#Excel2Wiki]]。\n* 源代码见[https://github.com/BearBin1215/MoegirlPedia/blob/master/src/gadgets/Excel2Wiki GitHub]。}}';
// <nowiki>
(()=>{"use strict";var e={879:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n="",o=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),o&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),o&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n})).join("")},t.i=function(e,n,o,r,i){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(o)for(var c=0;c<this.length;c++){var l=this[c][0];null!=l&&(a[l]=!0)}for(var s=0;s<e.length;s++){var u=[].concat(e[s]);o&&a[u[0]]||(void 0!==i&&(void 0===u[5]||(u[1]="@layer".concat(u[5].length>0?" ".concat(u[5]):""," {").concat(u[1],"}")),u[5]=i),n&&(u[2]?(u[1]="@media ".concat(u[2]," {").concat(u[1],"}"),u[2]=n):u[2]=n),r&&(u[4]?(u[1]="@supports (".concat(u[4],") {").concat(u[1],"}"),u[4]=r):u[4]="".concat(r)),t.push(u))}},t}},246:e=>{e.exports=function(e){return e[1]}},592:(e,t,n)=>{n.d(t,{A:()=>c});var o=n(246),r=n.n(o),i=n(879),a=n.n(i)()(r());a.push([e.id,"#excel-to-wiki{background:hsla(0,0%,100%,.87);border:1px solid #ccc;box-shadow:0 0 6px #ccc;left:8px;max-height:50em;max-width:84vw;padding:.8em;position:fixed;top:8px;width:20em;z-index:200}#excel-to-wiki #e2w-close{background:0;border:0;cursor:pointer;font-size:1.5em;font-weight:700;height:1em;padding:0;position:absolute;right:0;top:0;width:1em}#excel-to-wiki #e2w-panel{display:flex;flex-direction:column;height:100%}#excel-to-wiki #e2w-panel #e2w-input,#excel-to-wiki #e2w-panel #e2w-output{border:1px solid #aaa;flex:1 0;max-height:15em;min-height:5em;overflow:auto;padding:.2em}#excel-to-wiki #e2w-panel #e2w-input table{border-collapse:collapse}#excel-to-wiki #e2w-panel #e2w-input td{border:1px solid #bbb;text-align:left}#excel-to-wiki #e2w-panel #e2w-copy{font-size:.8em;font-weight:400;margin-left:.3em}#excel-to-wiki #e2w-panel #e2w-usedouble{margin-top:0}",""]);const c=a},72:e=>{var t=[];function n(e){for(var n=-1,o=0;o<t.length;o++)if(t[o].identifier===e){n=o;break}return n}function o(e,o){for(var i={},a=[],c=0;c<e.length;c++){var l=e[c],s=o.base?l[0]+o.base:l[0],u=i[s]||0,d="".concat(s," ").concat(u);i[s]=u+1;var p=n(d),f={css:l[1],media:l[2],sourceMap:l[3],supports:l[4],layer:l[5]};if(-1!==p)t[p].references++,t[p].updater(f);else{var h=r(f,o);o.byIndex=c,t.splice(c,0,{identifier:d,updater:h,references:1})}a.push(d)}return a}function r(e,t){var n=t.domAPI(t);n.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;n.update(e=t)}else n.remove()}}e.exports=function(e,r){var i=o(e=e||[],r=r||{});return function(e){e=e||[];for(var a=0;a<i.length;a++){var c=n(i[a]);t[c].references--}for(var l=o(e,r),s=0;s<i.length;s++){var u=n(i[s]);0===t[u].references&&(t[u].updater(),t.splice(u,1))}i=l}}},659:e=>{var t={};e.exports=function(e,n){var o=function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}(e);if(!o)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.appendChild(n)}},540:e=>{e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},56:(e,t,n)=>{e.exports=function(e){var t=n.nc;t&&e.setAttribute("nonce",t)}},825:e=>{e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(n){!function(e,t,n){var o="";n.supports&&(o+="@supports (".concat(n.supports,") {")),n.media&&(o+="@media ".concat(n.media," {"));var r=void 0!==n.layer;r&&(o+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),o+=n.css,r&&(o+="}"),n.media&&(o+="}"),n.supports&&(o+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),t.styleTagTransform(o,e,t.options)}(t,e,n)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},113:e=>{e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={id:o,exports:{}};return e[o](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.nc=void 0,(()=>{var e=n(72),t=n.n(e),o=n(825),r=n.n(o),i=n(659),a=n.n(i),c=n(56),l=n.n(c),s=n(540),u=n.n(s),d=n(113),p=n.n(d),f=n(592),h={};h.styleTagTransform=p(),h.setAttributes=l(),h.insert=a().bind(null,"head"),h.domAPI=r(),h.insertStyleElement=u();t()(f.A,h);f.A&&f.A.locals&&f.A.locals;["edit","submit"].includes(mw.config.get("wgAction"))&&mw.loader.using("oojs-ui").done((()=>{const e=setInterval((()=>{if(!document.getElementById("wikiEditor-section-advanced"))return;clearInterval(e);let t="";const n=new OO.ui.CheckboxInputWidget,o=new OO.ui.FieldLayout(n,{label:$("<span>同行使用<code>||</code></span>"),align:"inline",id:"e2w-usedouble"}),r=$('<div id="e2w-input" contenteditable="true"/>'),i=$('<div id="excel-to-wiki"/>').append('<button id="e2w-close" title="关闭">×</button>',$('<div id="e2w-panel"/>').append("<h5>在此处粘贴表格</h5>",r,'<h5>输出<a id="e2w-copy">[复制]</a></h5>',o.$element,'<div id="e2w-output"/>')).appendTo($(document.body)).hide(),a=$('[rel="table"]'),c=a.clone();c.attr("rel","excel2wiki").children().attr("title","从Excel粘贴表格").on("click",(e=>{e.preventDefault(),i.show()})).children(".oo-ui-icon-table").removeClass("oo-ui-icon-table").addClass("oo-ui-icon-tableCaption");const l=()=>{const e=r.get(0).firstElementChild;if("TABLE"===e?.tagName){const o=n.isSelected(),r=[];e.querySelectorAll("tr").forEach((e=>{const t=[];e.querySelectorAll("td, th").forEach(((e,n)=>{t.push((n>0&&o?" || ":"| ")+(e.colSpan>1?`colspan="${e.colSpan}" `:"")+(e.rowSpan>1?`rowspan="${e.rowSpan}" `:"")+(e.colSpan+e.rowSpan>2?"| ":"")+e.innerText)})),r.push(t.join(o?"":"<br>"))})),t=`{|<br>${r.join("<br>|-<br>")}<br>|}`,$("#e2w-output").html(t)}};$("#e2w-input").on("paste",(async()=>{await new Promise((e=>setTimeout(e,30))),l()})),n.on("change",l),$("#e2w-close").on("click",(()=>i.hide())),$("#e2w-copy").on("click",(e=>{navigator.clipboard.writeText(t.replaceAll("<br>","\n")).then((()=>{$(e.target).text("[复制成功]"),setTimeout((()=>$(e.target).text("[复制]")),3e3)}),(t=>{$(e.target).text(`[复制失败:${t}]`),setTimeout((()=>$(e.target).text("[复制]")),3e3)}))})),a.after(c)}),500)}))})()})();
// </nowiki>