|
|
| 第224行: |
第224行: |
| }; | | }; |
| if (mw.config.get("skin") === "MoeMobileSkin") { | | if (mw.config.get("skin") === "MoeMobileSkin") { |
| const ids = {
| |
| failed: {
| |
| aid: new Set(),
| |
| bvid: new Set(),
| |
| },
| |
| forbidden: {
| |
| aid: new Set(),
| |
| bvid: new Set(),
| |
| },
| |
| pending: 0,
| |
| };
| |
| const targets = $(".bilibili-video-container:not(.bilibili-video-initialized)");
| |
| ids.pending = targets.length;
| |
| targets.each((_, ele) => {
| |
| 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 !== "") {
| |
| injectErrMsgBefore(element, "attr", "t");
| |
| }
| |
| const validation = idCorrector(_id);
| |
| let id,
| |
| prefix;
| |
| if (validation) {
| |
| id = validation.id;
| |
| prefix = validation.prefix;
| |
| } else {
| |
| ele.outerHTML = genErr("id");
| |
| return;
| |
| }
| |
| ele.innerText = "正在加载中,若长时间空白则说明是网络问题……";
| |
| $.ajax({
| |
| url: `https://api.bilibili.com/x/web-interface/view?${prefix.iframe}=${id}&jsonp=jsonp`,
| |
| type: "GET",
| |
| dataType: "jsonp",
| |
| timeout: 10000,
| |
| success: function ({ code, message, data }) {
| |
| if (code !== 0) {
| |
| 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();
| |
| console.info("Widget:BilibiliVideo", `${prefix.href}${id}`, code, message);
| |
| const errorType = getErrorType(code);
| |
| if (errorType) {
| |
| ids[errorType][prefix.iframe].add(id);
| |
| }
| |
| return;
| |
| }
| |
| const list = data.pages;
| |
| 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].part !== pagename) { continue; }
| |
| _page = list[index].page;
| |
| break;
| |
| }
| |
| } else { _page = page; }
| |
| 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})`);
| |
| }
| |
| 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].includes(page) && !isNaN(page) ? ` (P${page})` : ""))).remove();
| |
| },
| |
| complete: () => {
| |
| submit(ids);
| |
| },
| |
| });
| |
| });
| |
| } | | } |
| else { | | else { |