社区文档构建中,欢迎编辑。 社区答疑群(非官方):717421103,点点小课堂(腾讯会议):5696651544

全站通知:

批量添加/删除分类

阅读

    

2021-11-26更新

    

最新编辑:顾小满real

阅读:

  

更新日期:2021-11-26

  

最新编辑:顾小满real

来自WIKI实验室WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
页面贡献者 :
顾小满real

此模板为一键安装导入,不建议手动修改。

简单说明

版本:1.0

说明:用于给大量页面添加或者删除分类使用的]

安装方法

  • 自动安装:拥有站点管理员权限的同学可以在本页面使用一键安装功能
  • 手动安装:复制以下依赖页面中的内容到相同页面名称的页面中

依赖页面

<div class="form-group" style="max-width:500px"> <label for="titles">标题</label> <input id="titles" name="titles" class="form-control" placeholder="英文逗号或顿号分割"></input> </div> <div class="form-group" style="max-width:500px"> <label for="category">分类</label> <input id="category" name="category" class="form-control"></input> </div> 添加分类 移除分类 <div class="form-group" style="max-width:500px"> <label for="wikitext">wikitext</label> <input id="wikitext" name="wikitext" class="form-control"></input> </div> <div class="checkbox"> <label> <input id="isPrepend" type="checkbox"> 在页面内容之前插入 </label> </div> 添加wikitext <script> var lock = false; function editWikitext(mode){ if(lock) return false; else lock = true window.titleArray = $("#titles").val().replace(/、|,/g, ",").replace(/, /, ",").split(",") window.category = $("#wikitext").val() window.pageIndex = 0 window.editMode = mode getPage() } function editCategories(mode){ if(lock) return false; else lock = true window.titleArray = $("#titles").val().replace(/、|,/g, ",").replace(/, /, ",").split(",") window.category = "["+"[分类:" + $("#category").val() + "]]" window.pageIndex = 0 window.editMode = mode getPage() } function getPage(){ if(pageIndex >= titleArray.length){lock=false; return alert("刷新完毕")} var isPrepend = $("#isPrepend").prop("checked") new mw.Api().edit( titleArray[pageIndex++], function (revision) { var text = revision.content, hasCategory = text.indexOf(category) !== -1. if(editMode === "add" && hasCategory) { console.log(pageIndex-1, titleArray[pageIndex-1], "已有该分类,未操作") return text; } if(editMode === "add") { isPrepend ? text = category + "\n" + text : text += "\n" + category } else if(editMode === "remove") text = text.replace(category, "") return { text: text, summary: "批量修改分类", minor: true }; } ).then(function () { console.log(pageIndex-1, titleArray[pageIndex-1], "操作成功") $.get(mw.config.get("wgCookiePath") + titleArray[pageIndex-1]) setTimeout(getPage, 500) }).catch(function (e) { console.log(pageIndex-1, titleArray[pageIndex-1], "操作失败") setTimeout(getPage, 500) }); } </script>

使用说明

  1. Widget:分类 页面中将需要批量刷新的页面名称以逗号隔开
  2. 在分类输入框里输入希望添加或者移除的1个分类,点击新增或者移除分类按钮进行分类
  3. 一次添加多个分类,使用添加wikitext


作者

迦洛翎


更新日志

1.0