Widget:BilibiliVideo:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
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(window.Map || mw.Map)(),
          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('div').css({
          }).find(".bilibili-iframe-overlay").css({
            width: width,
            width: width,
            height: height,
            height: height,
          }).text('正在加载,请稍候……');
          }).text('正在加载,请稍候……');
          $.extend(iframe, {
          iframe.appendTo(iframeContainer.empty());
           execAppend: function execAppend() {
             var iframe = this,
               retryLink = $('<a/>').attr("rel", "nofollow noreferrer noopener").text('重新加载').addClass('bilibili-iframe-retry-link').on('click', function() {
                 var container = $(this).closest('.bilibili-iframe-container'),
                   iframe = container.find('iframe'),
                   clone = iframe.clone();
                 window.widget.bilibili.iframes.delete(iframe[0]);
                 iframe.remove();
                 container.append(clone.on('load', function() {
                   $(this).data('load', 'complete');
                 }));
                 window.widget.bilibili.iframes.set(clone[0], $(this));
               });
             iframe.appendTo(iframeContainer.empty()).data('ready', 'appended').on('load', function() {
               $(this).data('load', 'complete');
             });
             window.setTimeout(function() {
               window.widget.bilibili.iframes.set(iframe[0], retryLink);
             }, 10000);
           },
         });
         iframe.data('ready', false);
          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 + '&cid=' + list[index].VideoCid + (tIsInvalid ? '' : '&t=' + t));
                  iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t));
                 if (iframeContainer.is(':visible')) iframe.execAppend();
                 else iframe.data('ready', true);
                  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));
                 if (iframeContainer.is(':visible')) iframe.execAppend();
                 else iframe.data('ready', true);
                }
                }
               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));
                if (iframeContainer.is(':visible')) iframe.execAppend();
                lazyLoadObserver.observe(iframe[0]);
               else iframe.data('ready', true);
              },
              },
            });
            });
第411行: 第431行:
            if ($(this).text() === '显示视频') {
            if ($(this).text() === '显示视频') {
              $(this).text('隐藏视频');
              $(this).text('隐藏视频');
             if (iframe.data('ready') === true) iframe.execAppend();
              $(window).resize();
              $(window).resize();
            } else {
            } else {
第441行: 第460行:
          });
          });
        });
        });
       window.setInterval(function() {
         if (!window.widget.bilibili.iframes || window.widget.bilibili.iframes.size === 0) return;
         window.widget.bilibili.iframes.forEach(function(retryLink, iframe) {
           if (!retryLink || !retryLink.closest || !iframe || !$(iframe).data) return window.widget.bilibili.iframes.delete(iframe);
           if (!retryLink.closest('.bilibili-iframe-container')[0]) retryLink.appendTo(iframe.closest('.bilibili-iframe-container'));
           if ($(iframe).data('load') !== 'complete') retryLink.fadeIn();
           else retryLink.fadeOut();
         });
       }, 1000);
        $(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"]').first().find('.bilibili-toggle').click();
          $('.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日第一版发布;
2015年2月6日更新;
2016年11月29日更新更多细节;
2017年4月10日更新至H5版(感谢众多dalao的debug_(:зゝ∠)_);
2020年01月27日更新至新版H5播放器。

发布地址: https://zh.moegirl.org.cn/Widget:BilibiliVideo && https://zh.moegirl.org.cn/Template:BilibiliVideo
注意事项: 如有问题,请联系作者。

本Widget不能单独使用,请使用{{BilibiliVideo}}!