2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

User:BearBin/js/BulkMove.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/BulkMove.js?_=1}-
文档  [编辑]
var _addText = '{{Documentation|content=* 工具介绍见[[User:BearBin/js#BulkMove]]。\n* 源代码见[https://github.com/BearBin1215/MoegirlPedia/blob/master/src/gadgets/BulkMove GitHub]。}}';

// <nowiki>

(()=>{"use strict";var e={411:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o="",n=void 0!==t[5];return t[4]&&(o+="@supports (".concat(t[4],") {")),t[2]&&(o+="@media ".concat(t[2]," {")),n&&(o+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),o+=e(t),n&&(o+="}"),t[2]&&(o+="}"),t[4]&&(o+="}"),o})).join("")},t.i=function(e,o,n,i,r){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(n)for(var l=0;l<this.length;l++){var s=this[l][0];null!=s&&(a[s]=!0)}for(var c=0;c<e.length;c++){var d=[].concat(e[c]);n&&a[d[0]]||(void 0!==r&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=r),o&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=o):d[2]=o),i&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=i):d[4]="".concat(i)),t.push(d))}},t}},922:e=>{e.exports=function(e){return e[1]}},197:(e,t,o)=>{o.d(t,{A:()=>l});var n=o(922),i=o.n(n),r=o(411),a=o.n(r)()(i());a.push([e.id,".bearbintools-loger .loger-clear{font-size:.9em;font-weight:400;margin-left:.3em}.bearbintools-loger .loger-body{background:hsla(0,0%,100%,.7);border:1px solid #ccc;display:flow-root;padding:.3em}.bearbintools-loger .loger-filter{float:right;padding:.4em}.bearbintools-loger .loger-filter>div{border-radius:.3em;cursor:pointer;margin-bottom:.2em;padding-right:.2em}.bearbintools-loger .loger-filter>div.loger-filter-selected{background-color:hsla(0,0%,50%,.07)}.bearbintools-loger .loger-filter .loger-filter-icon{display:inline-block;height:1em;line-height:1em;text-align:center;width:1.2em}.bearbintools-loger .loger-lines{font-family:monospace;list-style:inside;max-height:20em;overflow-y:auto}.bearbintools-loger .loger-lines>li a{color:inherit;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}",""]);const l=a},472:(e,t,o)=>{o.d(t,{A:()=>l});var n=o(922),i=o.n(n),r=o(411),a=o.n(r)()(i());a.push([e.id,".rootpage-Special_BulkMove #firstHeading{align-items:flex-end;display:flex;flex-wrap:wrap;justify-content:space-between}.rootpage-Special_BulkMove #firstHeading>div{font-size:.6em}.rootpage-Special_BulkMove #bodyContent{padding-right:0!important}.rootpage-Special_BulkMove #bodyContent #mw-content-text h3{margin-bottom:0}.rootpage-Special_BulkMove #bodyContent #mw-content-text ul.bm-notelist{margin:.4em 0 0 1.6em}#bm-page-list-table{border-collapse:collapse;max-width:900px;width:100%}#bm-page-list-table tbody{counter-reset:row-counter}#bm-page-list-table tbody tr{counter-increment:row-counter}#bm-page-list-table tbody tr:before{content:counter(row-counter);display:table-cell;padding-right:.3em;text-align:center;vertical-align:middle;width:0}#bm-page-list-table tbody tr td{background-color:hsla(0,0%,100%,.7);border:1px solid #aaa;padding:0}#bm-page-list-table tbody tr td:last-child,#bm-page-list-table tbody tr th:last-child{background-color:transparent;background-position:50%;border:none;width:20px}#bm-page-list-table input[type=text]{background:transparent;border:none;border-radius:0;box-sizing:border-box;height:100%;padding:.4em;width:100%}#bm-page-list-table input[type=text]:focus{background-color:hsla(0,0%,50%,.02);outline:none}#bm-page-list-table #bm-add-row,#bm-page-list-table .remove-row{border-radius:50%;cursor:pointer;height:20px;transition:background-color .2s ease;width:20px}#bm-page-list-table #bm-add-row:hover,#bm-page-list-table .remove-row:hover{background-color:hsla(0,0%,50%,.2)}#bm-option{margin-top:.8em}#bm-option>div{margin-top:.3em}#bm-submit-panel{display:flex;gap:.1rem;margin-top:.8em}#bm-submit-panel #bm-interval{flex:0 0 5.5em}#bm-submit-panel #bm-summary{max-width:none}",""]);const l=a},960:e=>{var t=[];function o(e){for(var o=-1,n=0;n<t.length;n++)if(t[n].identifier===e){o=n;break}return o}function n(e,n){for(var r={},a=[],l=0;l<e.length;l++){var s=e[l],c=n.base?s[0]+n.base:s[0],d=r[c]||0,p="".concat(c," ").concat(d);r[c]=d+1;var u=o(p),m={css:s[1],media:s[2],sourceMap:s[3],supports:s[4],layer:s[5]};if(-1!==u)t[u].references++,t[u].updater(m);else{var g=i(m,n);n.byIndex=l,t.splice(l,0,{identifier:p,updater:g,references:1})}a.push(p)}return a}function i(e,t){var o=t.domAPI(t);o.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;o.update(e=t)}else o.remove()}}e.exports=function(e,i){var r=n(e=e||[],i=i||{});return function(e){e=e||[];for(var a=0;a<r.length;a++){var l=o(r[a]);t[l].references--}for(var s=n(e,i),c=0;c<r.length;c++){var d=o(r[c]);0===t[d].references&&(t[d].updater(),t.splice(d,1))}r=s}}},443:e=>{var t={};e.exports=function(e,o){var n=function(e){if(void 0===t[e]){var o=document.querySelector(e);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}t[e]=o}return t[e]}(e);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");n.appendChild(o)}},628:e=>{e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},120:(e,t,o)=>{e.exports=function(e){var t=o.nc;t&&e.setAttribute("nonce",t)}},81:e=>{e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(o){!function(e,t,o){var n="";o.supports&&(n+="@supports (".concat(o.supports,") {")),o.media&&(n+="@media ".concat(o.media," {"));var i=void 0!==o.layer;i&&(n+="@layer".concat(o.layer.length>0?" ".concat(o.layer):""," {")),n+=o.css,i&&(n+="}"),o.media&&(n+="}"),o.supports&&(n+="}");var r=o.sourceMap;r&&"undefined"!=typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),t.styleTagTransform(n,e,t.options)}(t,e,o)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},849: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 o(n){var i=t[n];if(void 0!==i)return i.exports;var r=t[n]={id:n,exports:{}};return e[n](r,r.exports,o),r.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.nc=void 0,(()=>{const e=e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.children[0]};var t=o(960),n=o.n(t),i=o(81),r=o.n(i),a=o(443),l=o.n(a),s=o(120),c=o.n(s),d=o(628),p=o.n(d),u=o(849),m=o.n(u),g=o(197),b={};b.styleTagTransform=m(),b.setAttributes=c(),b.insert=l().bind(null,"head"),b.domAPI=r(),b.insertStyleElement=p();n()(g.A,b);g.A&&g.A.locals&&g.A.locals;class h{_logTypes={success:{icon:"✓",color:"#333",text:"完成"},warn:{icon:"!",color:"#f28500",text:"警告"},error:{icon:"✕",color:"#eb3941",text:"出错"}};element;headline;body=e('<div class="loger-body"></div>');logerLines=e('<ul class="loger-lines"></ul>');logDetails=[];filterButtons={};constructor(t=[],o="",n="h3"){t.length>0&&(this._logTypes=t.reduce(((e,{name:t,icon:o,color:n,text:i})=>(e[t]={icon:o,color:n,text:i},e)),{}));for(const e in this._logTypes)this._logTypes[e].show=!0;this.headline=e(`<${n} class="loger-headline"></${n}>`);const i=e('<a class="loger-clear">[清空]</a>');i.addEventListener("click",this.clear.bind(this));const r=e('<nav class="loger-filter"></nav>');for(const[t,{icon:o,color:n,text:i}]of Object.entries(this._logTypes)){const a=e(`<div class="loger-filter-selected loger-${t}" style="color:${n}"></div>`),l=e('<span class="loger-filter-icon"></span>');l.append(o);const s=e('<span class="loger-filter-count">0</span>');a.append(l,s,` ${i}`),a.addEventListener("click",(()=>{this._logTypes[t].show?(a.classList.remove("loger-filter-selected"),this.logerLines.classList.add(`loger-${t}-hidden`),this.logDetails.filter((e=>e.type===t)).forEach((e=>{e.element.style.display="none"})),this._logTypes[t].show=!1):(a.classList.add("loger-filter-selected"),this.logerLines.classList.remove(`loger-${t}-hidden`),this.logDetails.filter((e=>e.type===t)).forEach((e=>{e.element.style.display=""})),this._logTypes[t].show=!0)})),this.filterButtons[t]={button:a,countElement:s},r.appendChild(a)}this.element=e(`<div class="bearbintools-loger" id="${o||""}"></div>`),this.headline.append("日志",i),this.body.append(r,this.logerLines),this.element.append(this.headline,this.body)}record(e,t="normal",o=(new Date).toLocaleTimeString()){const n=document.createElement("li");return n.classList.add("loger-record",`loger-${t}`),n.innerHTML=`${o} - ${e}`,n.style.color=this._logTypes[t]?.color||"#222",!1===this._logTypes[t]?.show&&(n.style.display="none"),this.logerLines.appendChild(n),this.logerLines.scrollTop=this.logerLines.scrollHeight,this.logDetails.push({element:n,type:t}),this.filterButtons[t]&&(this.filterButtons[t].countElement.innerText=String(+this.filterButtons[t].countElement.innerText+1)),n}clear(){this.logDetails.length=0,this.logerLines.innerHTML="";for(const e in this.filterButtons)this.filterButtons[e].countElement.innerText="0"}}const f=e=>new Promise((t=>setTimeout(t,e)));var v=o(472),w={};w.styleTagTransform=m(),w.setAttributes=c(),w.insert=l().bind(null,"head"),w.domAPI=r(),w.insertStyleElement=p();n()(v.A,w);v.A&&v.A.locals&&v.A.locals;$((()=>(async()=>{if("Special:BulkMove"!==mw.config.get("wgPageName"))return await mw.loader.using(["mediawiki.util"]),void mw.util.addPortletLink("p-tb","/Special:BulkMove","批量移动","t-bulkmove");await mw.loader.using(["mediawiki.api","oojs-ui","mediawiki.user"]);const e=new mw.Api,t=new h;let o=0;mw.config.set("wgCanonicalSpecialPageName","BulkMove"),document.title="批量移动 - 萌娘百科_万物皆可萌的百科全书",$(".mw-invalidspecialpage").removeClass("mw-invalidspecialpage"),$("#firstHeading").html("批量移动页面<div>By BearBin</div>"),$("#contentSub").remove();const n=$('<table id="bm-page-list-table">'),i=$("<tbody>"),r=$('<th><div class="oo-ui-icon-add" id="bm-add-row" title="新增一行"></div></th>'),a=new OO.ui.CheckboxInputWidget({id:"bm-movetalk-box",selected:!0}),l=new OO.ui.FieldLayout(a,{label:"移动关联的讨论页",align:"inline"}),s=new OO.ui.CheckboxInputWidget({id:"bm-redirect-box"}),c=new OO.ui.FieldLayout(s,{label:"保留重定向",align:"inline"}),d=new OO.ui.CheckboxInputWidget({id:"bm-watchlist-box"}),p=new OO.ui.FieldLayout(d,{label:"监视源页面和目标页面",align:"inline"}),u=new OO.ui.CheckboxInputWidget({id:"bm-watchlist-box"}),m=new OO.ui.FieldLayout(u,{label:"移动子页面",align:"inline"}),g=new OO.ui.ButtonWidget({label:"提交",flags:["primary","progressive"],icon:"check"}),b=new OO.ui.TextInputWidget({type:"number",placeholder:"操作间隔",id:"bm-interval"}),v=new OO.ui.TextInputWidget({placeholder:"附加摘要",id:"bm-reason",name:"wpReason"}),w=(e=1)=>{for(let t=0;t<e;t++)o++,i.append($("<tr>").append($(`<td><input type="text" data-row-no="${o}" data-col-no="1" name="${o}-1"></td>`)).append($(`<td><input type="text" data-row-no="${o}" data-col-no="2" name="${o}-2"></td>`)).append($('<td><div class="remove-row oo-ui-icon-subtract" title="删除此行"></div></td>')))};$("#mw-content-text").empty().append("<h3>页面列表</h3>",n.append($("<thead>").append($("<tr>").append("<th></th>","<th>源页面</th>","<th>目标页面</th>",r)),i),$('<ul class="bm-notelist">').append("<li>请输入要移动的页面列表及目标页面,一一对应。</li>","<li>点击右上角“+”添加更多行。</li>","<li>可直接从Excel复制(部分浏览器可能不支持)。粘贴时浏览器可能会需要获取权限,请注意是否有提醒。</li>"),$('<div id="bm-option">').append(l.$element,c.$element,p.$element,m.$element),$('<div id="bm-submit-panel">').append(g.$element,b.$element,v.$element),$('<ul class="bm-notelist">').append("<li>操作间隔单位为秒(s),不填默认为0。不包含本身移动页面所用的服务器响应时间。</li>",'<li>请注意<a target="_blank" href="/萌娘百科:机器用户">机器用户方针</a>所规定的速率和<a target="_blank" href="/api.php?action=query&meta=userinfo&uiprop=ratelimits">ratelimit限制</a>并自行设置间隔,或申请机器用户权限。</li>'),t.element),w(10),mw.user.getRights().done((e=>{e.includes("suppressredirect")||s.setSelected(!0).setDisabled(!0)})),r.on("click",(async()=>{const e=new OO.ui.TextInputWidget({type:"number",value:1});await OO.ui.confirm(e.$element,{title:"增加行"})&&w(+e.getValue())})),n.on("click",".remove-row",(({target:e})=>{o--,$(e).closest("tr").remove(),i.children("tr").each(((e,t)=>{$(t).find("input").attr("data-row-no",e+1)}))})),n.on("paste",'input[type="text"]',(e=>{navigator.clipboard.readText().then((t=>{if(t.indexOf("\t")>-1||t.indexOf("\n")>-1&&t.indexOf("\n")!==t.length-1){e.preventDefault();const o=t.split("\n"),i=n.find("input[data-row-no][data-col-no]");for(let t=0;t<o.length;t++){const n=o[t].split("\t");for(let o=0;o<2;o++)if(n[o]?.trim().length>0){const r=t+Number($(e.target).attr("data-row-no")),a=o+Number($(e.target).attr("data-col-no"));i.filter(`[data-row-no="${r}"][data-col-no="${a}"]`).val(n[o])}}}}))})),g.on("click",(async()=>{const o=$("<p>请确认您的移动是否有误。若因输入不当而产生错误,请自行<ruby><rb>承担后果</rb><rp>(</rp><rt>料理后事</rt><rp>)</rp></ruby>。</p>");if(await OO.ui.confirm(o,{title:"提醒",size:"small"})){g.setDisabled(!0),window.onbeforeunload=()=>!0,$("#mw-content-text input, #mw-content-text textarea").prop("disabled",!0);const o=a.isSelected(),n=!s.isSelected(),r=u.isSelected(),l=d.isSelected()?"watch":"unwatch",c=v.getValue().length>0?`[[User:BearBin/js#批量移动页面|BulkMove]]:${v.getValue()}`:"[[User:BearBin/js#批量移动页面|BulkMove]]",p=1e3*Number(b.getValue()),m=mw.config.get("wgUserGroups").includes("bot")?"bot":"Automation tool",h=[];i.children("tr").each(((e,t)=>{const o=$(t).find("input")[0].value,n=$(t).find("input")[1].value;o?.length>0&&n?.length>0&&h.push({from:o,to:n})})),h.length>0?t.record(`共${h.length}个页面,即将开始移动。`):t.record("没有要移动的页面。");for(const{from:i,to:a}of h)try{"move"in await e.postWithToken("csrf",{format:"json",action:"move",from:i,to:a,movetalk:o,noredirect:n,watchlist:l,movesubpages:r,reason:c,tags:m,bot:!0})&&(t.record(`移动【<a href="/${i}${n?"":"?redirect=no"}" class="${n?"":"mw-redirect"}">${i}</a>】→【<a href="/${a}">${a}</a>】成功。`,"success"),await f(p))}catch(e){if("moderation-move-queued"===e){t.record(`移动【<a href="/${i}${n?"":"?redirect=no"}" class="${n?"":"mw-redirect"}">${i}</a>】→【<a href="/${a}">${a}</a>】成功请求已发出,等待审核中。`,"success"),await f(p);continue}let o="";switch(e){case"missingtitle":o="源页面不存在";break;case"articleexists":o="目标页面已存在";break;case"http":o="网络连接出错";break;default:o=e}t.record(`移动【<a href="/${i}">${i}</a>】→【<a href="/${a}">${a}</a>】失败:${o}。`,"error")}t.record("移动完毕。"),g.setDisabled(!1),window.onbeforeunload=()=>null,$("#mw-content-text input, #mw-content-text textarea").prop("disabled",!1)}}))})()))})()})();

// </nowiki>