Widget:BilibiliVideo:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
imported>=海豚=
无编辑摘要
第314行: 第314行:
          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 = () => {
       const dataset = this.dataset,
       $(".bilibili-video-container:not(.exec)").addClass("exec").each(function () {
         _id = dataset.id,
         const dataset = this.dataset,
         id = _id.replace(/^[ab]v/i, ""),
           _id = dataset.id,
         selfbox = $(this);
           id = _id.replace(/^[ab]v/i, ""),
       let prefix;
           selfbox = $(this);
       let decode = null;
         let prefix;
       if (/^(?:av)?\d{1,9}$/i.test(_id)) {
         let decode = null;
         prefix = {
         if (/^(?:av)?\d{1,9}$/i.test(_id)) {
           href: "av",
           prefix = {
           iframe: "aid",
             href: "av",
         };
             iframe: "aid",
       } else if (/^(?:bv)?[\da-z]{10}$/i.test(_id)) {
           };
         prefix = {
         } else if (/^(?:bv)?[\da-z]{10}$/i.test(_id)) {
           href: "BV",
           prefix = {
           iframe: "bvid",
             href: "BV",
         };
             iframe: "bvid",
         if (!converter._bvidRegExp.test(_id)) {
           };
           temp.add(_id);
           if (!converter._bvidRegExp.test(_id)) {
             temp.add(_id);
           } else {
             decode = converter.bvidToAid(_id);
           }
          } else {
          } else {
            decode = converter.bvidToAid(_id);
            if (/^(?:av)?\d{10,}$/i.test(_id)) {
             temp.add(_id);
           }
           return this.outerHTML = "<i>id错误</i>";
          }
          }
       } else {
          let page = parseInt(+(dataset.page || 1));
          if (/^(?:av)?\d{10,}$/i.test(_id)) {
         if (isNaN(page) || page < 1) { page = 1; }
           temp.add(_id);
         const pagename = dataset.pagename;
         }
         const title = dataset.title;
         return this.outerHTML = "<i>id错误</i>";
         const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || $(this).removeAttr("data-height"));
       }
         const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || $(this).removeAttr("data-width"));
       let page = parseInt(+(dataset.page || 1));
         const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || $(this).removeAttr("data-max-height"));
       if (isNaN(page) || page < 1) { page = 1; }
         const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || $(this).removeAttr("data-max-width"));
       const pagename = dataset.pagename;
         const subtitle = dataset.subtitle === "true" ? true : false;
       const title = dataset.title;
         const t = parseInt(dataset.t);
       const height = cssLengthUnitValidator(dataset.height, "441px", (isValidated) => isValidated || $(this).removeAttr("data-height"));
         const tIsInvalid = isNaN(t) || t <= 0;
       const width = cssLengthUnitValidator(dataset.width, "665px", (isValidated) => isValidated || $(this).removeAttr("data-width"));
         const iframeContainer = $(this).find(".bilibili-iframe-container");
       const maxHeight = cssLengthUnitValidator(dataset.maxHeight, undefined, (isValidated) => isValidated || $(this).removeAttr("data-max-height"));
         const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({
       const maxWidth = cssLengthUnitValidator(dataset.maxWidth, undefined, (isValidated) => isValidated || $(this).removeAttr("data-max-width"));
           href: `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`,
       const subtitle = dataset.subtitle === "true" ? true : false;
           target: "_blank",
       const t = parseInt(dataset.t);
         }).prependTo($(this).find(".bilibili-title"));
       const tIsInvalid = isNaN(t) || t <= 0;
         const iframe = $("<iframe/>").attr({
       const iframeContainer = $(this).find(".bilibili-iframe-container");
           frameborder: 0,
       const title_text = $("<a/>").attr("rel", "nofollow noreferrer noopener").addClass("external text").attr({
           scrolling: "no",
         href: `https://www.bilibili.com/video/${prefix.href}${id}?p=${page}${tIsInvalid ? "" : `&t=${t}`}`,
           src: "",
         target: "_blank",
           allowfullscreen: true,
       }).prependTo($(this).find(".bilibili-title"));
           "class": "bilibili-iframe",
       const iframe = $("<iframe/>").attr({
         }).css({
         frameborder: 0,
           width: width,
         scrolling: "no",
           height: height,
         src: "",
           "max-width": maxWidth,
         allowfullscreen: true,
           "max-height": maxHeight,
         "class": "bilibili-iframe",
         });
       }).css({
         if (!tIsInvalid) { selfbox.removeAttr("data-auto-expand"); }
         width: width,
         let sec = `${t % 60}`;
         height: height,
         if (sec.length === 1) { sec = `0${sec}`; }
         "max-width": maxWidth,
         const time = `${Math.floor(t / 60)}:${sec}`;
         "max-height": maxHeight,
         title_text.text(`${(title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ` (${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`)}【视频信息加载中……】`);
       });
         iframeContainer.css({
       if (!tIsInvalid) { selfbox.removeAttr("data-auto-expand"); }
           width: width,
       let sec = `${t % 60}`;
           height: height,
       if (sec.length === 1) { sec = `0${sec}`; }
           "max-width": maxWidth,
       const time = `${Math.floor(t / 60)}:${sec}`;
           "max-height": maxHeight,
       title_text.text(`${(title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ` (${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`)}【视频信息加载中……】`);
         });
       iframeContainer.css({
         iframe.appendTo(iframeContainer);
         width: width,
         window.setTimeout(() => { //异步出去不要卡主线程
         height: height,
           $.ajax({
         "max-width": maxWidth,
             url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
         "max-height": maxHeight,
             type: "GET",
       });
             timeout: 10000,
       iframe.appendTo(iframeContainer);
             success: function (data) {
       window.setTimeout(() => { //异步出去不要卡主线程
               const list = data.VideoEntities
         $.ajax({
                 .map((e, i) => {
           url: `https://mgwbcprd.azureedge.net/BilibiliMeta/Index/${encodeURIComponent(typeof decode === "string" ? decode : prefix.href + id)}`,
                   e.page = i + 1;
           type: "GET",
                   e.title = e.Title.replace(/^\d+、/, "");
           timeout: 10000,
                   return e;
           success: function (data) {
                 });
             const list = data.VideoEntities
               let _page = 1;
               .map((e, i) => {
               const name = title || (data.Title ? data.Title : prefix.href + id);
                 e.page = i + 1;
               let index;
                 e.title = e.Title.replace(/^\d+、/, "");
               let length;
                 return e;
               if (pagename) {
               });
                 for (index = 0, length = list.length; index < length; index++) {
             let _page = 1;
                   if (list[index].Title !== pagename && list[index].title !== pagename) { continue; }
             const name = title || (data.Title ? data.Title : prefix.href + id);
                   _page = list[index].page;
             let index;
                   break;
             let length;
                  }
             if (pagename) {
               } else { _page = page; }
               for (index = 0, length = list.length; index < length; index++) {
               index = _page - 1;
                 if (list[index].Title !== pagename && list[index].title !== pagename) { continue; }
               const href = title_text.attr("href");
                  _page = list[index].page;
               if (list[index] !== undefined && list[index].VideoCid !== undefined) {
                  break;
                 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}`}`);
                }
                }
             } else { _page = page; }
                lazyLoadObserver.observe(iframe[0]);
             index = _page - 1;
             },
             const href = title_text.attr("href");
             error: function (e) {
             if (list[index] !== undefined && list[index].VideoCid !== undefined) {
               title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ` (${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
               iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`);
               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>'); }
               title_text.attr("href", href.replace(new RegExp(`\\?p=${page}`, "g"), `?p=${_page}`));
               iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`);
               title_text.text(`${name} [${_page}/${list.length}]${tIsInvalid ? "" : `[视频从${time}开始播放]`}`);
               lazyLoadObserver.observe(iframe[0]);
                if (subtitle) { title_text.append(`<br>(${_page}、${list[index].Title})`); }
             },
             } else {
            });
               title_text.text(name + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
         }, 137);
               iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${_page}${tIsInvalid ? "" : `&t=${t}`}`);
         //toggle
             }
         selfbox.find(".bilibili-toggle").on("click", function () {
             lazyLoadObserver.observe(iframe[0]);
           selfbox.width(iframeContainer.outerWidth(true));
           },
           selfbox.toggleClass("onshow");
           error: function (e) {
           iframeContainer.toggle();
             title_text.text((title || prefix.href + id) + ([0, 1].indexOf(page) === -1 ? ` (${page})` : "") + (tIsInvalid ? "" : `[视频从${time}开始播放]`));
           if ($(this).text() === "显示视频") {
             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>'); }
             $(this).text("隐藏视频");
             iframe.attr("data-src", `${iframe_href_base + prefix.iframe}=${id}&page=${page}${tIsInvalid ? "" : `&t=${t}`}`);
             $(window).resize();
             lazyLoadObserver.observe(iframe[0]);
           } else {
            },
             $(this).text("显示视频");
             selfbox.removeAttr("style");
           }
         });
         selfbox.find(".bilibili-widescreen").on("click", function () {
           if (selfbox.is(":not(.onshow)")) { return; }
           if (selfbox.is(".widescreen")) {
             selfbox.removeClass("widescreen");
             $(this).text("显示宽屏");
             recallWH(iframeContainer);
             recallWH(iframe);
             recallWH(selfbox);
           } 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);
           }
          });
          });
       }, 137);
       //toggle
       selfbox.find(".bilibili-toggle").on("click", function () {
         selfbox.width(iframeContainer.outerWidth(true));
         selfbox.toggleClass("onshow");
         iframeContainer.toggle();
         if ($(this).text() === "显示视频") {
           $(this).text("隐藏视频");
           $(window).resize();
         } else {
           $(this).text("显示视频");
           selfbox.removeAttr("style");
         }
       });
       selfbox.find(".bilibili-widescreen").on("click", function () {
         if (selfbox.is(":not(.onshow)")) { return; }
         if (selfbox.is(".widescreen")) {
           selfbox.removeClass("widescreen");
           $(this).text("显示宽屏");
           recallWH(iframeContainer);
           recallWH(iframe);
           recallWH(selfbox);
         } 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);
         }
        });
        });
      });
      };
     run();
     mw.hook("wikipage.content").fire(run);
     $(window).on("load", run);
      $(window).on("resize", () => {
      $(window).on("resize", () => {
        $(".bilibili-video-container.onshow.widescreen").each(function () {
        $(".bilibili-video-container.onshow.widescreen").each(function () {
第476行: 第481行:
    setTimeout(async () => {
    setTimeout(async () => {
      if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) {
      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()}`);
        const raw = await $.get(`https://zh.moegirl.org/Template:BilibiliVideo/bvid?action=raw&ctype=application/json&_=${Math.random()}`);
        let flags = false;
        let flags = false;
        for (const i of temp) {
        for (const i of temp) {
第487行: 第492行:
          new mw.Api().postWithToken("csrf", {
          new mw.Api().postWithToken("csrf", {
            action: "edit",
            action: "edit",
            title: "User:AnnAngela/SandBox/bvid",
            title: "Template:BilibiliVideo/bvid",
            text: JSON.stringify(raw),
            text: JSON.stringify(raw),
            summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).filter(bvid => !raw.includes(bvid)).join(", ")}`,
            summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).filter(bvid => !raw.includes(bvid)).join(", ")}`,

2020年6月29日 (一) 17:04的版本

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