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 = $(`<${"span/"}>`); | ||
const genErr = (type, msg = "") => type in errMsg ? `${ | const genErr = (type, msg = "") => type in errMsg ? `<${"div"} style="font-style: italic; border: 1px dashed red;">BilibiliVideo模板:${errMsg[type].replace("$$$", sanNode.text(msg).html())}<${"/div"}>` : ""; | ||
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 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) { | ||
| 第143行: | 第142行: | ||
return defaultValue; | return defaultValue; | ||
}; | }; | ||
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)}`; | ||
const idCorrector = (id) => { | |||
if (/^(?:av)?\d{1,9}$/i.test(id)) { | |||
return { | |||
id: id.replace(/^av/i, ""), | |||
prefix: { | |||
href: "av", | |||
iframe: "aid", | |||
}, | |||
}; | |||
} else if (/^(?:(?:[bB][vV])?1)?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(id) | |||
&& /4.1.7..$/.test(id)) { | |||
return { | |||
id: id.replace(/^.*([fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9})$/i, "1$1"), | |||
prefix: { | |||
href: "BV", | |||
iframe: "bvid", | |||
}, | |||
}; | |||
} | |||
return false; | |||
}; | |||
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) => { | ||
| 第203行: | 第171行: | ||
element.addClass("bilibili-video-initialized"); | element.addClass("bilibili-video-initialized"); | ||
const _id = dataset.id, | const _id = dataset.id, | ||
title = dataset.title, | title = dataset.title, | ||
pagename = dataset.pagename, | pagename = dataset.pagename, | ||
| 第216行: | 第183行: | ||
} | } | ||
} | } | ||
if (typeof dataset.t === "string" && dataset.t !== "") { | if ((isNaN(t) || t <= 0) && typeof dataset.t === "string" && dataset.t !== "") { | ||
injectErrMsgBefore(element, "attr", "t"); | injectErrMsgBefore(element, "attr", "t"); | ||
} | } | ||
const validation = idCorrector(_id); | |||
let id, | |||
prefix | prefix; | ||
if (validation) { | |||
id = validation.id; | |||
prefix = validation.prefix; | |||
prefix = | |||
} else { | } else { | ||
ele.outerHTML = genErr("id"); | |||
return; | |||
} | } | ||
ele.innerText = "正在加载中,若长时间空白则说明是网络问题……"; | ele.innerText = "正在加载中,若长时间空白则说明是网络问题……"; | ||
| 第333行: | 第295行: | ||
const dataset = ele.dataset, | const dataset = ele.dataset, | ||
_id = dataset.id, | _id = dataset.id, | ||
selfbox = $(ele); | selfbox = $(ele); | ||
const validation = idCorrector(_id); | |||
let id, | |||
prefix | prefix; | ||
if (validation) { | |||
id = validation.id; | |||
prefix = validation.prefix; | |||
prefix = | |||
} else { | } else { | ||
ele.outerHTML = genErr("id"); | |||
return; | |||
} | } | ||
let page = parseInt(+(dataset.page || 1)); | let page = parseInt(+(dataset.page || 1)); | ||
| 第383行: | 第339行: | ||
"max-height": maxHeight, | "max-height": maxHeight, | ||
}); | }); | ||
if (tIsInvalid) { | if (!tIsInvalid) { | ||
selfbox.removeAttr("data-auto-expand"); | selfbox.removeAttr("data-auto-expand"); | ||
} else if (typeof dataset.t === "string" && dataset.t !== "") { | |||
injectErrMsgBefore(selfbox, "attr", "t"); | |||
} | } | ||
const time = secondsParser(t); | const time = secondsParser(t); | ||
| 第451行: | 第406行: | ||
const href = title_text.attr("href"); | const href = title_text.attr("href"); | ||
if (list[index] !== undefined && list[index].cid !== undefined) { | if (list[index] !== undefined && list[index].cid !== undefined) { | ||
iframe.attr("data-src", `${iframe_href_base | iframe.attr("data-src", `${iframe_href_base}${prefix.iframe}=${id}&cid=${list[index].cid}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`); | ||
title_text.attr("href", href.replace(new RegExp(`\\?p=${page}`, "g"), `?p=${_page}`)); | title_text.attr("href", href.replace(new RegExp(`\\?p=${page}`, "g"), `?p=${_page}`)); | ||
title_text.text(`${name} [${_page}/${list.length}]${tIsInvalid ? "" : `[视频从${time}开始播放]`}`); | title_text.text(`${name} [${_page}/${list.length}]${tIsInvalid ? "" : `[视频从${time}开始播放]`}`); | ||
| 第465行: | 第420行: | ||
iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`); | iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`); | ||
lazyLoadObserver.observe(iframe[0]); | lazyLoadObserver.observe(iframe[0]); | ||
}, | }, | ||
}); | }); | ||
//toggle | //toggle | ||
selfbox.find(".bilibili-widescreen").on("click", (_, ele) => { | selfbox.find(".bilibili-widescreen").on("click", (_, ele) => { | ||
const self = $(ele); | const self = $(ele); | ||
| 第526行: | 第460行: | ||
}); | }); | ||
} | } | ||
} catch (e) { | } catch (e) { | ||
/* eslint-disable */ | /* eslint-disable */ | ||