Widget:BilibiliVideo:修订间差异
跳到导航
跳到搜索
imported>=海豚= 无编辑摘要 |
imported>=海豚= ([InPageEdit] 没有编辑摘要) |
||
| 第112行: | 第112行: | ||
$(function() { | $(function() { | ||
'use strict'; | 'use strict'; | ||
if (mw.config.get("AnnTools-BilibiliVideo-running", false)) { | |||
return; | |||
} | |||
mw.config.set("AnnTools-BilibiliVideo-running", true); | |||
var isNaN = Number.isNaN || window.isNaN; | var isNaN = Number.isNaN || window.isNaN; | ||
const temp = new Set(); | const temp = new Set(); | ||
| 第244行: | 第248行: | ||
window.widget = window.widget || {}; | window.widget = window.widget || {}; | ||
window.widget.bilibili = { | window.widget.bilibili = { | ||
iframes: new( | iframes: [], | ||
}; | |||
let running = false; | |||
const loop = async () => { | |||
if (running) { | |||
return; | |||
} | |||
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.src = target.dataset.src; | |||
}); | |||
} | |||
}; | }; | ||
let lazyLoadObserver; | |||
if ("IntersectionObserver" in window && | |||
"IntersectionObserverEntry" in window && | |||
"intersectionRatio" in window.IntersectionObserverEntry.prototype && | |||
"isIntersecting" in window.IntersectionObserverEntry.prototype) { | |||
lazyLoadObserver = new IntersectionObserver(function(entries) { | |||
entries.forEach(function(entry) { | |||
if (entry.isIntersecting) { | |||
const lazyTarget = entry.target; | |||
widget.bilibili.iframes.push(lazyTarget); | |||
loop(); | |||
lazyLoadObserver.unobserve(lazyTarget); | |||
} | |||
}); | |||
}); | |||
} else { | |||
lazyLoadObserver = { | |||
observe: (ele) => { | |||
widget.bilibili.iframes.push(ele); | |||
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 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, | ||
| 第315行: | 第360行: | ||
src: '', | src: '', | ||
allowfullscreen: true, | allowfullscreen: true, | ||
class: "bilibili-iframe", | |||
}).css({ | }).css({ | ||
width: width, | width: width, | ||
| 第330行: | 第376行: | ||
width: width, | width: width, | ||
height: height, | height: height, | ||
}).find( | }).find(".bilibili-iframe-overlay").css({ | ||
width: width, | width: width, | ||
height: height, | height: height, | ||
}).text('正在加载,请稍候……'); | }).text('正在加载,请稍候……'); | ||
iframe.appendTo(iframeContainer.empty()); | |||
window.setTimeout(function() { //异步出去不要卡主线程 | window.setTimeout(function() { //异步出去不要卡主线程 | ||
$.ajax({ | $.ajax({ | ||
| 第382行: | 第406行: | ||
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 + prefix.iframe + '=' + id + '& | iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&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 + '开始播放]')); | ||
| 第390行: | 第412行: | ||
} else { | } else { | ||
title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | ||
iframe.attr('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]); | |||
}, | }, | ||
error: function(e) { | error: function(e) { | ||
title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ' (' + page + ')' : '') + (tIsInvalid ? '' : '[视频从' + time + '开始播放]')); | 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 + 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]); | |||
}, | }, | ||
}); | }); | ||
| 第411行: | 第431行: | ||
if ($(this).text() === '显示视频') { | if ($(this).text() === '显示视频') { | ||
$(this).text('隐藏视频'); | $(this).text('隐藏视频'); | ||
$(window).resize(); | $(window).resize(); | ||
} else { | } else { | ||
| 第441行: | 第460行: | ||
}); | }); | ||
}); | }); | ||
$(window).on('resize', function() { | $(window).on('resize', function() { | ||
$('.bilibili-video-container.onshow.widescreen').each(function() { | $('.bilibili-video-container.onshow.widescreen').each(function() { | ||
| 第459行: | 第469行: | ||
}); | }); | ||
setTimeout(function() { | setTimeout(function() { | ||
$('.bilibili-video-container.exec[data-auto-expand="true"]' | $('.bilibili-video-container.exec[data-auto-expand="true"]').find('.bilibili-toggle').click(); | ||
}, 100); | }, 100); | ||
} | } | ||
2020年4月8日 (三) 20:56的版本
| 名称: | 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}}!