Widget:BilibiliVideo:修订间差异
跳到导航
跳到搜索
imported>=海豚= 无编辑摘要 |
imported>=海豚= 无编辑摘要 |
||
| 第114行: | 第114行: | ||
attr: '下方填写的参数 $$$ 有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……', | attr: '下方填写的参数 $$$ 有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……', | ||
}; | }; | ||
const sanNode = $( | const sanNode = $(decodeURIComponent("%3Cspan%2F%3E")); | ||
const genErr = (type, msg = "") => type in errMsg ? ` | const genErr = (type, msg = "") => type in errMsg ? `${decodeURIComponent("%3Cdiv%20style%3D%22font-style%3A%20italic%3B%22%3E")}BilibiliVideo模板:${errMsg[type].replace("$$$", sanNode.text(msg).html())}${decodeURIComponent("%3C%2Fdiv%3E")}` : ""; | ||
const injectErrMsgBefore = ($ele, type, msg = "") => $ele.before(genErr(type, msg)); | const injectErrMsgBefore = ($ele, type, msg = "") => $ele.before(genErr(type, msg)); | ||
try { | try { | ||
const isNaN = Number.isNaN || window.isNaN; | const isNaN = Number.isNaN || window.isNaN; | ||
const temp = new Set(); | |||
const cssLengthUnitValidator = (length, defaultValue, callback, paramName, $ele) => { | const cssLengthUnitValidator = (length, defaultValue, callback, paramName, $ele) => { | ||
if (typeof length !== "string" || length.length === 0) { | if (typeof length !== "string" || length.length === 0) { | ||
| 第142行: | 第143行: | ||
return defaultValue; | return defaultValue; | ||
}; | }; | ||
/* const converter = new class Converter { | |||
constructor() { | |||
this._base58Table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF"; | |||
this._digitMap = [11, 10, 3, 8, 4, 6]; | |||
this._xor = 177451812; | |||
this._add = 8728348608; | |||
this._aidRegExp = /(?:av)\d{1,9}/ig; | |||
this._bvidRegExp = /(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}/g; | |||
this._bvidTemplate = ["B", "V", "1", "", "", "4", "", "1", "", "7", "", ""]; | |||
} | |||
_bvTobvid(bv) { | |||
if (bv.length === 12) { | |||
return bv; | |||
} else if (bv.length === 10) { | |||
return `BV${bv}`; | |||
} else if (bv.length === 9) { | |||
return `BV1${bv}`; | |||
} | |||
throw new Error("BV's length must be 9, 10 or 12"); | |||
} | |||
_bvidToAid(bvid) { | |||
let r = 0; | |||
for (let i = 0; i < 6; i++) { | |||
r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * 58 ** i; | |||
} | |||
return `av${r - this._add ^ this._xor}`; | |||
} | |||
bvidToAid(str) { | |||
return str.replace(this._bvidRegExp, (bv) => { | |||
return this._bvidToAid(this._bvTobvid(bv)); | |||
}); | |||
} | |||
_avToAid(av) { | |||
if (/^av/i.test(av)) { | |||
return av; | |||
} | |||
return `av${av}`; | |||
} | |||
_aidToBvid(aid) { | |||
const av = (+aid.replace(/^av/g, "") ^ this._xor) + this._add; | |||
const bvidClone = Array.from(this._bvidTemplate); | |||
for (let i = 0; i < 6; i++) { | |||
bvidClone[this._digitMap[i]] = this._base58Table[Math.floor(av / 58 ** i) % 58]; | |||
} | |||
return bvidClone.join(""); | |||
} | |||
aidToBvid(str) { | |||
return str.replace(this._aidRegExp, (av) => { | |||
return this._aidToBvid(this._avToAid(av)); | |||
}); | |||
} | |||
}; */ | |||
const fixedNumber = (number) => `${+number < 10 ? "0" : ""}${number}`; | const fixedNumber = (number) => `${+number < 10 ? "0" : ""}${number}`; | ||
const secondsParser = (seconds) => `${Math.floor(+seconds / 60)}:${fixedNumber(+seconds % 60)}`; | const secondsParser = (seconds) => `${Math.floor(+seconds / 60)}:${fixedNumber(+seconds % 60)}`; | ||
if (mw.config.get("skin") === "minerva") { | if (mw.config.get("skin") === "minerva") { | ||
$(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => { | $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => { | ||
| 第171行: | 第203行: | ||
element.addClass("bilibili-video-initialized"); | element.addClass("bilibili-video-initialized"); | ||
const _id = dataset.id, | const _id = dataset.id, | ||
id = _id.replace(/^[ab]v/i, ""), | |||
title = dataset.title, | title = dataset.title, | ||
pagename = dataset.pagename, | pagename = dataset.pagename, | ||
| 第183行: | 第216行: | ||
} | } | ||
} | } | ||
if ( | if (typeof dataset.t === "string" && dataset.t !== "") { | ||
injectErrMsgBefore(element, "attr", "t"); | injectErrMsgBefore(element, "attr", "t"); | ||
} | } | ||
let prefix; | |||
if (/^(?:av)?\d{1,9}$/i.test(_id)) { | |||
prefix = { | |||
if ( | href: "av", | ||
iframe: "aid", | |||
}; | |||
} else if (/^(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(_id)) { | |||
prefix = { | |||
href: "BV", | |||
iframe: "bvid", | |||
}; | |||
} else { | } else { | ||
ele.outerHTML = genErr("id") | temp.add(_id); | ||
return ele.outerHTML = genErr("id"); | |||
} | } | ||
ele.innerText = "正在加载中,若长时间空白则说明是网络问题……"; | ele.innerText = "正在加载中,若长时间空白则说明是网络问题……"; | ||
| 第295行: | 第333行: | ||
const dataset = ele.dataset, | const dataset = ele.dataset, | ||
_id = dataset.id, | _id = dataset.id, | ||
id = _id.replace(/^[ab]v/i, ""), | |||
selfbox = $(ele); | selfbox = $(ele); | ||
let prefix; | |||
if (/^(?:av)?\d{1,9}$/i.test(_id)) { | |||
prefix = { | |||
if ( | href: "av", | ||
iframe: "aid", | |||
}; | |||
} else if (/^(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(_id)) { | |||
prefix = { | |||
href: "BV", | |||
iframe: "bvid", | |||
}; | |||
} else { | } else { | ||
ele.outerHTML = genErr("id") | temp.add(_id); | ||
return ele.outerHTML = genErr("id"); | |||
} | } | ||
let page = parseInt(+(dataset.page || 1)); | let page = parseInt(+(dataset.page || 1)); | ||
| 第339行: | 第383行: | ||
"max-height": maxHeight, | "max-height": maxHeight, | ||
}); | }); | ||
if ( | if (tIsInvalid) { | ||
selfbox.removeAttr("data-auto-expand"); | selfbox.removeAttr("data-auto-expand"); | ||
if (typeof dataset.t === "string" && dataset.t !== "") { | |||
injectErrMsgBefore(selfbox, "attr", "t"); | |||
} | |||
} | } | ||
const time = secondsParser(t); | const time = secondsParser(t); | ||
| 第481行: | 第526行: | ||
}); | }); | ||
} | } | ||
setTimeout(async () => { | |||
if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) { | |||
const raw = await $.get(`https://zh.moegirl.org.cn/Template:BilibiliVideo/bvid?action=raw&ctype=application/json&_=${Math.random()}`); | |||
let flags = false; | |||
for (const i of temp) { | |||
if (!(i in raw)) { | |||
flags = true; | |||
raw[i] = mw.config.get("wgPageName"); | |||
} | |||
} | |||
if (flags) { | |||
new mw.Api().postWithToken("csrf", { | |||
action: "edit", | |||
title: "Template:BilibiliVideo/bvid", | |||
text: JSON.stringify(raw), | |||
summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).filter(bvid => !(bvid in raw)).join(", ")}`, | |||
tags: "Automation tool", | |||
minor: true, | |||
bot: true, | |||
nocreate: true, | |||
watchlist: "nochange", | |||
contentformat: "application/json", | |||
contentmodel: "json", | |||
}); | |||
} | |||
} | |||
}, 1); | |||
} catch (e) { | } catch (e) { | ||
/* eslint-disable */ | /* eslint-disable */ | ||
2021年5月5日 (三) 19:37的版本
| 名称: | Bilibili视频插件 |
| 作者: | 加大号的猫 |
| 修订: | Boxsnake |
| 重修订: | AnnAngela |
| H5版再修订: | |
| 新H5版又修订: | |
| 移动版支持: | XYZ指示物 |
| 版权协定: | MIT |
| 发布日期: | 2012年6月29日第一版发布; |
| 发布地址: | https://zh.moegirl.org.cn/Widget:BilibiliVideo && https://zh.moegirl.org.cn/Template:BilibiliVideo |
| 注意事项: | 如有问题,请联系作者。 |
本Widget不能单独使用,请使用{{BilibiliVideo}}!