注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://zh.moegirl.org.cn/User:AnnAngela/widgetBilibili/es5.js?_=1
/* jshint ignore:start */ 'use strict'; // https://tc39.github.io/ecma262/#sec-array.prototype.find if (!Array.prototype.find) { Object.defineProperty(Array.prototype, 'find', { value: function(predicate) { // 1. Let O be ? ToObject(this value). if (this == null) { throw new TypeError('"this" is null or not defined'); } var o = Object(this); // 2. Let len be ? ToLength(? Get(O, "length")). var len = o.length >>> 0; // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. var thisArg = arguments[1]; // 5. Let k be 0. var k = 0; // 6. Repeat, while k < len while (k < len) { // a. Let Pk be ! ToString(k). // b. Let kValue be ? Get(O, Pk). // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). // d. If testResult is true, return kValue. var kValue = o[k]; if (predicate.call(thisArg, kValue, k, o)) { return kValue; } // e. Increase k by 1. k++; } // 7. Return undefined. return undefined; } }); } var _slicedToArray = function() { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function() { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function(Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var BilibiliWidget = function() { _createClass(BilibiliWidget, [{ key: 'appendiframe', value: function appendiframe(iframe, container) { var self = this; var overlay = iframe.closest('.bilibili-iframe-container').find('.bilibili-iframe-overlay'); iframe.appendTo(container).data('ready', 'complete').on('load', function() { self.load($(this)); }); window.setTimeout(function() { overlay.append('<br/>').append(self.refreshLink('iframe')); }, 10000); } }]); function BilibiliWidget() { _classCallCheck(this, BilibiliWidget); var self = this; self.globalAutoplay = false; $('.bilibili-video-container').show().each(function() { self.exec($(this)); }); } _createClass(BilibiliWidget, [{ key: 'error', value: function error(_ref) { var $video = _ref.$video, mode = _ref.mode, info = _ref.info; var self = this; var message = { execError: '\uFF08rawPage: ' + info.page + ', execPage: ' + info._page + ', pageListLength: ' + info.list.length + ', list: ' + JSON.stringify(info.list) + '\uFF09', network: 'readyState: ' + info.readyState + ', responseText: "' + info.responseText + '", status: ' + info.status + ', statusText: "' + info.statusText + '"' }; $video.find('.bilibili-iframe-overlay').text('非常抱歉,我们无法解析这个视频~').append('<br/>').append('请点击下方链接重试,如果多次不成功请到提问求助区反馈并附上最下方信息!').append(self.refreshLink('load', { $video: $video })).append('<br/>').append(message[mode]); } }, { key: 'exec', value: function exec($video) { var self = this; var _$video$0$dataset = $video[0].dataset, _aid = _$video$0$dataset._aid, _page = _$video$0$dataset._page, pagename = _$video$0$dataset.pagename, title = _$video$0$dataset.title, _height = _$video$0$dataset._height, _width = _$video$0$dataset._width, _autoplay = _$video$0$dataset._autoplay; var aid = _aid.replace('av', ''), page = self.validNumber(_page) ? +_page : 1, height = self.validNumber(_height) ? +_height : 421, width = self.validNumber(_width) ? +_width : 600, autoplay = ['false', ''].find('_autoplay') ? false : true; var $title = $video.find('.bilibili-title'), iframeContainer = $video.find('.bilibili-iframe-container'), iframe = $('<iframe/>').attr({ frameborder: 0, scrolling: 'no', src: '', allowfullscreen: true }).css({ width: width, height: height }), overlay = iframeContainer.find('.bilibili-iframe-overlay'); $title.text((title || 'av' + aid) + ([0, 1].find(page) ? ' (' + page + ')' : '')); iframeContainer.add(overlay.text('正在加载,请稍候……')).css({ width: width, height: height }); self.getCid(aid).then(function(_ref2) { var _ref3 = _slicedToArray(_ref2, 2), list = _ref3[0], Title = _ref3[1]; var _page = 1, name = title || (Title ? Title : 'av' + aid), index = void 0, length = void 0; 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; var idx = _page - 1, href = $title.attr('href'); if (list[index] !== undefined && list[index].VideoCid !== undefined) { iframe.attr('src', 'https://www.bilibili.com/html/html5player.html?cid=' + list[index].VideoCid + '&aid=' + aid + '&page=' + _page + '&enable_ssl=1&as_wide=1' + (autoplay ? '&autoplay' : '')); if (iframeContainer.is(':visible')) self.appendiframe(iframe, iframeContainer); else iframe.data('ready', 'load'); $title.attr('href', href.replace(new RegExp('/index_' + page, 'g'), '/index_' + _page)); if (_page !== 1) name += ' [' + _page + '/' + list.length + ']'; $title.text(name); } else { $title.text(title || 'av' + aid + ' [' + _page + '/' + list.length + ']'); self.error({ $video: $video, mode: 'execError', info: { page: page, _page: _page, list: list, aid: aid } }); } }, function(err) { $title.text((title || 'av' + aid) + ([0, 1].find(page) ? ' (' + page + ')' : '')); self.error({ $video: $video, mode: 'network', info: err }); }); $video.find('.bilibili-toggle').on('click', function() { $(this).closest('tbody').children('.bilibili-video').toggle(); if ($(this).val() === '显示视频') { $(this).val('隐藏视频'); if (iframe.data('ready') === true) self.appendiframe(iframe, iframeContainer); } else $(this).val('显示视频'); })[autoplay ? 'click' : 'data'](); } }, { key: 'getCid', value: function getCid(aid) { var self = this; return new Promise(function(res, rej) { $.ajax({ url: 'https://mgwbcprd.azureedge.net/BilibiliCid/Index/av' + aid, type: 'GET', success: function success(data) { res([data.VideoEntities.map(function(e, i) { e.page = i + 1; e.title = e.Title.replace(/^\d+、/, ''); delete e.Id; delete e.ParentCollectionId; return e; }), data.Title]); }, error: function error(err) { rej(err); } }); }); } }, { key: 'load', value: function load(iframe) { var overlay = iframe.closest('.bilibili-iframe-container').find('.bilibili-iframe-overlay'); iframe.data('load', 'complete'); overlay.text('加载完毕,如果无法观看视频请刷新本页面,如果多次无法观看请到提问求助区反馈。').delay(2000).queue(function() { $(this).fadeOut(370, function() { $(this).remove(); }); $(this).dequeue(); }); } }, { key: 'refresh', value: function refresh(iframe) { var self = this; var container = $(this).closest('.bilibili-iframe-container'), clone = iframe.clone(); iframe.remove(); container.append(clone.on('load', function() { self.load($(this)); })); } }, { key: 'refreshLink', value: function refreshLink(mode, info) { var self = this; return $('<a/>').text('重新加载').on('click', function() { switch (mode) { case 'iframe': { self.refresh($(this).closest('.bilibili-iframe-container').find('iframe')); break; } case 'load': { info.$video.remove('iframe').find('.bilibili-iframe-overlay').text('正在加载,请稍候……'); self.exec(info.$video); } } }); } }, { key: 'validNumber', value: function validNumber(_n) { var n = +_n; if (isNaN(n) || n < 0 || /\./.test(_n)) return false; return true; } }]); return BilibiliWidget; }();