Widget:BilibiliVideo:修订间差异
跳到导航
跳到搜索
imported>850710247liu (创建页面,内容为“<noinclude>{{BilibiliVideo/doc/copyright}} '''本Widget不能单独使用''',请使用{{tl|BilibiliVideo}}!</noinclude><includeonly> <!--{if !isset($wgBilibili)…”) |
imported>=海豚= 无编辑摘要 |
||
| 第33行: | 第33行: | ||
display: none; | display: none; | ||
width: 1em; | width: 1em; | ||
right: -2rem; | right: calc(-2rem - 1px); | ||
border: 1px solid rgba(170,170,170,0.37); | border: 1px solid rgba(170,170,170,0.37); | ||
padding: .25rem .5rem; | padding: .25rem .5rem; | ||
line-height: 1.5em; | line-height: 1.5em; | ||
top: - | top: -2px; | ||
user-select: none; | user-select: none; | ||
cursor: pointer; | cursor: pointer; | ||
| 第113行: | 第113行: | ||
'use strict'; | 'use strict'; | ||
var isNaN = Number.isNaN || window.isNaN; | var isNaN = Number.isNaN || window.isNaN; | ||
const temp = new Set(); | |||
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}`; | |||
} else { | |||
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; | |||
} else { | |||
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 converter = new Converter(); | |||
if (mw.config.get('skin') === 'minerva') $('.bilibili-video-container:not(.bilibili-video-initialized)').each(function() { | if (mw.config.get('skin') === 'minerva') $('.bilibili-video-container:not(.bilibili-video-initialized)').each(function() { | ||
var element = $(this), | var element = $(this), | ||
dataset = this.dataset; | dataset = this.dataset; | ||
element.addClass("bilibili-video-initialized"); | element.addClass("bilibili-video-initialized"); | ||
var | var _id = dataset.id, | ||
id = _id.replace(/^[ab]v/i, ''), | |||
title = dataset.title, | title = dataset.title, | ||
pagename = dataset.pagename, | pagename = dataset.pagename, | ||
| 第124行: | 第181行: | ||
tIsInvalid = isNaN(t) || t <= 0, | tIsInvalid = isNaN(t) || t <= 0, | ||
subtitle = dataset.subtitle === 'true' ? true : false; | 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 { | |||
decode = converter.bvidToAid(_id); | |||
} | |||
} else { | |||
if (/^(?:av)?\d{10,}$/i.test(_id)) { | |||
temp.add(_id); | |||
} | |||
return this.outerHTML = "<i>id错误</i>"; | |||
} | |||
$.ajax({ | $.ajax({ | ||
url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent( | url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id), | ||
type: 'GET', | type: 'GET', | ||
success: function(data) { | success: function(data) { | ||
| 第135行: | 第215行: | ||
}), | }), | ||
_page = 1, | _page = 1, | ||
name = title || (data.Title ? data.Title : | name = title || (data.Title ? data.Title : prefix.href + id), | ||
index, | index, | ||
length; | length; | ||
| 第149行: | 第229行: | ||
if (sec.length === 1) sec = '0' + sec; | if (sec.length === 1) sec = '0' + sec; | ||
var time = Math.floor(t / 60) + ':' + sec; | var time = Math.floor(t / 60) + ':' + sec; | ||
var button = $('<a/>').addClass('bilibili-video-button').attr('href', "https://www.bilibili.com/video/ | 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) { | if (list[index] !== undefined && list[index].VideoCid !== undefined && subtitle) { | ||
button.append('<br>(' + _page + '、' + list[index].Title + ')'); | button.append('<br>(' + _page + '、' + list[index].Title + ')'); | ||
| 第156行: | 第236行: | ||
}, | }, | ||
error: function(e) { | error: function(e) { | ||
element.before($('<a/>').addClass('bilibili-video-button').attr('href', "https://www.bilibili.com/video/ | 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(); | ||
}, | }, | ||
}); | }); | ||
| 第166行: | 第246行: | ||
iframes: new(window.Map || mw.Map)(), | iframes: new(window.Map || mw.Map)(), | ||
}; | }; | ||
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 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, | var EPSILON = 2.220446049250313e-16, | ||
rememberWH = function rememberWH(ele) { | rememberWH = function rememberWH(ele) { | ||
| 第191行: | 第271行: | ||
$('.bilibili-video-container').addClass('exec').each(function() { | $('.bilibili-video-container').addClass('exec').each(function() { | ||
var dataset = this.dataset, | var dataset = this.dataset, | ||
_id = dataset.id, | |||
id = _id.replace(/^[ab]v/i, ''), | |||
selfbox = $(this); | selfbox = $(this); | ||
if ( | 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 { | |||
decode = converter.bvidToAid(_id); | |||
} | |||
} else { | |||
if (/^(?:av)?\d{10,}$/i.test(_id)) { | |||
temp.add(_id); | |||
} | |||
return this.outerHTML = "<i>id错误</i>"; | |||
} | |||
var page = parseInt(+(dataset.page || 1)), | var page = parseInt(+(dataset.page || 1)), | ||
pagename = dataset.pagename, | pagename = dataset.pagename, | ||
| 第203行: | 第306行: | ||
tIsInvalid = isNaN(t) || t <= 0, | tIsInvalid = isNaN(t) || t <= 0, | ||
iframeContainer = $(this).find('.bilibili-iframe-container'), | iframeContainer = $(this).find('.bilibili-iframe-container'), | ||
title_text = $('<a/>').addClass('external text').attr({ | title_text = $('<a/>').attr("rel", "nofollow noreferrer noopener").addClass('external text').attr({ | ||
href: "https://www.bilibili.com/video/ | href: "https://www.bilibili.com/video/" + prefix.href + id + "?p=" + page + (tIsInvalid ? '' : '&t=' + t), | ||
target: '_blank', | target: '_blank', | ||
}).prependTo($(this).find('.bilibili-title')), | }).prependTo($(this).find('.bilibili-title')), | ||
| 第223行: | 第326行: | ||
if (sec.length === 1) sec = '0' + sec; | if (sec.length === 1) sec = '0' + sec; | ||
var time = Math.floor(t / 60) + ':' + sec; | var time = Math.floor(t / 60) + ':' + sec; | ||
title_text.text((title || | title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ' (' + page + ')' : '') + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | ||
iframeContainer.css({ | iframeContainer.css({ | ||
width: width, | width: width, | ||
| 第234行: | 第337行: | ||
execAppend: function execAppend() { | execAppend: function execAppend() { | ||
var iframe = this, | var iframe = this, | ||
retryLink = $('<a/>').text('重新加载').addClass('bilibili-iframe-retry-link').on('click', function() { | retryLink = $('<a/>').attr("rel", "nofollow noreferrer noopener").text('重新加载').addClass('bilibili-iframe-retry-link').on('click', function() { | ||
var container = $(this).closest('.bilibili-iframe-container'), | var container = $(this).closest('.bilibili-iframe-container'), | ||
iframe = container.find('iframe'), | iframe = container.find('iframe'), | ||
| 第256行: | 第359行: | ||
window.setTimeout(function() { //异步出去不要卡主线程 | window.setTimeout(function() { //异步出去不要卡主线程 | ||
$.ajax({ | $.ajax({ | ||
url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent( | url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id), | ||
type: 'GET', | type: 'GET', | ||
success: function(data) { | success: function(data) { | ||
| 第266行: | 第369行: | ||
}), | }), | ||
_page = 1, | _page = 1, | ||
name = title || (data.Title ? data.Title : | name = title || (data.Title ? data.Title : prefix.href + id), | ||
index, | index, | ||
length; | length; | ||
| 第279行: | 第382行: | ||
var href = title_text.attr('href'); | var href = title_text.attr('href'); | ||
if (list[index] !== undefined && list[index].VideoCid !== undefined) { | if (list[index] !== undefined && list[index].VideoCid !== undefined) { | ||
iframe.attr('src', iframe_href_base + id + '&cid=' + list[index].VideoCid + (tIsInvalid ? '' : '&t=' + t)); | iframe.attr('src', iframe_href_base + prefix.iframe + '=' + id + '&cid=' + list[index].VideoCid + (tIsInvalid ? '' : '&t=' + t)); | ||
if (iframeContainer.is(':visible')) iframe.execAppend(); | if (iframeContainer.is(':visible')) iframe.execAppend(); | ||
else iframe.data('ready', true); | else iframe.data('ready', true); | ||
title_text.attr('href', href.replace(new RegExp(" | 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 + '开始播放]')); | ||
if (subtitle) title_text.append('<br>(' + _page + '、' + list[index].Title + ')'); | if (subtitle) title_text.append('<br>(' + _page + '、' + list[index].Title + ')'); | ||
} else { | } else { | ||
title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | ||
iframe.attr('src', iframe_href_base + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t)); | iframe.attr('src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t)); | ||
if (iframeContainer.is(':visible')) iframe.execAppend(); | if (iframeContainer.is(':visible')) iframe.execAppend(); | ||
else iframe.data('ready', true); | else iframe.data('ready', true); | ||
| 第293行: | 第396行: | ||
}, | }, | ||
error: function(e) { | error: function(e) { | ||
title_text.text((title || | 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.") title_text.parent().append('<sup title="“Bilibili采用会员制,大部分投稿视频会员与游客都可以观看,\n 但部分视频在UP主设定下只有会员才可以观看(这些视频常被称为‘只有会员才知道的世界’)。”\n - Bilibili#用户制度 @ ZhMoegirl\n在这种情况下我们无法为您解析视频及其分P标题、分P数量等。">(只有会员才知道的世界)</sup>'); | 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('src', iframe_href_base + id + '&page=' + page + (tIsInvalid ? '' : '&t=' + t)); | iframe.attr('src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + page + (tIsInvalid ? '' : '&t=' + t)); | ||
if (iframeContainer.is(':visible')) iframe.execAppend(); | if (iframeContainer.is(':visible')) iframe.execAppend(); | ||
else iframe.data('ready', true); | else iframe.data('ready', true); | ||
| 第359行: | 第462行: | ||
}, 100); | }, 100); | ||
} | } | ||
setTimeout(async () => { | |||
if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) { | |||
const raw = await $.get("https://zh.moegirl.org/User:AnnAngela/SandBox/bvid?action=raw&ctype=application/json&_=" + Math.random()); | |||
let flags = false; | |||
for (let 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: "User:AnnAngela/SandBox/bvid", | |||
text: JSON.stringify(raw), | |||
summary: "[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - " + submit.filter(bvid => !raw.includes(bvid)).join(", "), | |||
tags: "Automation tool", | |||
minor: true, | |||
bot: true, | |||
nocreate: true, | |||
watchlist: "nochange", | |||
contentformat: "application/json", | |||
contentmodel: "json" | |||
}); | |||
} | |||
} | |||
}, 1); | |||
}); | }); | ||
}); | }); | ||
</script><!--{/if}--> | </script><!--{/if}--> | ||
</includeonly> | </includeonly> | ||
2020年3月30日 (一) 16:27的版本
| 名称: | 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}}!