Widget:BilibiliVideo:修订间差异

删除3,430字节 、​ 2021年1月19日 (星期二)
无编辑摘要
imported>=海豚=
无编辑摘要
imported>=海豚=
无编辑摘要
第114行: 第114行:
      attr: '下方填写的参数 $$$ 有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……',
      attr: '下方填写的参数 $$$ 有误,请参考<a href="https://zh.moegirl.org.cn/Template:BilibiliVideo#firstHeading" target="_blank">模板文档</a>修正……',
    };
    };
    const sanNode = $(decodeURIComponent("%3Cspan%2F%3E"));
    const sanNode = $(`<${"span/"}>`);
    const genErr = (type, msg = "") => type in errMsg ? `${decodeURIComponent("%3Cdiv%20style%3D%22font-style%3A%20italic%3B%22%3E")}BilibiliVideo模板:${errMsg[type].replace("$$$", sanNode.text(msg).html())}${decodeURIComponent("%3C%2Fdiv%3E")}` : "";
    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"}>` : "";
    const injectErrMsgBefore = ($ele, type, msg = "") => $ele.before(genErr(type, msg));
    const injectErrMsgBefore = ($ele, type, msg = "") => $ele.before(genErr(type, msg));
    try {
    try {
      const isNaN = Number.isNaN || window.isNaN;
      const isNaN = Number.isNaN || window.isNaN;
     const temp = new Set();
      const cssLengthUnitValidator = (length, defaultValue, callback, paramName, $ele) => {
      const cssLengthUnitValidator = (length, defaultValue, callback, paramName, $ele) => {
        if (typeof length !== "string" || length.length === 0) {
        if (typeof length !== "string" || length.length === 0) {
第143行: 第142行:
        return defaultValue;
        return defaultValue;
      };
      };
     /* const converter = new 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");
       }
       _bvidToAid(bvid) {
         let r = 0;
         for (let i = 0; i < 6; i++) {
           r += this._base58Table.indexOf(bvid[this._digitMap[i]]) * 58 ** i;
         }
         return `av${r - this._add ^ this._xor}`;
       }
       bvidToAid(str) {
         return str.replace(this._bvidRegExp, (bv) => {
           return this._bvidToAid(this._bvTobvid(bv));
         });
       }
       _avToAid(av) {
         if (/^av/i.test(av)) {
           return av;
         }
         return `av${av}`;
       }
       _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("");
       }
       aidToBvid(str) {
         return str.replace(this._aidRegExp, (av) => {
           return this._aidToBvid(this._avToAid(av));
         });
       }
     }; */
      const fixedNumber = (number) => `${+number < 10 ? "0" : ""}${number}`;
      const fixedNumber = (number) => `${+number < 10 ? "0" : ""}${number}`;
      const secondsParser = (seconds) => `${Math.floor(+seconds / 60)}:${fixedNumber(+seconds % 60)}`;
      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",
           },
         };
       }
       return false;
     };
      if (mw.config.get("skin") === "minerva") {
      if (mw.config.get("skin") === "minerva") {
        $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => {
        $(".bilibili-video-container:not(.bilibili-video-initialized)").each((_, ele) => {
第203行: 第171行:
          element.addClass("bilibili-video-initialized");
          element.addClass("bilibili-video-initialized");
          const _id = dataset.id,
          const _id = dataset.id,
           id = _id.replace(/^[ab]v/i, ""),
            title = dataset.title,
            title = dataset.title,
            pagename = dataset.pagename,
            pagename = dataset.pagename,
第216行: 第183行:
            }
            }
          }
          }
          if (typeof dataset.t === "string" && dataset.t !== "") {
          if ((isNaN(t) || t <= 0) && typeof dataset.t === "string" && dataset.t !== "") {
            injectErrMsgBefore(element, "attr", "t");
            injectErrMsgBefore(element, "attr", "t");
          }
          }
          let prefix;
          const validation = idCorrector(_id);
          if (/^(?:av)?\d{1,9}$/i.test(_id)) {
          let id,
            prefix = {
            prefix;
             href: "av",
          if (validation) {
             iframe: "aid",
           id = validation.id;
           };
            prefix = validation.prefix;
          } else if (/^(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(_id)) {
            prefix = {
             href: "BV",
             iframe: "bvid",
           };
          } else {
          } else {
            temp.add(_id);
            ele.outerHTML = genErr("id");
           return ele.outerHTML = genErr("id");
           return;
          }
          }
          ele.innerText = "正在加载中,若长时间空白则说明是网络问题……";
          ele.innerText = "正在加载中,若长时间空白则说明是网络问题……";
第333行: 第295行:
            const dataset = ele.dataset,
            const dataset = ele.dataset,
              _id = dataset.id,
              _id = dataset.id,
             id = _id.replace(/^[ab]v/i, ""),
              selfbox = $(ele);
              selfbox = $(ele);
            let prefix;
            const validation = idCorrector(_id);
            if (/^(?:av)?\d{1,9}$/i.test(_id)) {
            let id,
              prefix = {
              prefix;
               href: "av",
            if (validation) {
               iframe: "aid",
             id = validation.id;
             };
              prefix = validation.prefix;
            } else if (/^(?:[bB][vV])?1?[fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF]{9}$/.test(_id)) {
              prefix = {
               href: "BV",
               iframe: "bvid",
             };
            } else {
            } else {
              temp.add(_id);
              ele.outerHTML = genErr("id");
             return ele.outerHTML = genErr("id");
             return;
            }
            }
            let page = parseInt(+(dataset.page || 1));
            let page = parseInt(+(dataset.page || 1));
第383行: 第339行:
              "max-height": maxHeight,
              "max-height": maxHeight,
            });
            });
            if (tIsInvalid) {
            if (!tIsInvalid) {
              selfbox.removeAttr("data-auto-expand");
              selfbox.removeAttr("data-auto-expand");
             if (typeof dataset.t === "string" && dataset.t !== "") {
           } else if (typeof dataset.t === "string" && dataset.t !== "") {
               injectErrMsgBefore(selfbox, "attr", "t");
             injectErrMsgBefore(selfbox, "attr", "t");
             }
            }
            }
            const time = secondsParser(t);
            const time = secondsParser(t);
第526行: 第481行:
        });
        });
      }
      }
     setTimeout(async () => {
       if (temp.size > 0 && mw.config.get("wgUserGroups").includes("autoconfirmed")) {
         const raw = await $.get(`https://zh.moegirl.org.cn/Template:BilibiliVideo/bvid?action=raw&ctype=application/json&_=${Math.random()}`);
         let flags = false;
         for (const i of temp) {
           if (!(i in raw)) {
             flags = true;
             raw[i] = mw.config.get("wgPageName");
           }
         }
         if (flags) {
           new mw.Api().postWithToken("csrf", {
             action: "edit",
             title: "Template:BilibiliVideo/bvid",
             text: JSON.stringify(raw),
             summary: `[[Widget:BilibiliVideo|BilibiliVideo]]:bvid不符合格式 - ${Array.from(temp.values()).filter(bvid => !(bvid in raw)).join(", ")}`,
             tags: "Automation tool",
             minor: true,
             bot: true,
             nocreate: true,
             watchlist: "nochange",
             contentformat: "application/json",
             contentmodel: "json",
           });
         }
       }
     }, 1);
    } catch (e) {
    } catch (e) {
      /* eslint-disable */
      /* eslint-disable */
匿名用户