“Widget:BilibiliVideo”的版本间的差异
第105行: | 第105行: | ||
background: white; | background: white; | ||
padding: 0px 0.5em; | padding: 0px 0.5em; | ||
+ | } | ||
+ | html > body > .navpopup .bilibili-video-container > * { | ||
+ | display: none !important; | ||
+ | } | ||
+ | html > body > .navpopup .bilibili-video-container::before { | ||
+ | content: "请不要在注释里使用 BilibiliVideo 模板"; | ||
+ | font-style: italic; | ||
} | } | ||
</style><script> | </style><script> | ||
"use strict"; | "use strict"; | ||
− | window.RLQ.push(() => { | + | window.RLQ.push(async () => { |
const errMsg = { | const errMsg = { | ||
id: '此处填写的id有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……', | id: '此处填写的id有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……', | ||
第114行: | 第121行: | ||
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>修正……', | ||
}; | }; | ||
+ | await $.ready; | ||
+ | const ifNamespaceAllow = [0, 4, 10, 12].includes(mw.config.get("wgNamespaceNumber")); | ||
const sanNode = $(`<${"span/"}>`); | const sanNode = $(`<${"span/"}>`); | ||
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 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)); | ||
+ | const getErrorType = (code) => { | ||
+ | switch (code) { | ||
+ | case 62003: { | ||
+ | return false; | ||
+ | } | ||
+ | case -403: { | ||
+ | return "forbidden"; | ||
+ | } | ||
+ | default: { | ||
+ | return "failed"; | ||
+ | } | ||
+ | } | ||
+ | }; | ||
try { | try { | ||
const isNaN = Number.isNaN || window.isNaN; | const isNaN = Number.isNaN || window.isNaN; | ||
第164行: | 第186行: | ||
} | } | ||
return false; | return false; | ||
+ | }; | ||
+ | const submit = (ids) => { | ||
+ | if (!ifNamespaceAllow) { | ||
+ | return; | ||
+ | } | ||
+ | if (--ids.pending > 0) { | ||
+ | return; | ||
+ | } | ||
+ | let changed = false; | ||
+ | if (ids.failed.aid.size + ids.failed.bvid.size > 0 && !mw.config.get("wgCategories").includes("带有失效视频的条目")) { | ||
+ | changed = true; | ||
+ | } | ||
+ | if (ids.forbidden.aid.size + ids.forbidden.bvid.size > 0 && !mw.config.get("wgCategories").includes("带有受限视频的条目")) { | ||
+ | changed = true; | ||
+ | } | ||
+ | if (ids.failed.aid.size + ids.failed.bvid.size === 0 && mw.config.get("wgCategories").includes("带有失效视频的条目")) { | ||
+ | changed = true; | ||
+ | } | ||
+ | if (ids.forbidden.aid.size + ids.forbidden.bvid.size === 0 && mw.config.get("wgCategories").includes("带有受限视频的条目")) { | ||
+ | changed = true; | ||
+ | } | ||
+ | if (changed) { | ||
+ | const url = new URL("https://moegirlpedia.annangela.cn/bilibiliCollector/videoCheck"); | ||
+ | url.searchParams.set("pageid", mw.config.get("wgArticleId")); | ||
+ | $.get(`${url}`); | ||
+ | } | ||
}; | }; | ||
if (mw.config.get("skin") === "minerva") { | if (mw.config.get("skin") === "minerva") { | ||
− | $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => { | + | const ids = { |
+ | failed: { | ||
+ | aid: new Set(), | ||
+ | bvid: new Set(), | ||
+ | }, | ||
+ | forbidden: { | ||
+ | aid: new Set(), | ||
+ | bvid: new Set(), | ||
+ | }, | ||
+ | pending: 0, | ||
+ | }; | ||
+ | const targets = $(".bilibili-video-container:not(.bilibili-video-initialized)"); | ||
+ | ids.pending = targets.length; | ||
+ | targets.each((_, ele) => { | ||
const element = $(ele), | const element = $(ele), | ||
dataset = ele.dataset; | dataset = ele.dataset; | ||
第206行: | 第267行: | ||
element.before($("<a/>").addClass("bilibili-video-button").attr("rel", "nofollow noreferrer noopener").attr("href", `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`).text((title || prefix.href + id) + (![0, 1].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove(); | element.before($("<a/>").addClass("bilibili-video-button").attr("rel", "nofollow noreferrer noopener").attr("href", `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`).text((title || prefix.href + id) + (![0, 1].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove(); | ||
console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message); | console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message); | ||
+ | const errorType = getErrorType(code); | ||
+ | if (errorType) { | ||
+ | ids[errorType][prefix.iframe].add(id); | ||
+ | } | ||
return; | return; | ||
} | } | ||
第230行: | 第295行: | ||
error: function () { | error: function () { | ||
element.before($("<a/>").addClass("bilibili-video-button").attr("rel", "nofollow noreferrer noopener").attr("href", `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`).text((title || prefix.href + id) + (![0, 1].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove(); | element.before($("<a/>").addClass("bilibili-video-button").attr("rel", "nofollow noreferrer noopener").attr("href", `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`).text((title || prefix.href + id) + (![0, 1].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove(); | ||
+ | }, | ||
+ | complete: () => { | ||
+ | submit(ids); | ||
}, | }, | ||
}); | }); | ||
第292行: | 第360行: | ||
}; | }; | ||
const run = () => { | const run = () => { | ||
− | $(".bilibili-video-container:not(.exec)").addClass("exec").each((_, ele) => { | + | const ids = { |
+ | failed: { | ||
+ | aid: new Set(), | ||
+ | bvid: new Set(), | ||
+ | }, | ||
+ | forbidden: { | ||
+ | aid: new Set(), | ||
+ | bvid: new Set(), | ||
+ | }, | ||
+ | pending: 0, | ||
+ | }; | ||
+ | const targets = $(".bilibili-video-container:not(.exec)"); | ||
+ | ids.pending = targets.length; | ||
+ | targets.addClass("exec").each((_, ele) => { | ||
const dataset = ele.dataset; | const dataset = ele.dataset; | ||
const _id = dataset.id; | const _id = dataset.id; | ||
第392行: | 第473行: | ||
lazyLoadObserver.observe(iframe[0]); | lazyLoadObserver.observe(iframe[0]); | ||
console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message); | console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message); | ||
+ | const errorType = getErrorType(code); | ||
+ | if (errorType) { | ||
+ | ids[errorType][prefix.iframe].add(id); | ||
+ | } | ||
return; | return; | ||
} | } | ||
第431行: | 第516行: | ||
selfbox.removeAttr("style"); | selfbox.removeAttr("style"); | ||
} | } | ||
+ | submit(ids); | ||
}, | }, | ||
}); | }); |
2022年7月9日 (六) 13:33的版本
名称: | 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}}!