Widget:BilibiliVideo:修订间差异
跳到导航
跳到搜索
imported>=海豚= 无编辑摘要 |
imported>=海豚= 无编辑摘要 |
||
| 第195行: | 第195行: | ||
const converter = new Converter(); | const converter = new Converter(); | ||
if (mw.config.get("skin") === "minerva") { | if (mw.config.get("skin") === "minerva") { | ||
$(".bilibili-video-container:not(.bilibili-video-initialized)").each( | $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => { | ||
const element = $( | const element = $(ele), | ||
dataset = | dataset = ele.dataset; | ||
element.addClass("bilibili-video-initialized"); | element.addClass("bilibili-video-initialized"); | ||
const _id = dataset.id, | const _id = dataset.id, | ||
| 第229行: | 第229行: | ||
temp.add(_id); | temp.add(_id); | ||
} | } | ||
return | return ele.outerHTML = "<i>id错误</i>"; | ||
} | } | ||
$.ajax({ | $.ajax({ | ||
| 第309行: | 第309行: | ||
const h = container.outerHeight(true); | const h = container.outerHeight(true); | ||
let t = 0; | let t = 0; | ||
container.children().each( | container.children().each((_, ele) => { | ||
t += $( | t += $(ele).outerHeight(true); | ||
}); | }); | ||
target.css("max-height", `calc(100% - ${parseInt(t - h + 2 - (Number.EPSILON || EPSILON))}px)`); | target.css("max-height", `calc(100% - ${parseInt(t - h + 2 - (Number.EPSILON || EPSILON))}px)`); | ||
}; | }; | ||
const run = () => { | const run = () => { | ||
$(".bilibili-video-container:not(.exec)").addClass("exec").each( | $(".bilibili-video-container:not(.exec)").addClass("exec").each((_, ele) => { | ||
const dataset = | const dataset = ele.dataset, | ||
_id = dataset.id, | _id = dataset.id, | ||
id = _id.replace(/^[ab]v/i, ""), | id = _id.replace(/^[ab]v/i, ""), | ||
selfbox = $( | selfbox = $(ele); | ||
let prefix; | let prefix; | ||
let decode = null; | let decode = null; | ||
| 第341行: | 第341行: | ||
temp.add(_id); | temp.add(_id); | ||
} | } | ||
return | return ele.outerHTML = "<i>id错误</i>"; | ||
} | } | ||
let page = parseInt(+(dataset.page || 1)); | let page = parseInt(+(dataset.page || 1)); | ||
| 第347行: | 第347行: | ||
const pagename = dataset.pagename; | const pagename = dataset.pagename; | ||
const title = dataset.title; | const title = dataset.title; | ||
const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || | const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || selfbox.removeAttr("data-height")); | ||
const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || | const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || selfbox.removeAttr("data-width")); | ||
const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || | const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-height")); | ||
const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || | const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-width")); | ||
const subtitle = dataset.subtitle === "true" ? true : false; | const subtitle = dataset.subtitle === "true" ? true : false; | ||
const t = parseInt(dataset.t); | const t = parseInt(dataset.t); | ||
const tIsInvalid = isNaN(t) || t <= 0; | const tIsInvalid = isNaN(t) || t <= 0; | ||
const iframeContainer = | const iframeContainer = selfbox.find(".bilibili-iframe-container"); | ||
const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({ | const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({ | ||
href: `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`, | href: `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`, | ||
target: "_blank", | target: "_blank", | ||
}).prependTo( | }).prependTo(selfbox.find(".bilibili-title")); | ||
const iframe = $("<iframe/>").attr({ | const iframe = $("<iframe/>").attr({ | ||
frameborder: 0, | frameborder: 0, | ||
| 第426行: | 第426行: | ||
}, | }, | ||
}); | }); | ||
}, | }, 13); | ||
//toggle | //toggle | ||
selfbox.find(".bilibili-toggle").on("click", | selfbox.find(".bilibili-toggle").on("click", (_, ele) => { | ||
const self = $(ele); | |||
selfbox.width(iframeContainer.outerWidth(true)); | selfbox.width(iframeContainer.outerWidth(true)); | ||
selfbox.toggleClass("onshow"); | selfbox.toggleClass("onshow"); | ||
iframeContainer.toggle(); | iframeContainer.toggle(); | ||
if ( | if (self.text() === "显示视频") { | ||
self.text("隐藏视频"); | |||
$(window).resize(); | $(window).resize(); | ||
} else { | } else { | ||
self.text("显示视频"); | |||
selfbox.removeAttr("style"); | selfbox.removeAttr("style"); | ||
} | } | ||
}); | }); | ||
selfbox.find(".bilibili-widescreen").on("click", | selfbox.find(".bilibili-widescreen").on("click", (_, ele) => { | ||
const self = $(ele); | |||
if (selfbox.is(":not(.onshow)")) { return; } | if (selfbox.is(":not(.onshow)")) { return; } | ||
if (selfbox.is(".widescreen")) { | if (selfbox.is(".widescreen")) { | ||
selfbox.removeClass("widescreen"); | selfbox.removeClass("widescreen"); | ||
self.text("显示宽屏"); | |||
recallWH(iframeContainer); | recallWH(iframeContainer); | ||
recallWH(iframe); | recallWH(iframe); | ||
| 第450行: | 第452行: | ||
} else { | } else { | ||
selfbox.addClass("widescreen"); | selfbox.addClass("widescreen"); | ||
self.text("退出宽屏"); | |||
rememberWH(selfbox); | rememberWH(selfbox); | ||
selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%"); //可以看见按钮的最小宽度 665 的 1/0.73 倍 | selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%"); //可以看见按钮的最小宽度 665 的 1/0.73 倍 | ||
| 第464行: | 第466行: | ||
}); | }); | ||
}; | }; | ||
run | $(run); | ||
mw.hook("wikipage.content"). | mw.hook("wikipage.content").add(run); | ||
$(window).on("load", run); | $(window).on("load", run); | ||
$(window).on("resize", () => { | $(window).on("resize", () => { | ||
$(".bilibili-video-container.onshow.widescreen").each( | $(".bilibili-video-container.onshow.widescreen").each((_, ele) => { | ||
const selfbox = $( | const selfbox = $(ele); | ||
selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%"); | selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%"); | ||
setTureHeight(selfbox); | setTureHeight(selfbox); | ||
2020年7月2日 (四) 09:25的版本
| 名称: | 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}}!