全站通知:

用户:33961147/snippets

来自bilibili游戏中心 - WIKI
跳到导航 跳到搜索
$(".new").each(function(){
    // 强制显示受损链接、受损文件链接的DOM节点,方便定位到具体链接、文件
    var pNodes = $(this).parents();
    for(var i in pNodes){
        if(pNodes.eq(i).css("display") === 'none')
            pNodes.eq(i).css("display","inline-block")
    }
})
// 当上传重复文件遇到警告时,可强制全选
$(".file-warning [type='checkbox']").click()
// 沙盒请求img信息
https://wiki.biligame.com/ys/%E7%89%B9%E6%AE%8A:ApiSandbox#action=query&format=json&prop=imageinfo&titles=File%3AXianglingSHUI.png&iiprop=timestamp%7Cuser%7Curl
// 返回用户id 
(document.cookie.match(/DedeUserID=([^;]+)/) || [])[1] || ""

// 返回用户昵称,UserStatus的数据为单独请求获取,id有缓存不能用,要用用cookie
UserStatus.userInfo.uname
// 返回页面分类,UserStatus的数据为单独请求获取
mw.config.get("wgCategories")
// 子页面
{{Special:PrefixIndex/{{FULLPAGENAME}}/|stripprefix=1}}
// 查看队列数量
../api.php?action=query&meta=siteinfo&siprop=statistics
</syntaxhighlight>
// 刷新分类页面 // 已整合到bikit
function purge(){
	window.titleArray = titles.replace(", ", ",").split(",")
	window.pageIndex = 0
	new mw.Api().post({
		"action": "purge",
		"format": "json",
		"titles": titleArray.join("|")
	}).then( getPage )
}
function getPage(){
	if(pageIndex >= titleArray.length) return alert("刷新完毕")
	$.get(mw.config.get("wgCookiePath") + titleArray[pageIndex++])
	setTimeout(getPage, 500)
}
var titles = [];
$(".mw-category a").each(function(){titles.push($(this).attr("title"))})
titles = titles.join(",")
purge()
// 确定上传重复文件
$(".file [type=checkbox]").click()
// 取消上传重复文件
$(".file [type=checkbox]").each(function(){$(this).parents(".file").children().eq(0).click()})


// excel转二维数组
excel = `以爱之名		
荆棘玫瑰		
跃动音符		
靡靡之音		
奢华晚宴	跃动音符	奢华晚宴
破阵曲	靡靡之音	
破阵曲	奢华晚宴	
奢华晚宴	破阵曲	以爱之名
`
console.log(arr = "[[\""+excel.replace(/\n$/g, "").replace(/(\t)+\n|\n/g,"\"],\n[\"").replace(/(\t)+/g,"\",\"") + "\"]]")
console.log(json = JSON.parse("[[\""+excel.replace(/\n$/g, "").replace(/(\t)+\n|\n/g,"\"],\n[\"").replace(/(\t)+/g,"\",\"") + "\"]]"))


>> [["以爱之名"],
["荆棘玫瑰"],
["跃动音符"],
["靡靡之音"],
["奢华晚宴","跃动音符","奢华晚宴"],
["破阵曲","靡靡之音"],
["破阵曲","奢华晚宴"],
["奢华晚宴","破阵曲","以爱之名"]]
>> (8) [Array(1), Array(1), Array(1), Array(1), Array(3), Array(2), Array(2), Array(3)]


// 避免模板内css或js重复加载
{{#if:{{#varexists:防止多次加载JS}}||{{#vardefineecho:防止多次加载JS|{{JS|PlotOptions}}}}}}
// 获取链入页面的页面名
var a = []; $("#mw-whatlinkshere-list li >a").each(function(){a.push($(this).attr("title"))}); console.log(a.join("、"))
var csv = test_array.map(function(d){
    return d.join();
}).join('\n');
<includeonly></includeonly><noinclude>{{#widget:{{PAGENAME}}}}</noinclude>
(window.RLQ = window.RLQ || []).push(['jquery', () => {
     $(function(){....})
}]);
// 下面的废掉咯
<script>(function () { var t = function () { window.jQuery && window.mw && window.mw.loader ? $tab() : window.setTimeout(t, 100); }; t();  })();</script>
{{#vardefine: index | 1 }}{{#while: | {{#if: {{{ {{#var: index }}| }}} | true }} | 
<!-- 输出参数值 {{{ {{#var: paramindex }} }}} -->
{{#vardefine: index | {{#expr: {{#var: index }} + 1 }} }} }}
// 删除common.css样式
$("link[href*='modules=site.styles']").remove()
// 批量替换
titles = "祈祷之音·珍稀、祈祷之音·华丽、祈祷之音";
titles = titles.split("、");
index = 0;
edit()

function edit(){
    if(!titles[index]) return alert("处理结束");
    new mw.Api().edit(
        titles[index++],
        function (revision) {
            submitData = revision.content.replace(/(\|名称=[^ ]+) ([^\n]+\n)/g, "$1\n|英文名称=$2")
            return {
                text: submitData,
                summary: "分离英文名称",
                minor: true,
                tags: 'apiedit'
            };
        }
    ).then(function () {
        edit();
    }).catch(function (e) {
        
    });
}
// 修复换皮肤导致的无法访问,在其他wiki保持登录状态后控制台执行,ys换成坏掉的wiki
$.post("https://wiki.biligame.com/ys/api.php?action=query&meta=tokens&format=json").then(function(data){
    $.post("https://wiki.biligame.com/ys/api.php",{
    	"action": "options",
    	"format": "json",
    	"optionname": "skin",
    	"optionvalue": "vector",
       "token":data.query.tokens.csrftoken
    });
});
// new mw.Api().saveOption(name, value)
// 或可通过修改url参数来通过默认皮肤的预览模式进行恢复
在被排序的属性页面(属性:xxx),加上
[[Has type::Number]]

保存后需要等队列刷新,批量刷新或可加快队列执行过程,被队列处理过的页面数据会被清空,需要重新purge后恢复正常
 


// 炸站之后清空sidebar以恢复正常
// 炸站原因:写script标签,写不配对的html注释符号
new mw.Api().edit(
        "mediawiki:sidebar",
        function (revision) {
            return {
                text: "",
                summary: "重置sidebar",
                minor: true
            };
        }
    )

common.js
/* == 加载Bikit == */
try { mw.loader.load('//wiki.biligame.com/wiki/MediaWiki:Bikit.js?action=raw&ctype=text/javascript');} catch(e) {}
/* -- 加载Bikit -- */


模板
<div class="bikit-audio" data-src="{{filepath:{{{1}}}.mp3}}" data-mode="default"></div>


// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
// 表单提交
const url = '/wiki/api.php';
const data = new FormData();
data.append('action', 'parse');
data.append('format', 'json');
data.append('text', '{{黑幕|123}}');
data.append('contentmodel', 'wikitext');

fetch(url, {
  method: 'POST',
  body: data,
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));


// 转换参数
const url = '/wiki/api.php';
const data = {
    	"action": "parse",
    	"format": "json",
    	"text": "{{黑幕|123}}",
    	"contentmodel": "wikitext"
};

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  },
  body: new URLSearchParams(data).toString(),
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));


// 给卧龙凤雏清sidebar MediaWiki:Sidebar?action=raw
const url = '/yyzy/api.php';

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  },
  body: new URLSearchParams({
    "action": "query",
    "format": "json",
    "meta": "tokens",
    "formatjson": "2"
  }).toString(),
})
  .then((response) => response.json())
  .then((data) => {
    console.log(data.query.tokens.csrftoken)
    fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      body: new URLSearchParams({
        "action": "edit",
        "format": "json",
        "title": "mediawiki:sidebar",
        "text": "",
        "token": data.query.tokens.csrftoken
      }).toString(),
    })
      .then((response) => response.json())
      .then((data) => console.log(data))

  })