无编辑摘要
imported>=海豚= 无编辑摘要 |
imported>=海豚= 无编辑摘要 |
||
| 第16行: | 第16行: | ||
} | } | ||
.bilibili-video-container, | .bilibili-video-container, | ||
.bilibili-video-container div, | |||
.bilibili-video-container .bilibili-widescreen, | .bilibili-video-container .bilibili-widescreen, | ||
.bilibili-video-container iframe { | .bilibili-video-container iframe { | ||
| 第76行: | 第77行: | ||
border: 0 solid rgba(170,170,170,0.37); | border: 0 solid rgba(170,170,170,0.37); | ||
border-top-width: 1px; | border-top-width: 1px; | ||
max-width: calc(100% - 12px)!important; | max-width: calc(100% - 12px)!important; | ||
} | } | ||
.onshow .bilibili-iframe-container { | |||
max-height: calc(100% - 27px)!important; | max-height: calc(100% - 27px)!important; | ||
} | } | ||
| 第110行: | 第109行: | ||
} | } | ||
</style><script> | </style><script> | ||
window.RLQ.push(function() { | |||
$(function() { | |||
'use strict'; | |||
window.RLQ.push(function () { | |||
$(function () { | |||
if (mw.config.get("AnnTools-BilibiliVideo-running", false)) { | if (mw.config.get("AnnTools-BilibiliVideo-running", false)) { | ||
return; | return; | ||
} | } | ||
mw.config.set("AnnTools-BilibiliVideo-running", true); | mw.config.set("AnnTools-BilibiliVideo-running", true); | ||
var isNaN = Number.isNaN || window.isNaN; | |||
const temp = new Set(); | const temp = new Set(); | ||
class Converter { | class Converter { | ||
constructor() { | constructor() { | ||
| 第161行: | 第135行: | ||
} else if (bv.length === 9) { | } else if (bv.length === 9) { | ||
return `BV1${bv}`; | return `BV1${bv}`; | ||
} else { | |||
throw new Error("BV's length must be 9, 10 or 12"); | |||
} | } | ||
} | } | ||
_bvidToAid(bvid) { | _bvidToAid(bvid) { | ||
let r = 0; | let r = 0; | ||
for (let i = 0; i < 6; i++) { | for (let i = 0; i < 6; i++) { | ||
r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * 58 ** i; | r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * (58 ** i); | ||
} | } | ||
return | return 'av' + ((r - this._add) ^ this._xor); | ||
} | } | ||
bvidToAid(str) { | bvidToAid(str) { | ||
| 第180行: | 第154行: | ||
if (/^av/i.test(av)) { | if (/^av/i.test(av)) { | ||
return av; | return av; | ||
} else { | |||
return `av${av}`; | |||
} | } | ||
} | } | ||
_aidToBvid(aid) { | _aidToBvid(aid) { | ||
| 第199行: | 第173行: | ||
} | } | ||
const converter = new Converter(); | const converter = new Converter(); | ||
if (mw.config.get( | if (mw.config.get('skin') === 'minerva') $('.bilibili-video-container:not(.bilibili-video-initialized)').each(function() { | ||
var element = $(this), | |||
dataset = this.dataset; | |||
element.addClass("bilibili-video-initialized"); | |||
var _id = dataset.id, | |||
id = _id.replace(/^[ab]v/i, ''), | |||
title = dataset.title, | |||
pagename = dataset.pagename, | |||
page = parseInt(dataset.page), | |||
t = parseInt(dataset.t), | |||
tIsInvalid = isNaN(t) || t <= 0, | |||
subtitle = dataset.subtitle === 'true' ? true : false; | |||
var prefix; | |||
var decode = null; | |||
if (/^(?:av)?\d{1,9}$/i.test(_id)) { | |||
prefix = { | |||
href: "av", | |||
iframe: "aid" | |||
}; | |||
} else if (/^(?:bv)?[\da-z]{10}$/i.test(_id)) { | |||
prefix = { | |||
href: "BV", | |||
iframe: "bvid" | |||
}; | |||
if (!/[bB][vV][fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{10}/.test(_id)) { | |||
temp.add(_id); | |||
} else { | } else { | ||
if (/^(?:av)?\d{10,}$/i.test(_id)) { | decode = converter.bvidToAid(_id); | ||
} | |||
} else { | |||
if (/^(?:av)?\d{10,}$/i.test(_id)) { | |||
temp.add(_id); | |||
} | } | ||
$.ajax({ | return this.outerHTML = "<i>id错误</i>"; | ||
} | |||
$.ajax({ | |||
url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id), | |||
type: 'GET', | |||
success: function(data) { | |||
var list = data.VideoEntities | |||
.map(function(e, i) { | |||
e.page = i + 1; | |||
e.title = e.Title.replace(/^\d+、/, ''); | |||
return e; | |||
}), | |||
_page = 1, | |||
name = title || (data.Title ? data.Title : prefix.href + id), | |||
index, | |||
length; | |||
if (pagename) { | |||
for (index = 0, length = list.length; index < length; index++) { | |||
if (list[index].Title !== pagename && list[index].title !== pagename) continue; | |||
_page = list[index].page; | |||
break; | |||
} | } | ||
element.before(button).remove(); | } else _page = page; | ||
index = _page - 1; | |||
var sec = t % 60 + ''; | |||
if (sec.length === 1) sec = '0' + sec; | |||
var time = Math.floor(t / 60) + ':' + sec; | |||
var button = $('<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(name + ' [' + _page + '/' + list.length + ']' + (tIsInvalid ? '' : '[跳转至' + time + ']')); | |||
if (list[index] !== undefined && list[index].VideoCid !== undefined && subtitle) { | |||
button.append('<br>(' + _page + '、' + list[index].Title + ')'); | |||
} | |||
element.before(button).remove(); | |||
}, | |||
error: function(e) { | |||
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].indexOf(page) !== -1 && !isNaN(page) ? ' (P' + page + ')' : ''))).remove(); | |||
}, | |||
}); | }); | ||
} | }); | ||
else { | else { | ||
var global_element = $('#mw-content-text'); | |||
window.widget = window.widget || {}; | window.widget = window.widget || {}; | ||
window.widget.bilibili = { | window.widget.bilibili = { | ||
| 第285行: | 第256行: | ||
} | } | ||
running = true; | running = true; | ||
let target = widget.bilibili.iframes.shift(); | |||
while (target) { | |||
await new Promise((res) => { | |||
target.addEventListener("load", () => { | |||
running = false; | |||
target = widget.bilibili.iframes.shift(); | |||
res(); | |||
target. | |||
}); | }); | ||
target.src = target.dataset.src; | |||
}); | |||
} | |||
} | } | ||
}; | }; | ||
| 第305行: | 第273行: | ||
"intersectionRatio" in window.IntersectionObserverEntry.prototype && | "intersectionRatio" in window.IntersectionObserverEntry.prototype && | ||
"isIntersecting" in window.IntersectionObserverEntry.prototype) { | "isIntersecting" in window.IntersectionObserverEntry.prototype) { | ||
lazyLoadObserver = new IntersectionObserver(function (entries) { | lazyLoadObserver = new IntersectionObserver(function(entries) { | ||
entries.forEach(function (entry) { | entries.forEach(function(entry) { | ||
if (entry.isIntersecting) { | if (entry.isIntersecting) { | ||
const lazyTarget = entry.target; | const lazyTarget = entry.target; | ||
widget.bilibili.iframes.push(lazyTarget); | |||
loop(); | loop(); | ||
lazyLoadObserver.unobserve(lazyTarget); | lazyLoadObserver.unobserve(lazyTarget); | ||
| 第318行: | 第286行: | ||
lazyLoadObserver = { | lazyLoadObserver = { | ||
observe: (ele) => { | observe: (ele) => { | ||
widget.bilibili.iframes.push(ele); | |||
loop(); | loop(); | ||
} | } | ||
} | } | ||
} | } | ||
var iframe_href_base = 'https://www.bilibili.com/blackboard/newplayer.html?playlist=true&playlist_order=sequential&musth5=1&noEndPanel=1&crossDomain=1&autoplay=0&'; | |||
var EPSILON = 2.220446049250313e-16, | |||
rememberWH = function rememberWH(ele) { | rememberWH = function rememberWH(ele) { | ||
ele.data({ width: ele.width(), height: ele.height() }); | ele.data({ width: ele.width(), height: ele.height() }); | ||
}, | }, | ||
setTureHeight = function setTureHeight(ele) { | setTureHeight = function setTureHeight(ele) { | ||
var barHeight = ele.data('height') - ele.data('width') * 9 / 16; //计算标题和播放器控制栏高度 | |||
ele.height(ele.width() * 9 / 16 + barHeight); | ele.height(ele.width() * 9 / 16 + barHeight); | ||
}, | }, | ||
setWH = function setWH(ele) { | setWH = function setWH(ele) { | ||
ele.css({ width: | ele.css({ width: '100%', height: '100%' }); | ||
}, | }, | ||
recallWH = function recallWH(ele) { | recallWH = function recallWH(ele) { | ||
ele.width(ele.data( | ele.width(ele.data('width')).height(ele.data('height')); | ||
}, | }, | ||
setMaxHeight = function setMaxHeight(container, target) { | setMaxHeight = function setMaxHeight(container, target) { | ||
var h = container.outerHeight(true); | |||
var t = 0; | |||
container.children().each(function () { | container.children().each(function() { | ||
t += $(this).outerHeight(true); | t += $(this).outerHeight(true); | ||
}); | }); | ||
target.css( | target.css('max-height', 'calc(100% - ' + parseInt(t - h + 2 - (Number.EPSILON || EPSILON)) + 'px)'); | ||
}; | }; | ||
$( | $('.bilibili-video-container').addClass('exec').each(function() { | ||
var dataset = this.dataset, | |||
_id = dataset.id, | _id = dataset.id, | ||
id = _id.replace(/^[ab]v/i, | id = _id.replace(/^[ab]v/i, ''), | ||
selfbox = $(this); | selfbox = $(this); | ||
var prefix; | |||
var decode = null; | |||
if (/^(?:av)?\d{1,9}$/i.test(_id)) { | if (/^(?:av)?\d{1,9}$/i.test(_id)) { | ||
prefix = { | prefix = { | ||
href: "av", | href: "av", | ||
iframe: "aid" | iframe: "aid" | ||
}; | }; | ||
} else if (/^(?:bv)?[\da-z]{10}$/i.test(_id)) { | } else if (/^(?:bv)?[\da-z]{10}$/i.test(_id)) { | ||
prefix = { | prefix = { | ||
href: "BV", | href: "BV", | ||
iframe: "bvid" | iframe: "bvid" | ||
}; | }; | ||
if (! | if (!/[bB][vV][fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{10}/.test(_id)) { | ||
temp.add(_id); | temp.add(_id); | ||
} else { | } else { | ||
| 第374行: | 第342行: | ||
return this.outerHTML = "<i>id错误</i>"; | return this.outerHTML = "<i>id错误</i>"; | ||
} | } | ||
var page = parseInt(+(dataset.page || 1)), | |||
pagename = dataset.pagename, | |||
title = dataset.title, | |||
height = +dataset.height || 441, | |||
width = +dataset.width || 665, | |||
subtitle = dataset.subtitle === 'true' ? true : false, | |||
t = parseInt(dataset.t), | |||
tIsInvalid = isNaN(t) || t <= 0, | |||
iframeContainer = $(this).find('.bilibili-iframe-container'), | |||
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), | |||
target: '_blank', | |||
}).prependTo($(this).find('.bilibili-title')), | |||
iframe = $('<iframe/>').attr({ | |||
frameborder: 0, | |||
scrolling: 'no', | |||
src: '', | |||
allowfullscreen: true, | |||
class: "bilibili-iframe", | |||
}).css({ | |||
width: width, | |||
height: height, | |||
}); | |||
if (!tIsInvalid) selfbox.removeAttr("data-auto-expand"); | |||
if (isNaN(page) || page < 1) page = 1; | |||
if (isNaN(width)) width = 665; | |||
if (isNaN(height)) height = 441; | |||
var sec = t % 60 + ''; | |||
if (sec.length === 1) sec = '0' + sec; | |||
var time = Math.floor(t / 60) + ':' + sec; | |||
title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ' (' + page + ')' : '') + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | |||
iframeContainer.css({ | |||
width: width, | width: width, | ||
height: height, | height: height, | ||
}).find(".bilibili-iframe-overlay").css({ | |||
}) | |||
width: width, | width: width, | ||
height: height, | height: height, | ||
}).text('正在加载,请稍候……'); | |||
iframe.appendTo(iframeContainer.empty()); | |||
}); | window.setTimeout(function() { //异步出去不要卡主线程 | ||
iframe.appendTo(iframeContainer); | |||
window.setTimeout(function () { //异步出去不要卡主线程 | |||
$.ajax({ | $.ajax({ | ||
url: | url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id), | ||
type: | type: 'GET', | ||
success: function(data) { | |||
success: function (data) { | var list = data.VideoEntities | ||
.map(function(e, i) { | |||
.map(function (e, i) { | |||
e.page = i + 1; | e.page = i + 1; | ||
e.title = e.Title.replace(/^\d+、/, | e.title = e.Title.replace(/^\d+、/, ''); | ||
return e; | return e; | ||
}) | }), | ||
_page = 1, | |||
name = title || (data.Title ? data.Title : prefix.href + id), | |||
index, | |||
length; | |||
if (pagename) { | if (pagename) { | ||
for (index = 0, length = list.length; index < length; index++) { | for (index = 0, length = list.length; index < length; index++) { | ||
if (list[index].Title !== pagename && list[index].title !== pagename) | if (list[index].Title !== pagename && list[index].title !== pagename) continue; | ||
_page = list[index].page; | _page = list[index].page; | ||
break; | break; | ||
} | } | ||
} else | } else _page = page; | ||
index = _page - 1; | index = _page - 1; | ||
var href = title_text.attr('href'); | |||
if (list[index] !== undefined && list[index].VideoCid !== undefined) { | if (list[index] !== undefined && list[index].VideoCid !== undefined) { | ||
iframe.attr( | iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t)); | ||
title_text.attr( | title_text.attr('href', href.replace(new RegExp("\\?p=" + page, 'g'), "?p=" + _page)); | ||
title_text.text(name + | title_text.text(name + ' [' + _page + '/' + list.length + ']' + (tIsInvalid ? '' : '[视频从' + time + ' 开始播放]')); | ||
if (subtitle) | if (subtitle) title_text.append('<br>(' + _page + ' 、' + list[index].Title + ' )'); | ||
} else { | } else { | ||
title_text.text(name + (tIsInvalid ? | title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + ' 开始播放]')); | ||
iframe.attr( | iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t)); | ||
} | } | ||
lazyLoadObserver.observe(iframe[0]); | lazyLoadObserver.observe(iframe[0]); | ||
}, | }, | ||
error: function (e) { | error: function(e) { | ||
title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? | title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ' (' + page + ')' : '') + (tIsInvalid ? '' : '[视频从' + time + ' 开始播放]')); | ||
if (e && e.responseJSON && e.responseJSON.message && e.responseJSON.message === "Authentication is required for accessing this video.") | if (e && e.responseJSON && e.responseJSON.message && e.responseJSON.message === "Authentication is required for accessing this video.") title_text.parent().append('<sup title="“Bilibili采用会员制,大部分投稿视频会员与游客都可以观看,\n 但部分视频在UP主设定下只有会员才可以观看(这些视频常被称为‘只有会员才知道的世界’)。”\n - Bilibili#用户制度 @ ZhMoegirl\n在这种情况下我们无法为您解析视频及其分P标题、分P数量等。">(只有会员才知道的世界)</sup>'); | ||
iframe.attr( | iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + page + (tIsInvalid ? '' : '&t=' + t)); | ||
lazyLoadObserver.observe(iframe[0]); | lazyLoadObserver.observe(iframe[0]); | ||
}, | }, | ||
| 第459行: | 第425行: | ||
}, 137); | }, 137); | ||
//toggle | //toggle | ||
selfbox.find( | selfbox.find('.bilibili-toggle').on('click', function() { | ||
selfbox.width(iframeContainer.outerWidth(true)); | selfbox.width(iframeContainer.outerWidth(true)); | ||
selfbox.toggleClass( | selfbox.toggleClass('onshow'); | ||
iframeContainer.toggle(); | iframeContainer.toggle(); | ||
if ($(this).text() === | if ($(this).text() === ' 显示视频') { | ||
$(this).text( | $(this).text(' 隐藏视频'); | ||
$(window).resize(); | $(window).resize(); | ||
} else { | } else { | ||
$(this).text( | $(this).text(' 显示视频'); | ||
selfbox.removeAttr( | selfbox.removeAttr('style'); | ||
} | } | ||
}); | }); | ||
selfbox.find( | selfbox.find('.bilibili-widescreen').on('click', function() { | ||
if (selfbox.is( | if (selfbox.is(':not(.onshow)')) return; | ||
if (selfbox.is( | if (selfbox.is('.widescreen')) { | ||
selfbox.removeClass( | selfbox.removeClass('widescreen'); | ||
$(this).text( | $(this).text(' 显示宽屏'); | ||
recallWH(iframeContainer); | recallWH(iframeContainer); | ||
recallWH(iframe); | recallWH(iframe); | ||
recallWH(selfbox); | recallWH(selfbox); | ||
} else { | } else { | ||
selfbox.addClass( | selfbox.addClass('widescreen'); | ||
$(this).text( | $(this).text(' 退出宽屏'); | ||
rememberWH(selfbox); | rememberWH(selfbox); | ||
selfbox.css( | selfbox.css('width', selfbox.parent().width() > Math.min(911, global_element.width()) ? '73%' : '100%'); //可以看见按钮的最小宽度 665 的 1/0.73 倍 | ||
setTureHeight(selfbox); | setTureHeight(selfbox); | ||
rememberWH(iframe); | rememberWH(iframe); | ||
| 第494行: | 第460行: | ||
}); | }); | ||
}); | }); | ||
$(window).on( | $(window).on('resize', function() { | ||
$( | $('.bilibili-video-container.onshow.widescreen').each(function() { | ||
var selfbox = $(this); | |||
selfbox.css( | selfbox.css('width', selfbox.parent().width() > Math.min(911, global_element.width()) ? '73%' : '100%'); | ||
setTureHeight(selfbox); | setTureHeight(selfbox); | ||
setMaxHeight(selfbox, selfbox.find( | setMaxHeight(selfbox, selfbox.find('.bilibili-iframe-container')); | ||
}); | }); | ||
}); | }); | ||
setTimeout(function () { | setTimeout(function() { | ||
$('.bilibili-video-container.exec[data-auto-expand="true"]').find( | $('.bilibili-video-container.exec[data-auto-expand="true"]').find('.bilibili-toggle').click(); | ||
}, 100); | }, 100); | ||
} | } | ||
| 第510行: | 第476行: | ||
const raw = await $.get("https://zh.moegirl.org/User:AnnAngela/SandBox/bvid?action=raw&ctype=application/json&_=" + Math.random()); | const raw = await $.get("https://zh.moegirl.org/User:AnnAngela/SandBox/bvid?action=raw&ctype=application/json&_=" + Math.random()); | ||
let flags = false; | let flags = false; | ||
for ( | for (let i of temp) { | ||
if (!(i in raw)) { | if (!(i in raw)) { | ||
flags = true; | flags = true; | ||
| 第521行: | 第487行: | ||
title: "User:AnnAngela/SandBox/bvid", | title: "User:AnnAngela/SandBox/bvid", | ||
text: JSON.stringify(raw), | text: JSON.stringify(raw), | ||
summary: "[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - " + | summary: "[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - " + submit.filter(bvid => !raw.includes(bvid)).join(", "), | ||
tags: "Automation tool", | tags: "Automation tool", | ||
minor: true, | minor: true, | ||
| 第528行: | 第494行: | ||
watchlist: "nochange", | watchlist: "nochange", | ||
contentformat: "application/json", | contentformat: "application/json", | ||
contentmodel: "json" | contentmodel: "json" | ||
}); | }); | ||
} | } | ||