Widget:BilibiliVideo:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
imported>=海豚=
无编辑摘要
第112行: 第112行:
"use strict";
"use strict";
window.RLQ.push(() => {
window.RLQ.push(() => {
    if (mw.config.get("AnnTools-BilibiliVideo-running", false)) {
    try {
      return;
      const isNaN = Number.isNaN || window.isNaN;
   }
     const temp = new Set();
   mw.config.set("AnnTools-BilibiliVideo-running", true);
     const cssLengthUnitValidator = (length, defaultValue, callback) => {
   const isNaN = Number.isNaN || window.isNaN;
       if (typeof length !== "string" || length.length === 0) {
   const temp = new Set();
         callback(false);
   const cssLengthUnitValidator = (length, defaultValue, callback) => {
         return defaultValue;
     if (typeof length !== "string" || length.length === 0) {
       }
       const parsedNumber = parseFloat(length.replace(/[a-z]+/i, ""));
       if (isNaN(parsedNumber) || parsedNumber <= 0) {
         callback(false);
         return defaultValue;
       }
       if (/^(?:\d+|\d*\.\d+)(?:em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|Q|in|pc|pt|px|%)$/.test(length)) {
         callback(true);
         return length;
       }
       if (/^(?:\d+|\d*\.\d+)$/.test(length)) {
         callback(true);
         return `${length}px`;
       }
        callback(false);
        callback(false);
        return defaultValue;
        return defaultValue;
      }
      };
      const parsedNumber = parseFloat(length.replace(/[a-z]+/i, ""));
      const converter = new class Converter {
     if (isNaN(parsedNumber) || parsedNumber <= 0) {
       constructor() {
       callback(false);
         this._base58Table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF";
       return defaultValue;
         this._digitMap = [11, 10, 3, 8, 4, 6];
     }
         this._xor = 177451812;
     if (/^(?:\d+|\d*\.\d+)(?:em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|Q|in|pc|pt|px|%)$/.test(length)) {
         this._add = 8728348608;
       callback(true);
         this._aidRegExp = /(?:av)\d{1,9}/ig;
       return length;
         this._bvidRegExp = /(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}/g;
     }
         this._bvidTemplate = ["B", "V", "1", "", "", "4", "", "1", "", "7", "", ""];
     if (/^(?:\d+|\d*\.\d+)$/.test(length)) {
       callback(true);
       return `${length}px`;
     }
     callback(false);
     return defaultValue;
   };
   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}`;
        }
        }
        throw new Error("BV's length must be 9, 10 or 12");
        _bvTobvid(bv) {
 
         if (bv.length === 12) {
     }
           return bv;
     _bvidToAid(bvid) {
         } else if (bv.length === 10) {
       let r = 0;
           return `BV${bv}`;
       for (let i = 0; i < 6; i++) {
         } else if (bv.length === 9) {
          r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * 58 ** i;
           return `BV1${bv}`;
          }
         throw new Error("BV's length must be 9, 10 or 12");
        }
        }
        return `av${r - this._add ^ this._xor}`;
        _bvidToAid(bvid) {
     }
         let r = 0;
     bvidToAid(str) {
         for (let i = 0; i < 6; i++) {
       return str.replace(this._bvidRegExp, (bv) => {
           r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * 58 ** i;
         return this._bvidToAid(this._bvTobvid(bv));
         }
       });
         return `av${r - this._add ^ this._xor}`;
     }
     _avToAid(av) {
       if (/^av/i.test(av)) {
         return av;
        }
        }
        return `av${av}`;
        bvidToAid(str) {
 
         return str.replace(this._bvidRegExp, (bv) => {
     }
           return this._bvidToAid(this._bvTobvid(bv));
     _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("");
        _avToAid(av) {
     }
          if (/^av/i.test(av)) {
     aidToBvid(str) {
            return av;
       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((_, ele) => {
       const element = $(ele),
         dataset = ele.dataset;
       element.addClass("bilibili-video-initialized");
       const _id = dataset.id,
         id = _id.replace(/^[ab]v/i, ""),
         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; }
       let prefix;
       let 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 (!converter._bvidRegExp.test(_id)) {
           temp.add(_id);
         } else {
           decode = converter.bvidToAid(_id);
          }
          }
        } else {
         return `av${av}`;
          if (/^(?:av)?\d{10,}$/i.test(_id)) {
        }
            temp.add(_id);
       _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 ele.outerHTML = "<i>id错误</i>";
          return bvidClone.join("");
        }
        }
        $.ajax({
        aidToBvid(str) {
          url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
          return str.replace(this._aidRegExp, (av) => {
         type: "GET",
            return this._aidToBvid(this._avToAid(av));
         timeout: 10000,
         success: function (data) {
           const list = data.VideoEntities
             .map((e, i) => {
               e.page = i + 1;
               e.title = e.Title.replace(/^\d+、/, "");
               return e;
             });
           let _page = 1;
           const name = title || (data.Title ? data.Title : prefix.href + id);
           let index;
           let 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;
             }
           } else { _page = page; }
           index = _page - 1;
           let sec = `${t % 60}`;
           if (sec.length === 1) { sec = `0${sec}`; }
           const time = `${Math.floor(t / 60)}:${sec}`;
           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}/${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 () {
           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 {
     const global_element = $("#mw-content-text");
     let lazyLoadObserver;
     if ("IntersectionObserver" in window &&
       "IntersectionObserverEntry" in window &&
       "intersectionRatio" in window.IntersectionObserverEntry.prototype &&
       "isIntersecting" in window.IntersectionObserverEntry.prototype) {
       lazyLoadObserver = new IntersectionObserver((entries) => {
         entries.forEach((entry) => {
           if (entry.isIntersecting) {
             entry.target.src = entry.target.dataset.src;
             lazyLoadObserver.unobserve(entry.target);
           }
          });
          });
        });
        }
      } else {
      };
       lazyLoadObserver = {
      if (mw.config.get("skin") === "minerva") {
         observe: (target) => {
        $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => {
           target.src = target.dataset.src;
         const element = $(ele),
         },
           dataset = ele.dataset;
       };
          element.addClass("bilibili-video-initialized");
      }
          const _id = dataset.id,
     const iframe_href_base = "https://www.bilibili.com/blackboard/newplayer.html?playlist=true&playlist_order=sequential&musth5=1&noEndPanel=1&crossDomain=1&autoplay=0&";
     const EPSILON = 2.220446049250313e-16,
       rememberWH = function rememberWH(ele) {
         ele.data({ width: ele.width(), height: ele.height() });
       },
       setTureHeight = function setTureHeight(ele) {
         const barHeight = ele.data("height") - ele.data("width") * 9 / 16; //计算标题和播放器控制栏高度
         ele.height(ele.width() * 9 / 16 + barHeight);
        },
       setWH = function setWH(ele) {
         ele.css({ width: "100%", height: "100%" });
       },
       recallWH = function recallWH(ele) {
         ele.width(ele.data("width")).height(ele.data("height"));
       },
       setMaxHeight = function setMaxHeight(container, target) {
         const h = container.outerHeight(true);
         let t = 0;
         container.children().each((_, ele) => {
           t += $(ele).outerHeight(true);
         });
          target.css("max-height", `calc(100% - ${parseInt(t - h + 2 - (Number.EPSILON || EPSILON))}px)`);
       };
     const run = () => {
       $(".bilibili-video-container:not(.exec)").addClass("exec").each((_, ele) => {
          const dataset = ele.dataset,
           _id = dataset.id,
            id = _id.replace(/^[ab]v/i, ""),
            id = _id.replace(/^[ab]v/i, ""),
            selfbox = $(ele);
            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; }
          let prefix;
          let prefix;
          let decode = null;
          let decode = null;
第343行: 第225行:
            return ele.outerHTML = "<i>id错误</i>";
            return ele.outerHTML = "<i>id错误</i>";
          }
          }
          let page = parseInt(+(dataset.page || 1));
          ele.innerText = "正在加载中,若长时间空白则说明是网络问题……";
          if (isNaN(page) || page < 1) { page = 1; }
          $.ajax({
         const pagename = dataset.pagename;
           url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
         const title = dataset.title;
           type: "GET",
         const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || selfbox.removeAttr("data-height"));
           timeout: 10000,
         const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || selfbox.removeAttr("data-width"));
           success: function (data) {
         const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-height"));
             const list = data.VideoEntities
         const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-width"));
               .map((e, i) => {
         const subtitle = dataset.subtitle === "true" ? true : false;
                 e.page = i + 1;
         const t = parseInt(dataset.t);
                 e.title = e.Title.replace(/^\d+、/, "");
         const tIsInvalid = isNaN(t) || t <= 0;
                 return e;
         const iframeContainer = selfbox.find(".bilibili-iframe-container");
               });
         const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({
             let _page = 1;
           href: `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`,
             const name = title || (data.Title ? data.Title : prefix.href + id);
           target: "_blank",
             let index;
         }).prependTo(selfbox.find(".bilibili-title"));
             let length;
         const iframe = $("<iframe/>").attr({
             if (pagename) {
           frameborder: 0,
               for (index = 0, length = list.length; index < length; index++) {
           scrolling: "no",
                 if (list[index].Title !== pagename && list[index].title !== pagename) { continue; }
           src: "",
                 _page = list[index].page;
           allowfullscreen: true,
                 break;
           "class": "bilibili-iframe",
               }
         }).css({
             } else { _page = page; }
           width: width,
             index = _page - 1;
           height: height,
             let sec = `${t % 60}`;
           "max-width": maxWidth,
             if (sec.length === 1) { sec = `0${sec}`; }
            "max-height": maxHeight,
             const time = `${Math.floor(t / 60)}:${sec}`;
             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}/${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 () {
             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();
            },
          });
          });
          if (!tIsInvalid) { selfbox.removeAttr("data-auto-expand"); }
       });
         let sec = `${t % 60}`;
     }
         if (sec.length === 1) { sec = `0${sec}`; }
     else {
          const time = `${Math.floor(t / 60)}:${sec}`;
       const global_element = $("#mw-content-text");
         title_text.text(`${(title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ` (${page})` : "") + (tIsInvalid ? "" : `[视频从${time} 开始播放]`)}【视频信息加载中……】`);
       const placeholderToggle = (iframe) => {
         iframeContainer.css({
          if (iframe.data("displayFlag")) {
           width: width,
           iframe.data("displayFlag", false);
            height: height,
           iframe.data("placeholder").fadeOut(370);
           "max-width": maxWidth,
         }
           "max-height": maxHeight,
       };
       let lazyLoadObserver;
       if ("IntersectionObserver" in window &&
         "IntersectionObserverEntry" in window &&
         "intersectionRatio" in window.IntersectionObserverEntry.prototype &&
         "isIntersecting" in window.IntersectionObserverEntry.prototype) {
          lazyLoadObserver = new IntersectionObserver((entries) => {
           entries.forEach((entry) => {
             if (entry.isIntersecting) {
               entry.target.src = entry.target.dataset.src;
               setTimeout(() => {
                 placeholderToggle($(entry.target));
               }, 13070);
               lazyLoadObserver.unobserve(entry.target);
             }
            });
          });
          });
         iframe.appendTo(iframeContainer);
       } else {
          window.setTimeout(() => { //异步出去不要卡主线程
          lazyLoadObserver = {
            $.ajax({
            observe: (target) => {
              url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
              target.src = target.dataset.src;
              type: "GET",
              setTimeout(() => {
             timeout: 10000,
                placeholderToggle($(target));
             success: function (data) {
             }, 13070);
                const list = data.VideoEntities
           },
                 .map((e, i) => {
         };
                   e.page = i + 1;
       }
                   e.title = e.Title.replace(/^\d+、/, "");
       const iframe_href_base = "https://www.bilibili.com/blackboard/newplayer.html?playlist=true&playlist_order=sequential&musth5=1&noEndPanel=1&crossDomain=1&autoplay=0&";
                   return e;
       const EPSILON = 2.220446049250313e-16,
                 });
         rememberWH = function rememberWH(ele) {
               let _page = 1;
           ele.data({ width: ele.width(), height: ele.height() });
               const name = title || (data.Title ? data.Title : prefix.href + id);
         },
               let index;
         setTureHeight = function setTureHeight(ele) {
               let length;
           const barHeight = ele.data("height") - ele.data("width") * 9 / 16; //计算标题和 播放 器控制栏高度
               if (pagename) {
           ele.height(ele.width() * 9 / 16 + barHeight);
                 for (index = 0, length = list.length; index < length; index++) {
         },
                   if (list[index].Title !== pagename && list[index].title !== pagename) { continue; }
         setWH = function setWH(ele) {
                   _page = list[index].page;
           ele.css({ width: "100%", height: "100%" });
                   break;
         },
                 }
         recallWH = function recallWH(ele) {
               } else { _page = page; }
           ele.width(ele.data("width")).height(ele.data("height"));
               index = _page - 1;
         },
               const href = title_text.attr("href");
         setMaxHeight = function setMaxHeight(container, target) {
               if (list[index] !== undefined && list[index].VideoCid !== undefined) {
           const h = container.outerHeight(true);
                 iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`);
           let t = 0;
                 title_text.attr("href", href.replace(new RegExp(`\\?p=${page}`, "g"), `?p=${_page}`));
           container.children().each((_, ele) => {
                 title_text.text(`${name} [${_page}/${list.length}]${tIsInvalid ? "" : `[视频从${time}开始 播放]`}`);
             t += $(ele).outerHeight(true);
                 if (subtitle) { title_text.append(`<br>(${_page}、${list[index].Title})`); }
               } else {
                 title_text.text(name + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
                 iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`);
               }
               lazyLoadObserver.observe(iframe[0]);
             },
             error: function (e) {
               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>'); }
               iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`);
               lazyLoadObserver.observe(iframe[0]);
             },
            });
            });
         }, 13);
           target.css("max-height", `calc(100% - ${parseInt(t - h + 2 - (Number.EPSILON || EPSILON))}px)`);
          //toggle
          };
          selfbox.find(".bilibili-toggle").on("click", (_, ele) => {
       const run = () => {
            const self = $(ele);
          $(".bilibili-video-container:not(.exec)").addClass("exec").each((_, ele) => {
            selfbox.width(iframeContainer.outerWidth(true));
            const dataset = ele.dataset,
           selfbox.toggleClass("onshow");
             _id = dataset.id,
            iframeContainer.toggle();
             id = _id.replace(/^[ab]v/i, ""),
           if (self.text() === "显示视频") {
             selfbox = $(ele);
             self.text("隐藏视频");
            let prefix;
              $(window).resize();
           let 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 (!converter._bvidRegExp.test(_id)) {
               temp.add(_id);
              } else {
               decode = converter.bvidToAid(_id);
             }
            } else {
            } else {
              self.text("显示视频");
              if (/^(?:av)?\d{10,}$/i.test(_id)) {
              selfbox.removeAttr("style");
               temp.add(_id);
              }
             return ele.outerHTML = "<i>id错误</i>";
            }
            }
           let page = parseInt(+(dataset.page || 1));
           if (isNaN(page) || page < 1) { page = 1; }
           const pagename = dataset.pagename;
           const title = dataset.title;
           const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || selfbox.removeAttr("data-height"));
           const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || selfbox.removeAttr("data-width"));
           const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-height"));
           const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || selfbox.removeAttr("data-max-width"));
           const subtitle = dataset.subtitle === "true" ? true : false;
           const t = parseInt(dataset.t);
           const tIsInvalid = isNaN(t) || t <= 0;
           const iframeContainer = selfbox.find(".bilibili-iframe-container");
           const 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(selfbox.find(".bilibili-title"));
           const iframe = $("<iframe/>").attr({
             frameborder: 0,
             scrolling: "no",
             src: "",
             allowfullscreen: true,
             "class": "bilibili-iframe",
           }).css({
             width: width,
             height: height,
             "max-width": maxWidth,
             "max-height": maxHeight,
           });
           if (!tIsInvalid) { selfbox.removeAttr("data-auto-expand"); }
           let sec = `${t % 60}`;
           if (sec.length === 1) { sec = `0${sec}`; }
           const 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,
             "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);
           });
           window.setTimeout(() => { //异步出去不要卡主线程
             $.ajax({
               url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
               type: "GET",
               timeout: 10000,
               success: function (data) {
                 const list = data.VideoEntities
                   .map((e, i) => {
                     e.page = i + 1;
                     e.title = e.Title.replace(/^\d+、/, "");
                     return e;
                   });
                 let _page = 1;
                 const name = title || (data.Title ? data.Title : prefix.href + id);
                 let index;
                 let 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;
                   }
                 } else { _page = page; }
                 index = _page - 1;
                 const href = title_text.attr("href");
                 if (list[index] !== undefined && list[index].VideoCid !== undefined) {
                   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.text(`${name} [${_page}/${list.length}]${tIsInvalid ? "" : `[视频从${time}开始播放]`}`);
                   if (subtitle) { title_text.append(`<br>(${_page}、${list[index].Title})`); }
                 } else {
                   title_text.text(name + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
                   iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`);
                 }
                 lazyLoadObserver.observe(iframe[0]);
               },
               error: function (e) {
                 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>'); }
                 iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`);
                 lazyLoadObserver.observe(iframe[0]);
               },
             });
           }, 13);
           //toggle
           selfbox.find(".bilibili-toggle").on("click", (_, ele) => {
             const self = $(ele);
             selfbox.width(iframeContainer.outerWidth(true));
             selfbox.toggleClass("onshow");
             iframeContainer.toggle();
             if (self.text() === "显示视频") {
               self.text("隐藏视频");
               $(window).resize();
             } else {
               self.text("显示视频");
               selfbox.removeAttr("style");
             }
           });
           selfbox.find(".bilibili-widescreen").on("click", (_, ele) => {
             const self = $(ele);
             if (selfbox.is(":not(.onshow)")) { return; }
             if (selfbox.is(".widescreen")) {
               selfbox.removeClass("widescreen");
               self.text("显示宽屏");
               recallWH(iframeContainer);
               recallWH(iframe);
               recallWH(selfbox);
             } else {
               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", (_, ele) => {
       };
           const self = $(ele);
       $(run);
           if (selfbox.is(":not(.onshow)")) { return; }
       mw.hook("wikipage.content").add(run);
           if (selfbox.is(".widescreen")) {
       $(window).on("load", run);
             selfbox.removeClass("widescreen");
       $(window).on("resize", () => {
             self.text(" 显示宽屏");
         $(".bilibili-video-container.onshow.widescreen").each((_, ele) => {
             recallWH(iframeContainer);
           const selfbox = $(ele);
             recallWH(iframe);
           selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%");
             recallWH(selfbox);
           setTureHeight(selfbox);
           } else {
           setMaxHeight(selfbox, selfbox.find(".bilibili-iframe-container"));
             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);
           }
          });
          });
        });
        });
     };
        setTimeout(() => {
     $(run);
          $('.bilibili-video-container.exec[data-auto-expand="true"]').find(".bilibili-toggle").click();
     mw.hook("wikipage.content").add(run);
       }, 100);
     $(window).on("load", run);
     }
     $(window).on("resize", () => {
     setTimeout(async () => {
        $(".bilibili-video-container.onshow.widescreen").each((_, ele) => {
       if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) {
          const selfbox = $(ele);
         const raw = await $.get(`https://zh.moegirl.org/Template:BilibiliVideo/bvid?action=raw&ctype=application/json&_=${Math.random()}`);
         selfbox.css("width", selfbox.parent().width() > Math.min(911, global_element.width()) ? "73%" : "100%");
         let flags = false;
         setTureHeight(selfbox);
         for (const i of temp) {
         setMaxHeight(selfbox, selfbox.find(".bilibili-iframe-container"));
           if (!(i in raw)) {
       });
             flags = true;
     });
             raw[i] = mw.config.get("wgPageName");
     setTimeout(() => {
           }
       $('.bilibili-video-container.exec[data-auto-expand="true"]').find(".bilibili-toggle").click();
         }
     }, 100);
         if (flags) {
   }
           new mw.Api().postWithToken("csrf", {
   setTimeout(async () => {
             action: "edit",
     if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) {
             title: "Template:BilibiliVideo/bvid",
       const raw = await $.get(`https://zh.moegirl.org/Template:BilibiliVideo/bvid?action=raw&ctype=application/json&_=${Math.random()}`);
             text: JSON.stringify(raw),
       let flags = false;
             summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).filter(bvid => !(bvid in raw)).join(", ")}`,
       for (const i of temp) {
             tags: "Automation tool",
         if (!(i in raw)) {
             minor: true,
           flags = true;
             bot: true,
           raw[i] = mw.config.get("wgPageName");
             nocreate: true,
             watchlist: "nochange",
             contentformat: "application/json",
             contentmodel: "json",
           });
          }
          }
        }
        }
       if (flags) {
     }, 1);
         new mw.Api().postWithToken("csrf", {
   } catch (e) {
           action: "edit",
     // eslint-disable-next-line prefer-template
           title: "Template:BilibiliVideo/bvid",
     prompt("BilibiliVideo模板执行出现问题,请复制以下内容并在提问求助区处粘贴寻求帮助:", navigator.userAgent + " : " + e + " " + e.stack.split("\n")[1].trim());
           text: JSON.stringify(raw),
    }
           summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).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年7月4日 (六) 09:38的版本

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