MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
Gadget:WikiEditorModify.js
"use strict";
//////////////////////////////////////////////////////////////
// Author: Salt //
// Function: 修改WikiEditor快速插入部分 //
// Describe: 修改WikiEditor快速插入部分 //
// 为了不污染全局命名空间,全部放进自执行函数里 //
// License: CC BY-NC-SA 4.0 //
// Special-Thanks: 绿色毛茸茸的WikiEditor文档 //
//////////////////////////////////////////////////////////////
// 注:绿色毛茸茸 是 Sheep_Realm
// 注2:我在想绵羊是先看到这段话还是先注意到我少写了一个 s
// 一些第一眼看上去奇怪的地方
// $('#wpTextbox1')
// 这个功能似乎和jQuery绑定
// $('#wpTextbox1').wikiEditor('addToToolbar',{sections:{}})
// 添加自定义的信息
// $('#wpTextbox1').wikiEditor('removeFromToolbar',{'section': 'insertion'})
// 删掉原有的插入信息
//var jQuery, mw; // 不然ts会报错
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
(function () {
var safe = 0;
var prefix = "[WikiEditor自动插入内容更改] ";
var a = setInterval(function () {
// safe: 安全开关
// 等待20s:
// mw.config.get() 存在
// jQuery('#wpTextbox1').wikiEditor() 存在
// 二次环境检测:
// 判断是不是在编辑或预览
if (typeof jQuery("#wpTextbox1").wikiEditor != "function" || typeof mw.config.get != "function") {
if (safe > 80) {
clearInterval(a);
} else {
safe++;
}
} else {
var mvConfig = mw.config.get("wgAction");
if (["edit", "submit"].indexOf(mvConfig) == -1) {
// 判断是不是在编辑或预览
console.log(prefix + "不是编辑页面");
} else {
setTimeout(wikiEditorModify, 0);
}
clearInterval(a);
}
}, 250);
function wikiEditorModify() {
var $ = void 0;
var sections, magicWord, adminTool;
//var myPage: page
var editor;
if (!envCheck()) {
return;
} // 检查环境
init(); // 初始化
main(); // 主过程
// 主过程
function main() {
editor.wikiEditor("removeFromToolbar", { section: "insertion" }); // 删掉原有的插入信息
addToToolbar("快速插入", "insertion", sections);
addToToolbar("魔术字", "magicword", magicWord);
//addToToolbar('管理员工具', 'admintool', adminTool); //给隔壁写的管理员工具不适用于BBSWiki
}
// 写入sections
function getData() {
sections = [
/*{
id: '',
disp: '',
spanbtns: [
{
disp: '',
tip: '',
wiki: '',
//$1: ''
},
]
},*/
{
id: "ihysgeui",
disp: "常用格式",
spanbtns: [{
disp: "正常换行",
tip: "两个连续换行",
wiki: "\n\n"
}, {
disp: "标签换行",
tip: "【不推荐】使用换行标签——慎用!",
wiki: "<br/>"
}, {
disp: "二级标题",
tip: "二级标题",
wiki: "== $1 ==",
$1: "二级标题"
}, {
disp: "三级标题",
tip: "三级标题",
wiki: "=== $1 ===",
$1: "三级标题"
}, {
disp: "四级标题",
tip: "四级标题",
wiki: "==== $1 ====",
$1: "四级标题"
}, {
disp: "置于中间",
tip: "将文字置于中间",
wiki: "<center>$1</center>",
$1: "置中文字"
}, {
disp: "删除线",
tip: "用删除线划去内容",
wiki: "<del>$1</del>",
$1: "被删除内容"
}, {
disp: "下划线",
tip: "用下划线标记内容",
wiki: "<u>$1</u>",
$1: "被标记内容"
// }, {
// disp: '等宽字体',
// tip: '【不推荐】使用等宽字体',
// wiki: '<samp>$1</samp>',
// $1: '等宽文字'
}, {
disp: "code语法标记",
tip: "用code标记代码内容",
wiki: "<code>$1</code>",
$1: "code"
}, {
disp: "nowiki标记",
tip: "用nowiki标记不解析内容",
wiki: "<nowiki>$1</nowiki>",
$1: "不解析"
}, {
disp: "pre语法标记",
tip: "用pre预格式化文本块",
wiki: "<pre>$1</pre>",
$1: "纯文本"
}, {
disp: "语法高亮",
tip: "用syntaxhighlight进行语法高亮",
wiki: "<syntaxhighlight>$1</syntaxhighlight>",
$1: "纯文本"
}, {
disp: "添加分类",
tip: "添加分类",
wiki: "[" + "[分类:$1]]",
$1: ""
}, {
disp: "内部链接",
tip: "添加连接到其他页面链接",
wiki: "[" + "[$1]]",
$1: "页面名"
}, {
disp: "外部链接",
tip: "添加连接到网页的链接,选中部分作为网址",
wiki: "[$1]",
$1: "https://网址"
}, {
disp: "外部链接+",
tip: "添加连接到网页的链接,选中部分作为网页说明",
wiki: "[https://网址 $1]",
$1: "网页说明"
}, {
disp: "直接插入图片",
tip: "直接插入一张图片",
wiki: "[" + "[文件:$1]]",
$1: "图片名.后缀名"
}, {
disp: "插入缩放图片",
tip: "插入一张图片宽高不超过256像素的图片",
wiki: "[" + "[文件:$1|256px]]",
$1: "图片名.后缀名"
}, {
disp: "插入缩略图/右",
tip: "插入一张右浮动的缩略图",
wiki: "[" + "[文件:$1|缩略图]]",
$1: "图片名.后缀名"
}, {
disp: "插入缩略图/居中",
tip: "插入一张居中的缩略图",
wiki: "[" + "[文件:$1|缩略图|居中]]",
$1: "图片名.后缀名"
}, {
disp: "插入缩略图/左",
tip: "插入一张左浮动的缩略图",
wiki: "[" + "[文件:$1|缩略图|左]]",
$1: "图片名.后缀名"
}, {
disp: "不显示在此页面",
tip: "里面的内容不显示在此页面",
wiki: "<includeonly>$1</includeonly>",
$1: "这里的内容将显示在调用这个页面的地方"
}, {
disp: "只显示在此页面",
tip: "里面的内容只显示在此页面",
wiki: "<noinclude>$1</noinclude>",
$1: "这里的内容不会显示在调用这个页面的地方"
}, {
disp: "添加注释",
tip: "使用HTML注释代码",
wiki: "<!-- $1 -->",
$1: "注释内容"
}]
}, {
id: "ihysmubj",
disp: "常用模板",
spanbtns: [{
disp: "颜色",
tip: "给文字添加颜色",
wiki: "{" + "{color|black|$1}}",
$1: "文字"
}, {
disp: "黑幕",
tip: "给文字添加一个黑幕",
wiki: "{" + "{黑幕|$1}}",
$1: ""
}, {
disp: "Ruby",
tip: "给文字添加注释",
wiki: "{" + "{ruby|$1|注释}}",
$1: "文字"
}, {
disp: "图标",
tip: "图标模板",
wiki: "{" + "{图标|$1}}",
$1: "物品名"
}, {
disp: "多图标",
tip: "图标模板的封装",
wiki: "{" + "{多图标|$1|物品2}}",
$1: "物品名"
// }, {
// disp: '图标lite',
// tip: '图标模板的轻量化版本',
// wiki: '{'+'{图标lite|$1}}',
// $1: '物品名'
// }, {
// disp: '多图标lite',
// tip: '图标模板轻量化版本的封装',
// wiki: '{'+'{多图标lite|$1|物品2}}',
// $1: '物品名'
}, {
disp: "同级子页面",
tip: "同父页面的其他子页面",
wiki: "{" + "{nbi|$1}}",
$1: "页面名"
}, {
disp: "多同级子页面",
tip: "nbi模板的封装",
wiki: "{" + "{mnbi|$1|页面名2}}",
$1: "页面名"
}, {
disp: "隐藏",
tip: "隐藏文字、图片等信息",
wiki: "{" + "{hide|标题=标题|内容=$1}}",
$1: "内容"
}, {
disp: "折叠",
tip: "折叠文字、图片等信息,需要填写一个不重复的id值",
wiki: "{" + "{折叠|标题=标题|id=<!--字母与数字-->|内容=$1}}",
$1: "内容"
}, {
disp: "模板",
tip: "以调用模板的格式来显示",
wiki: "{" + "{tl|$1}}",
$1: "模板"
}, {
disp: "参数",
tip: "以调用参数的格式来显示",
wiki: "{" + "{p|$1}}",
$1: "参数"
}]
}, {
id: "teuuzifu",
disp: "特殊字符",
spanbtns: [{
disp: "间隔符",
tip: "•",
wiki: "{" + "{w}}"
}, {
disp: "管道符",
tip: "",
wiki: "{" + "{!}}"
}, {
disp: "左尖括号",
tip: "< 可被解析",
wiki: "{" + "{《}}"
}, {
disp: "左尖括号+",
tip: "< 不可解析",
wiki: "<"
}, {
disp: "空格符",
tip: "一个普通的空格",
wiki: " "
}, {
disp: "等于号",
tip: "一个普通的等于号",
wiki: "{" + "{=}}"
}, {
disp: "方括号",
tip: "[]方括号包裹",
wiki: "[$1]",
$1: ""
}, {
disp: "花括号",
tip: "{" + "{}}双层花括号包裹",
wiki: "{" + "{$1}}",
$1: ""
}]
}];
magicWord = [
/*{
id: '',
disp: '',
spanbtns: [
{
disp: '',
tip: '',
wiki: '',
//$1: ''
},
]
},*/
{
id: "jxxihjuu",
disp: "解析器函数",
spanbtns: [{
disp: "相对路径",
tip: "指定页面的相对路径",
wiki: "{" + "{localurl:$1}}",
$1: "页面名称"
}, {
disp: "相对协议路径",
tip: "指定页面的相对协议路径",
wiki: "{" + "{fullurl:$1}}",
$1: "页面名称"
}, {
disp: "绝对协议路径",
tip: "指定页面的绝对协议路径",
wiki: "{" + "{canonicalurl:$1}}",
$1: "页面名称"
}, {
disp: "文件路径",
tip: "指定文件的绝对协议路径",
wiki: "{" + "{filepath:$1}}",
$1: "文件名称"
}, {
disp: "字母小写",
tip: "将字符串里的字母小写",
wiki: "{" + "{lc:$1}}",
$1: "ABC"
}, {
disp: "首字母小写",
tip: "将字符串里的首字母小写",
wiki: "{" + "{lcfirst:$1}}",
$1: "Abc"
}, {
disp: "字母大写",
tip: "将字符串里的字母大写",
wiki: "{" + "{uc:$1}}",
$1: "abc"
}, {
disp: "首字母大写",
tip: "将字符串里的首字母大写",
wiki: "{" + "{ucfirst:$1}}",
$1: "aBC"
}, {
disp: "数学表达式",
tip: "计算并返回数学表达式的结果",
wiki: "{" + "{#expr: $1 }}",
$1: "<!--表达式-->"
}, {
disp: "判断非空",
tip: "判断是否为非空字符串",
wiki: "{" + "{#if: $1 | <!--如果非空--> | <!--如果为空--> }}",
$1: "<!--内容-->"
}, {
disp: "判断相等",
tip: "判断两个内容是否相等",
wiki: "{" + "{#ifeq: $1 | <!--内容--> | <!--如果为真--> | <!--如果为假--> }}",
$1: "<!--内容-->"
}, {
disp: "逻辑判断",
tip: "判断是否为逻辑真假,不等于0则为真",
wiki: "{" + "{#if: $1 | <!--如果为真--> | <!--如果为假--> }}",
$1: "<!--表达式-->"
}, {
disp: "条件判断",
tip: "switch选择器",
wiki: "{" + "{#switch: $1\n|可能性1 = 结果1\n|可能性2 = 结果2\n|#default = B}}",
$1: "<!--内容/参数/表达式-->"
}, {
disp: "定义变量",
tip: "定义一个变量",
wiki: "{" + "{#vardefine: $1 | 变量值}}",
$1: "变量名"
}, {
disp: "获取变量值",
tip: "获取一个变量的值",
wiki: "{" + "{#var: $1}}",
$1: "变量名"
}, {
disp: "索引变量循环",
tip: "遍历索引变量(数字变量)",
wiki: "{" + "{#fornumargs: number | value | $1}}",
$1: "{" + "{#var: number}} = {" + "{#var: value}}"
}, {
disp: "变量循环",
tip: "遍历所有变量",
wiki: "{" + "{#forargs: arg | key | value | $1}}",
$1: "{" + "{#var: key}} = {" + "{#var: value}}"
}, {
disp: "改变标题",
tip: "改变当前页面的标题,可以改变字母大小写,让下划线代替空格",
wiki: "{" + "{DISPLAYTITLE:$1|noreplace}}",
$1: "{" + "{FULLPAGENAME}}"
}, {
disp: "CSS样式表",
tip: "给页面添加CSS",
wiki: "{" + "{#css:\n$1\n}}",
$1: "/* 样式 */"
}, {
disp: "获取页面",
tip: "SMW功能,根据指定内容获取页面",
wiki: "{" + "{#ask:$1}}",
$1: "<!-- 分类或属性 -->"
}, {
disp: "获取页面+",
tip: "封装过的#ask",
wiki: "{" + "{#ask:$1|format=<!--\ncount:数量\nbroadtable:表格\n--><!-- |mainlabel = 标题|?属性名 = 属性名描述 -->}}",
$1: "<!-- 分类或属性 -->"
}]
}, {
id: "xitsbmld",
disp: "系统变量",
spanbtns: [{
disp: "完整标题",
tip: "包含名字空间的完整页面标题",
wiki: "{" + "{FULLPAGENAME}}"
}, {
disp: "名字空间",
tip: "当前页面名字空间名称",
wiki: "{" + "{NAMESPACE}}"
}, {
disp: "名字空间ID",
tip: "当前页面名字空间ID",
wiki: "{" + "{NAMESPACENUMBER}}"
}, {
disp: "页面标题",
tip: "不包含名字空间的完整页面标题",
wiki: "{" + "{PAGENAME}}"
}, {
disp: "父页面标题",
tip: "不包含名字空间和当前子页面标题的的页面标题",
wiki: "{" + "{BASEPAGENAME}}"
}, {
disp: "子页面标题",
tip: "仅子页面标题",
wiki: "{" + "{SUBPAGENAME}}"
}, {
disp: "根页面标题",
tip: "该页面的根页面的不含名字空间的页面名",
wiki: "{" + "{ROOTPAGENAME}}"
}, {
disp: "管道符",
tip: "",
wiki: "{" + "{!}}"
}]
}, {
id: "vdtlklgr",
disp: "状态开关",
spanbtns: [{
disp: "目录",
tip: "将目录显示在这个位置(页面中只有第一个有效)",
wiki: "__TOC__"
}, {
disp: "强制显示目录",
tip: "将目录强制显示在这个位置",
wiki: "__FORCETOC__"
}, {
disp: "隐藏目录",
tip: "隐藏目录",
wiki: "__NOTOC__"
}]
}];
adminTool = [{
id: "tmjwxukevg",
disp: "添加许可证",
spanbtns: [{
disp: "版权所有",
tip: "All Rights Reserved",
wiki: "{" + "{协议|ARR}}"
}]
}, {
id: "tmjwfflz",
disp: "添加分类",
spanbtns: [{
disp: "Wiki图片",
tip: "",
wiki: "[" + "[分类:Wiki图片]]"
}, {
disp: "游戏截图",
tip: "",
wiki: "[" + "[分类:游戏截图]]"
}, {
disp: "MOD材质",
tip: "",
wiki: "[" + "[分类:MOD材质]]"
}, {
disp: "MOD封面",
tip: "",
wiki: "[" + "[分类:MODLOGO]]"
}, {
disp: "数据包材质",
tip: "",
wiki: "[" + "[分类:数据包材质]]"
}, {
disp: "数据包封面",
tip: "",
wiki: "[" + "[分类:数据包LOGO]]"
}, {
disp: "模板页的文档",
tip: "",
wiki: "[" + "[分类:模板页的文档]]"
}, {
disp: "模板页的文档+",
tip: "",
wiki: "<" + "noinclude>[" + "[分类:模板页的文档]]<" + "/noinclude>"
}]
}];
}
// 封装起来
function addToToolbar(label, scname, sc) {
var scs = {};
scs[scname] = {
type: "booklet",
label: label,
pages: sectionsFormat(sc)
};
editor.wikiEditor("addToToolbar", { sections: scs });
addTitle(sc); // 添加提示
}
// 格式化sections
// 能拆就拆我真是个天才
function sectionsFormat(sc) {
var pages = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = sc[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var i = _step.value;
var tlF = spanbtnsFormat(i.spanbtns);
pages[i.id] = {
label: i.disp,
layout: "characters",
characters: tlF
};
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return pages;
}
// 格式化spanbtn
// 能拆就拆我真是个天才
function spanbtnsFormat(tl) {
var tls = [];
for (var i = 0; i < tl.length; i++) {
tls[i] = onespanbtnFormat(tl[i]);
}
return tls;
}
function onespanbtnFormat(tl) {
var opt = {};
if (tl.wiki.indexOf("$1") != -1) {
var splited = tl.wiki.split("$1");
opt = {
pre: splited[0] || "",
periMsg: tl.$1 || "",
post: splited[1] || ""
};
} else {
opt = { pre: tl.wiki, post: "" };
}
return {
label: tl.disp,
action: {
type: "encapsulate",
options: opt
}
};
}
// 添加title说明
function addTitle(scs) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
var _loop = function _loop() {
var sc = _step2.value;
$('div[rel="' + sc.id + '"] span[rel]').each(function (i, j) {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = sc.spanbtns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var btn = _step3.value;
if (j.getAttribute("rel") == btn.disp) {
j.setAttribute("title", btn.tip);
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
});
};
for (var _iterator2 = scs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
_loop();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
// 环境检查
function envCheck() {
if (mw.config.get("wgPageContentModel") != "wikitext") {
// 判断是不是Wikitext格式的页面
log("不正确的使用场景");
return false;
}
return true;
}
// 初始化
function init() {
$ = jQuery;
editor = $("#wpTextbox1");
getData(); // 写入按钮信息
}
// log
}
function log(msg) {
var t = typeof msg === "undefined" ? "undefined" : _typeof(msg);
if (t == "string" || t == "number") {
console.log(prefix + msg);
} else if (t == "object" || t == "function") {
console.log(prefix);
console.log(msg);
} else if (t == "undefined") {
console.log(prefix + "undefined");
}
}
})();