Widget:BilibiliVideo:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
(fix)
 
(未显示1个用户的24个中间版本)
第1行: 第1行:
<noinclude>{{BilibiliVideo/doc/copyright}}
<noinclude>{{BilibiliVideo/doc/copyright}}
'''本Widget不能单独使用''',请使用{{tl|BilibiliVideo}}!</noinclude><includeonly>
'''本Widget不能单独使用''',请使用{{tl|BilibiliVideo}}!</noinclude><includeonly><!--{if !isset($wgBilibili) || !$wgBilibili}--><!--{assign var="wgBilibili" value=true scope="global"}--><style>
<!--{if !isset($wgBilibili) || !$wgBilibili}-->
<!--{assign var="wgBilibili" value=true scope="global"}-->
<style>
.bilibili-video-container {
.bilibili-video-container {
    border: 1px solid rgba(170,170,170,0.37);
    border: 1px solid rgba(170,170,170,0.37);
第16行: 第13行:
}
}
.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 {
第77行: 第73行:
    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;
}
.bilibili-video-container:not([data-max-width]) .bilibili-iframe-container {
    max-width: calc(100% - 12px)!important;
    max-width: calc(100% - 12px)!important;
}
}
.onshow .bilibili-iframe-container {
.bilibili-video-container:not([data-max-width]).onshow .bilibili-iframe-container {
    max-height: calc(100% - 27px)!important;
    max-height: calc(100% - 27px)!important;
}
}
第109行: 第107行:
}
}
</style><script>
</style><script>
window.RLQ.push(function() {
"use strict";
    $(function() {
window.addEventListener('jquery-ready', () => {
      'use strict';
    const errMsg = {
      if (mw.config.get("AnnTools-BilibiliVideo-running", false)) {
      id: ' 此处填写的id有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……',
       return;
     error: "执行出现问题,请复制以下内容并在提问求助区处粘贴寻求帮助:$$$",
     }
      attr: '下方填写的参数 $$$ 有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……',
     mw.config.set("AnnTools-BilibiliVideo-running", true);
   };
      var isNaN = Number.isNaN || window.isNaN;
   const sanNode = $(`<${"span/"}>`);
      const temp = new Set();
   const genErr = (type, msg = "") => type in errMsg ? `<${"div"} style="font-style: italic; border: 1px dashed red;">BilibiliVideo 模板:${errMsg[type].replace("$$$", sanNode.text(msg).html())}<${"/div"}>` : "";
     class Converter {
   const injectErrMsgBefore = ($ele, type, msg = "") => $ele.before(genErr(type, msg));
        constructor() {
   try {
         this._base58Table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF";
      const isNaN = Number.isNaN || window.isNaN;
         this._digitMap = [11, 10, 3, 8, 4, 6];
      const cssLengthUnitValidator = (length, defaultValue, callback, paramName, $ele) => {
          this._xor = 177451812;
        if (typeof length !== "string" || length.length === 0) {
          this._add = 8728348608;
          callback(false);
         this._aidRegExp = /(?:av)\d{1,9}/ig;
          return defaultValue;
          this._bvidRegExp = /(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}/g;
       }
          this._bvidTemplate = ["B", "V", "1", "", "", "4", "", "1", "", "7", "", ""];
       const parsedNumber = parseFloat(length.replace(/[a-z]+/i, ""));
       if (isNaN(parsedNumber) || parsedNumber <= 0) {
          callback(false);
          injectErrMsgBefore($ele, "attr", paramName);
         return defaultValue;
        }
        }
        _bvTobvid(bv) {
        if (/^(?:\d+|\d*\.\d+)(?:em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|Q|in|pc|pt|px|%)$/.test(length)) {
         if (bv.length === 12) {
          callback(true);
           return bv;
          return length;
         } 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) {
        if (/^(?:\d+|\d*\.\d+)$/.test(length)) {
         let r = 0;
         callback(true);
         for (let i = 0; i < 6; i++) {
          return `${length}px`;
           r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * (58 ** i);
          }
         return 'av' + ((r - this._add) ^ this._xor);
        }
        }
        bvidToAid(str) {
        callback(false);
          return str.replace(this._bvidRegExp, (bv) => {
       injectErrMsgBefore($ele, "attr", paramName);
            return this._bvidToAid(this._bvTobvid(bv));
       return defaultValue;
          });
     };
     const fixedNumber = (number) => `${+number < 10 ? "0" : ""}${number}`;
     const secondsParser = (seconds) => `${Math.floor(+seconds / 60)}:${fixedNumber(+seconds % 60)}`;
     const idCorrector = (id) => {
       if (/^(?:av)?\d{1,9}$/i.test(id)) {
          return {
           id: id.replace(/^av/i, ""),
           prefix: {
             href: "av",
             iframe: "aid",
           },
         };
       } else if (/^(?:(?:[bB][vV])?1)?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(id)
         && /4.1.7..$/.test(id)) {
         return {
            id: id.replace(/^.*([fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9})$/i, "1$1"),
           prefix: {
             href: "BV",
             iframe: "bvid",
           },
          };
        }
        }
        _avToAid(av) {
        return false;
          if (/^av/i.test(av)) {
     };
            return av;
     if (mw.config.get("skin") === "minerva") {
          } else {
       $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => {
            return `av${av}`;
          const element = $(ele),
           dataset = ele.dataset;
         element.addClass("bilibili-video-initialized");
         const _id = dataset.id,
           title = dataset.title,
           pagename = dataset.pagename,
           t = parseInt(dataset.t),
           tIsInvalid = isNaN(t) || t <= 0,
            subtitle = dataset.subtitle === "true" ? true : false;
         let page = parseInt(dataset.page);
          if (isNaN(page) || page < 1) {
            page = 1;
           if (typeof dataset.page === "string" && dataset.page !== "") {
             injectErrMsgBefore(element, "attr", "page");
           }
          }
          }
       }
         if ((isNaN(t) || t <= 0) && typeof dataset.t === "string" && dataset.t !== "") {
       _aidToBvid(aid) {
            injectErrMsgBefore(element, "attr", "t");
         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("");
          const validation = idCorrector(_id);
       }
          let id,
       aidToBvid(str) {
            prefix;
          return str.replace(this._aidRegExp, (av) => {
          if (validation) {
            return this._aidToBvid(this._avToAid(av));
           id = validation.id;
          });
           prefix = validation.prefix;
       }
     }
     const converter = new Converter();
     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 {
            decode = converter.bvidToAid(_id);
            ele.outerHTML = genErr("id");
           return;
          }
          }
       } else {
          ele.innerText = " 正在加载中,若长时间空白则说明是网络问题……";
         if (/^(?:av)?\d{10,}$/i.test(_id)) {
         $.ajax({
           temp.add(_id);
           url: `https://api.bilibili.com/x/web-interface/view?${prefix.iframe}=${id}&jsonp=jsonp`,
          }
           type: "GET",
         return this.outerHTML = "<i>id错误</i>";
           dataType: "jsonp",
       }
           timeout: 10000,
       $.ajax({
           success: function ({ code, message, data }) {
         url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id),
             if (code !== 0) {
         type: 'GET',
               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].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove();
         success: function(data) {
                console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message);
           var list = data.VideoEntities
                return;
             .map(function(e, i) {
              }
               e.page = i + 1;
              const list = data.pages;
                e.title = e.Title.replace(/^\d+、/, '');
             let _page = 1;
                return e;
              const name = title || (data.title ? data.title : prefix.href + id);
              }),
              let index;
              _page = 1,
              let length;
              name = title || (data.Title ? data.Title : prefix.href + id),
             if (pagename) {
              index,
               for (index = 0, length = list.length; index < length; index++) {
              length;
                 if (list[index].part !== pagename) { continue; }
           if (pagename) {
                 _page = list[index].page;
             for (index = 0, length = list.length; index < length; index++) {
                 break;
               if (list[index].Title !== pagename && list[index].title !== pagename) continue;
               }
               _page = list[index].page;
             } else { _page = page; }
                break;
             index = _page - 1;
             const time = secondsParser(t);
             const 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}/${secondsParser(list[index].duration)}]${tIsInvalid ? "" : `[跳转至${time}]`}`);
             if (list[index] !== undefined && list[index].cid !== undefined && subtitle) {
                button.append(`<br>(${_page}、${list[index].part})`);
              }
              }
           } else _page = page;
              element.before(button).remove();
           index = _page - 1;
           },
           var sec = t % 60 + '';
           error: function () {
           if (sec.length === 1) sec = '0' + sec;
             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].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove();
           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');
        const global_element = $("#mw-content-text");
       window.widget = window.widget || {};
        const placeholderToggle = (iframe) => {
       window.widget.bilibili = {
          if (iframe.data("displayFlag")) {
         iframes: [],
            iframe.data("displayFlag", false);
       };
           iframe.data("placeholder").fadeOut(370);
       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;
           });
          }
          }
        };
        };
第273行: 第247行:
          "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((entries) => {
            entries.forEach(function(entry) {
            entries.forEach((entry) => {
              if (entry.isIntersecting) {
              if (entry.isIntersecting) {
                const lazyTarget = entry.target;
                entry.target.src = entry.target.dataset.src;
                widget.bilibili.iframes.push(lazyTarget);
                setTimeout(() => {
                loop();
                 placeholderToggle($(entry.target));
                lazyLoadObserver.unobserve(lazyTarget);
                }, 13070);
                lazyLoadObserver.unobserve(entry.target);
              }
              }
            });
            });
第285行: 第260行:
        } else {
        } else {
          lazyLoadObserver = {
          lazyLoadObserver = {
            observe: (ele) => {
            observe: (target) => {
              widget.bilibili.iframes.push(ele);
              target.src = target.dataset.src;
              loop();
             setTimeout(() => {
            }
               placeholderToggle($(target));
          }
              }, 13070);
            },
          };
        }
        }
        var iframe_href_base = 'https://www.bilibili.com/blackboard/newplayer.html?playlist=true&playlist_order=sequential&musth5=1&noEndPanel=1&crossDomain=1&autoplay=0&';
        const 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,
        const 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; //计算标题和播放器控制栏高度
            const 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: '100%', height: '100%' });
            ele.css({ width: "100%", height: "100%" });
          },
          },
          recallWH = function recallWH(ele) {
          recallWH = function recallWH(ele) {
            ele.width(ele.data('width')).height(ele.data('height'));
            ele.width(ele.data("width")).height(ele.data("height"));
          },
          },
          setMaxHeight = function setMaxHeight(container, target) {
          setMaxHeight = function setMaxHeight(container, target) {
            var h = container.outerHeight(true);
            const h = container.outerHeight(true);
            var t = 0;
            let t = 0;
            container.children().each(function() {
            container.children().each((_, ele) => {
              t += $(this).outerHeight(true);
              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)`);
          };
          };
        $('.bilibili-video-container').addClass('exec').each(function() {
        const run = () => {
         var dataset = this.dataset,
         $(".bilibili-video-container:not(.exec)").addClass("exec").each((_, ele) => {
           _id = dataset.id,
           const dataset = ele.dataset,
           id = _id.replace(/^[ab]v/i, ''),
             _id = dataset.id,
           selfbox = $(this);
             selfbox = $(ele);
         var prefix;
           const validation = idCorrector(_id);
         var decode = null;
            let id,
         if (/^(?:av)?\d{1,9}$/i.test(_id)) {
              prefix;
            prefix = {
            if (validation) {
             href: "av",
             id = validation.id;
              iframe: "aid"
              prefix = validation.prefix;
            };
         } 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 {
              decode = converter.bvidToAid(_id);
              ele.outerHTML = genErr("id");
             return;
            }
            }
         } else {
           let page = parseInt(+(dataset.page || 1));
            if (/^(?:av)?\d{10,}$/i.test(_id)) {
            if (isNaN(page) || page < 1) {
             temp.add(_id);
             page = 1;
             if (typeof dataset.page === "string" && dataset.page !== "") {
               injectErrMsgBefore(selfbox, "attr", "page");
             }
            }
            }
            return this.outerHTML = "<i>id错误</i>";
            const pagename = dataset.pagename;
         }
           const title = dataset.title;
         var page = parseInt(+(dataset.page || 1)),
           const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || selfbox.removeAttr("data-height"), "height", selfbox);
            pagename = dataset.pagename,
            const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || selfbox.removeAttr("data-width"), "width", selfbox);
           title = dataset.title,
            const maxHeight = cssLengthUnitValidator(dataset.maxHeight, "100vh", (isValidated) => isValidated || selfbox.removeAttr("data-max-height"), "maxHeight", selfbox);
            height = +dataset.height || 441,
            const maxWidth = cssLengthUnitValidator(dataset.maxWidth, "100%", (isValidated) => isValidated || selfbox.removeAttr("data-max-width"), "maxWidth", selfbox);
            width = +dataset.width || 665,
            const subtitle = dataset.subtitle === "true" ? true : false;
            subtitle = dataset.subtitle === 'true' ? true : false,
            const t = parseInt(dataset.t);
            t = parseInt(dataset.t),
            const tIsInvalid = isNaN(t) || t <= 0;
            tIsInvalid = isNaN(t) || t <= 0,
            const iframeContainer = selfbox.find(".bilibili-iframe-container");
            iframeContainer = $(this).find('.bilibili-iframe-container'),
            const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({
            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(selfbox.find(".bilibili-title"));
            }).prependTo($(this).find('.bilibili-title')),
            const iframe = $("<iframe/>").attr({
            iframe = $('<iframe/>').attr({
              frameborder: 0,
              frameborder: 0,
              scrolling: 'no',
              scrolling: "no",
              src: '',
              src: "",
              allowfullscreen: true,
              allowfullscreen: true,
              class: "bilibili-iframe",
              "class": "bilibili-iframe",
            }).css({
            }).css({
              width: width,
              width: width,
              height: height,
              height: height,
             "max-width": maxWidth,
             "max-height": maxHeight,
           });
           if (!tIsInvalid) {
             selfbox.removeAttr("data-auto-expand");
           } else if (typeof dataset.t === "string" && dataset.t !== "") {
             injectErrMsgBefore(selfbox, "attr", "t");
           }
           const time = secondsParser(t);
           title_text.text(`${(title || prefix.href + id) + (![0, 1].includes(page) ? ` (P${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`)}`);
           iframeContainer.css({
             width: width,
             height: height,
             "max-width": maxWidth,
             "max-height": maxHeight,
           });
           iframe.appendTo(iframeContainer);
           const div = $("<div/>");
           div.css({
             position: "absolute",
             top: "0",
             left: "0",
             bottom: "0",
             right: "0",
             "z-index": "99",
             display: "flex",
             "align-items": "center",
             background: "rgba(255, 255, 255, .37)",
           });
           const text = $("<div/>");
           text.css({
             "text-align": "center",
             width: "100%",
           }).text("正在加载中,若长时间空白则说明是网络问题……");
           div.append(text).appendTo(iframeContainer);
           iframe.data({
             placeholder: div,
             displayFlag: true,
           });
           iframe[0].addEventListener("load", () => {
             placeholderToggle(iframe);
            });
            });
         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,
           height: height,
         }).find(".bilibili-iframe-overlay").css({
           width: width,
           height: height,
         }).text('正在加载,请稍候……');
         iframe.appendTo(iframeContainer.empty());
         window.setTimeout(function() { //异步出去不要卡主线程
            $.ajax({
            $.ajax({
              url: 'https://mgwbcprd.azureedge.net/BilibiliMeta/Index/' + encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id),
              url: `https://api.bilibili.com/x/web-interface/view?${prefix.iframe}=${id}&jsonp=jsonp`,
              type: 'GET',
              type: "GET",
              success: function(data) {
             dataType: "jsonp",
                var list = data.VideoEntities
             timeout: 10000,
                  .map(function(e, i) {
              success: function ({ code, message, data }) {
                   e.page = i + 1;
                if (code !== 0) {
                   e.title = e.Title.replace(/^\d+、/, '');
                  title_text.text((title || prefix.href + id) + (![0, 1].includes(page) ? ` (P${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
                   return e;
                 iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`);
                 }),
                 lazyLoadObserver.observe(iframe[0]);
                 _page = 1,
                 console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message);
                 name = title || (data.Title ? data.Title : prefix.href + id),
                 return;
                 index,
               }
                 length;
               const list = data.pages;
               let _page = 1;
               const name = title || (data.title ? data.title : prefix.href + id);
               let index;
               let 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) continue;
                    if (list[index].part !== pagename) { continue; }
                    _page = list[index].page;
                    _page = list[index].page;
                    break;
                    break;
                  }
                  }
                } else _page = page;
                } else { _page = page; }
                index = _page - 1;
                index = _page - 1;
                var href = title_text.attr('href');
                const href = title_text.attr("href");
                if (list[index] !== undefined && list[index].VideoCid !== undefined) {
                if (list[index] !== undefined && list[index].cid !== undefined) {
                  iframe.attr('data-src', iframe_href_base + prefix.iframe + '=' + id + '&page=' + _page + (tIsInvalid ? '' : '&t=' + t));
                  iframe.attr("data-src", `${iframe_href_base}${prefix.iframe}=${id}&cid=${list[index].cid}&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} 开始播放]`}`);
                  if (subtitle) title_text.append('<br>(' + _page + ' ' + list[index].Title + ' ');
                  if (subtitle) { title_text.append(`<br>(${_page} ${list[index].part} `); }
                } else {
                } else {
                  title_text.text(name + (tIsInvalid ? '' : '[视频从' + time + ' 开始播放]'));
                  title_text.text(name + (tIsInvalid ? "" : `[视频从${time} 开始播放]`));
                  iframe.attr('data-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]);
                lazyLoadObserver.observe(iframe[0]);
              },
              },
              error: function(e) {
              error: function () {
                title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ' (' + page + ')' : '') + (tIsInvalid ? '' : '[视频从' + time + ' 开始播放]'));
                title_text.text((title || prefix.href + id) + (![0, 1].includes(page) ? ` (P${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>');
                iframe.attr("data-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]);
                lazyLoadObserver.observe(iframe[0]);
              },
              },
            });
            });
         }, 137);
           //toggle
         //toggle
           selfbox.find(".bilibili-widescreen").on("click", (_, ele) => {
         selfbox.find('.bilibili-toggle').on('click', function() {
             const self = $(ele);
           selfbox.width(iframeContainer.outerWidth(true));
             if (selfbox.is(":not(.onshow)")) { return; }
           selfbox.toggleClass('onshow');
             if (selfbox.is(".widescreen")) {
           iframeContainer.toggle();
               selfbox.removeClass("widescreen");
           if ($(this).text() === '显示视频') {
               self.text("显示宽屏");
             $(this).text('隐藏视频');
               recallWH(iframeContainer);
             $(window).resize();
               recallWH(iframe);
           } else {
               recallWH(selfbox);
             $(this).text('显示视频');
             } else {
             selfbox.removeAttr('style');
               selfbox.addClass("widescreen");
            }
               self.text("退出宽屏");
               rememberWH(selfbox);
               selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%"); //可以看见按钮的最小宽度 665 的 1/0.73 倍
               setTureHeight(selfbox);
               rememberWH(iframe);
               rememberWH(iframeContainer);
               setWH(iframe);
               setWH(iframeContainer);
               iframeContainer.height(selfbox.height() - title_text.parent().height());
               setMaxHeight(selfbox, iframeContainer);
             }
            });
          });
          });
         selfbox.find('.bilibili-widescreen').on('click', function() {
       };
           if (selfbox.is(':not(.onshow)')) return;
       $(run);
           if (selfbox.is('.widescreen')) {
       mw.hook("wikipage.content").add(run);
             selfbox.removeClass('widescreen');
       $(window).on("load", run);
             $(this).text('显示宽屏');
        $(window).on("resize", () => {
             recallWH(iframeContainer);
          $(".bilibili-video-container.onshow.widescreen").each((_, ele) => {
             recallWH(iframe);
            const selfbox = $(ele);
             recallWH(selfbox);
            selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%");
           } else {
             selfbox.addClass('widescreen');
             $(this).text('退出宽屏');
             rememberWH(selfbox);
             selfbox.css('width', selfbox.parent().width() > Math.min(911, global_element.width()) ? '73%' : '100%'); //可以看见按钮的最小宽度 665 的 1/0.73 倍
             setTureHeight(selfbox);
             rememberWH(iframe);
             rememberWH(iframeContainer);
             setWH(iframe);
             setWH(iframeContainer);
             iframeContainer.height(selfbox.height() - title_text.parent().height());
             setMaxHeight(selfbox, iframeContainer);
           }
         });
       });
        $(window).on('resize', function() {
          $('.bilibili-video-container.onshow.widescreen').each(function() {
            var selfbox = $(this);
            selfbox.css('width', selfbox.parent().width() > Math.min(911, global_element.width()) ? '73%' : '100%');
            setTureHeight(selfbox);
            setTureHeight(selfbox);
            setMaxHeight(selfbox, selfbox.find('.bilibili-iframe-container'));
            setMaxHeight(selfbox, selfbox.find(".bilibili-iframe-container"));
          });
          });
        });
        });
       setTimeout(function() {
         $('.bilibili-video-container.exec[data-auto-expand="true"]').find('.bilibili-toggle').click();
       }, 100);
      }
      }
     setTimeout(async () => {
   } catch (e) {
       if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) {
     /* eslint-disable */
         const raw = await $.get("https://zh.moegirl.org/User:AnnAngela/SandBox/bvid?action=raw&ctype=application/json&_=" + Math.random());
     var msg = genErr("error", navigator.userAgent + " : " + e + " " + e.stack.split("\n")[1].trim());
         let flags = false;
     $(".bilibili-video-container").each(function (_, ele) {
         for (let i of temp) {
       ele.outerHTML = msg;
           if (!(i in raw)) {
     });
             flags = true;
      /* eslint-enable */
             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>

2022年11月20日 (日) 17:07的最新版本

名称: 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}}!