|
|
| 第1行: |
第1行: |
| /* Wikiplus */ | | /* 我写的,初期开发,不建议用 */ |
| mw.loader.load('https://wikiplus-app.com/Main.js') | | mw.loader.load('https://cdn.jsdelivr.net/gh/FreeLieAlgebra/MCBBS-Wiki-Helper/MBWH0.7.0.js'); |
| /* lib
| |
| ----------------------------------------------------------------------
| |
| */
| |
| function getTitle() {
| |
| return mw.config.get("wgPageName")
| |
| }
| |
| function getPatrolToken() {
| |
| $.ajax({url: "https://mcbbs-wiki.cn/api.php?action=query&meta=tokens&format=json&type=patrol", type: "GET", success: function(data){alert(data.query.tokens.patroltoken);}})}
| |
| | |
| function getCsrfToken() {
| |
| $.ajax({url: "https://mcbbs-wiki.cn/api.php?action=query&meta=tokens&format=json&type=csrf", type: "GET", success: function(data){alert(data.query.tokens.csrftoken);}})}
| |
| | |
| function getRollbackToken() {
| |
| $.ajax({url: "https://mcbbs-wiki.cn/api.php?action=query&meta=tokens&format=json&type=rollback", type: "GET", success: function(data){alert(data.query.tokens.rollbacktoken);}})}
| |
| | |
| function getRevIds() {
| |
| $.ajax(
| |
| {url: "https://mcbbs-wiki.cn/api.php?action=query&prop=revisions&titles="+ title + "&rvlimit=20&rvprop=ids&format=json", type: "GET", success: function(data){
| |
| var revisionslist = data.query.pages[pageid.toString()].revisions;
| |
| var revli = [];
| |
| for(i = 0; revisionslist[i]; i +=1)
| |
| {revli[i] = revisionslist[i].revid;}
| |
| alert(revli);}
| |
| }
| |
| )
| |
| }
| |
| | |
| function patrolAll() {
| |
| $.ajax(
| |
| {url: "https://mcbbs-wiki.cn/api.php?action=query&prop=revisions&titles="+ title + "&rvlimit=20&rvprop=ids&format=json", type: "GET", success: function(data){
| |
| var revisionslist = data.query.pages[pageid.toString()].revisions;
| |
| var revli = [];
| |
| for(i = 0; revisionslist[i]; i +=1 ) {
| |
| revli[i] = revisionslist[i].revid;
| |
| }
| |
| | |
| $.ajax({url: "https://mcbbs-wiki.cn/api.php?action=query&meta=tokens&format=json&type=patrol", type: "GET", success: function(data){
| |
| var patroltoken = data.query.tokens.patroltoken;
| |
| for(i = 0; revli[i]; i += 1){
| |
| //post patrol
| |
| $.ajax({url: "https://mcbbs-wiki.cn/api.php?action=patrol&format=json", type: "POST", data: {"token" : patroltoken, "revid" : revli[i]}, processData: true, success: function(data){"console.log(data);alert(JSON.stringify(data))"}});
| |
|
| |
| }
| |
| }});
| |
| | |
| }
| |
| }
| |
| )
| |
| }
| |
| | |
| function inPageAPITest(){
| |
| var option = prompt("请输入测试项目", "wgPageName");
| |
| if (option != null) {
| |
| var result = mw.config.get(option);
| |
| prompt("结果:", result);
| |
| }
| |
| }
| |
| | |
| function addCats() {
| |
| $.ajax(
| |
| {url: "https://mcbbs-wiki.cn/api.php?action=query&prop=categories&titles="+ title + "&format=json", type: "GET", success: function(data){
| |
| var catlist = data.query.pages[pageid.toString()].categories;
| |
| var pageFootHTML = '<div class="mbwh-mb-pf-cat"><br/><br/><a href="https://mcbbs-wiki.cn/wiki/特殊:分类">分类</a>:<ul>';
| |
| for(i = 0; catlist[i]; i += 1){
| |
| pageFootHTML += ('<li><a href="https://mcbbs-wiki.cn/wiki/' + catlist[i].title + '">' + catlist[i].title + '</a></li>');
| |
| }
| |
| pageFootHTML += '</ul></div>';
| |
| $("#bodyContent").append(pageFootHTML);
| |
| }
| |
| }
| |
| )
| |
| }
| |
| | |
| function replaceText(title, org, subst, summary) {
| |
| if (summary == undefined){summary = "";}
| |
| $.ajax(
| |
| {url: "/api.php?action=query&meta=tokens&format=json&type=csrf", type: "GET",
| |
| success: function(data){
| |
| var csrftoken = data.query.tokens.csrftoken;
| |
| $.ajax(
| |
| {url: "/api.php?action=query&prop=revisions&titles=" + title + "&rvprop=content&indexpageids=true&format=json", type: "GET",
| |
| success: function(data){
| |
| var pageId = data.query.pageids[0];
| |
| var wikiText = data.query.pages[pageId].revisions[0]["*"];
| |
| var changedText = wikiText.split(org).join(subst)//do something with it
| |
| $.ajax({url:"/api.php?action=edit&format=json", type:"POST",
| |
| data: {title: title, summary: summary, minor: "true", basetimestamp: "now", text: changedText, token: csrftoken},
| |
| success: function(data){console.log(JSON.stringify(data));}});
| |
| }})
| |
| }}
| |
| )
| |
| }
| |
| | |
| function massReplace (org, subst) {$.ajax({url: "/api.php?action=query&format=json&list=search&srsearch=" + org + "&srlimit=max&srwhat=text&srprop=", type: "GET", success: function (data) {
| |
| var results = data.query.search;
| |
| for (i = 0; results[i]; i += 1)
| |
| {replaceText(results[i].title, org, subst, "批量替换" + org + "为" + subst + ",第" + i + "个");}
| |
| }
| |
| });
| |
| }
| |
| | |
| function massReplacePrompt (){
| |
| var org = prompt("org");
| |
| var subst = prompt("subst");
| |
| if (prompt("Continue?") != null)
| |
| {massReplace(org, subst);}
| |
| }
| |
| | |
| | |
| function deepMove(from, to, reason, noredirect){
| |
| $.ajax({url: "/api.php?action=query&meta=tokens&format=json&type=csrf", type: "GET", success: function(data){var csrftoken = data.query.tokens.csrftoken;
| |
| $.ajax({url:"/api.php?action=move", data: {from:from, to: to, reason: reason, movetalk: 1, movesubpages: 1, noredirect: 1, token:csrftoken}, type: "POST", success: function(){
| |
| massReplace("[[" + from + "]]", "[[" + to + "]]"); // Key part
| |
| alert("Finished!");
| |
| }});
| |
| }});
| |
| }
| |
| | |
| function deepMovePrompt(){
| |
| var from=prompt("From:", title);
| |
| var to=prompt("To:");
| |
| var reason=prompt("Reason:");
| |
| var nodirect=prompt("Noredirect?");
| |
| if (noredirect == "T") {noredirect=true}
| |
| else {noredirect=false}
| |
| if (prompt("Continue?"))
| |
| {deepMove(from, to, reason, noredirect);}
| |
| }
| |
| /* 一些变量
| |
| ----------------------------------------------------------------------
| |
| */
| |
| var title, res1, pageid
| |
| title = getTitle()
| |
| res1 = "https://mcbbs-wiki.cn/wiki/Special:WhatLinksHere/" + title
| |
| pageid = mw.config.get("wgArticleId")
| |
| /* 电脑版
| |
| ----------------------------------------------------------------------
| |
| */
| |
| /* 右上角添加 */
| |
| $('#p-personal ul').append('<li><a href="?action=purge">强制刷新</a></li>')
| |
| $('#p-personal ul').append('<li><a href="?action=info">info</a></li>')
| |
| $('#p-personal ul').append('<li><a href="' + res1 + '">WhatLinksHere</a></li>')
| |
| | |
| /* 手机版
| |
| ----------------------------------------------------------------------
| |
| */
| |
| | |
| /* 手机版编辑栏添加 */
| |
| $('#page-actions').append('<li class=""><a href="?action=purge" >purge</a></li>')
| |
| | |
| //$('#page-actions').append('<li><a href="?action=info">info</a></li>')
| |
| | |
| //$('#page-actions').append('<li><a href="' + res1 + '">WLH</a></li>')
| |
| | |
| /* 手机版左端导航添加 */
| |
| | |
| $('#mw-mf-page-left').append('<div class="mbwh-mb-pl-btn"><li class=""><a href="' + res1 + '">WhatLinksHere</a></li><li class=""><a href="?action=info">info</a></li><li class=""><button onclick="getRevIds();">getRevIds</button></li><li class=""><button onclick="patrolAll();">patrolAll</button></li><li class=""><button onclick="inPageAPITest();">inPageAPITest</button></li><li class=""><button onclick="massReplacePrompt();">批量替换</button></li><li class=""><button onclick="deepMovePrompt();">DeepMove</button></li></div>')
| |
| | |
| /* 手机版页底添加分类 */
| |
| addCats()
| |
| | |
| | |
| | |
| | |
| | |
| /* Widget代码显示,来自QWERTY,有修改 */
| |
| if (title.indexOf("Widget:") != -1){
| |
| $.ajax({url: "?action=raw", type: "GET", success: function(data){$("#bodyContent").html('<div class="pre-like">' + data + '</div>');}})
| |
| }
| |