diff --git a/package.json b/package.json index f2197ff..7acc14c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bilibili-helper-master", - "version": "1.2.14", + "version": "1.2.16-beta.1", "description": "bilibili-helper", "main": "index.js", "dependencies": { diff --git a/src/js/libs/messageStore.js b/src/js/libs/messageStore.js index 0ab56fb..6f3e6ad 100644 --- a/src/js/libs/messageStore.js +++ b/src/js/libs/messageStore.js @@ -36,9 +36,11 @@ export class MessageStore { this.has(tabId) && removeInfo.isWindowClosing && this.delete(tabId); }); chrome.tabs.onUpdated.addListener((tabId, changeInfo) => { - const {status, url} = changeInfo; + const {status, url, favIconUrl, audible} = changeInfo; // 切换分P时url!==undefined,不需要清除 - if (this.has(tabId) && status === 'loading' && url === undefined) { this.delete(tabId); } else if (this.has(tabId) && status === 'complete') { + if (this.has(tabId) && status === 'loading' && url === undefined && !favIconUrl && audible === undefined) { + this.delete(tabId); + } else if (this.has(tabId) && status === 'complete' && !favIconUrl && audible === undefined) { this.createData(tabId); } }); @@ -49,10 +51,13 @@ export class MessageStore { * @param id * @return {{state, queue, data}} */ - createData = (id) => { - if (this.has(id)) { return this.store[id]; } else { + createData = (id, frameId) => { + const storeId = this.createStoreId(id, frameId); + if (this.has(storeId)) { + return this.store[storeId]; + } else { //console.warn(`Create MessageStore on Tab ${id}`); - return this.store[id] = { + return this.store[storeId] = { state: 0, // 初始状态 0 等待前端信号 queue: [], // 任务队列 data: {id}, // 数据对象 存储如cid之类的数据 @@ -60,11 +65,13 @@ export class MessageStore { } }; - has = (id) => !!this.store[id]; + createStoreId = (id, frameId) => `${id}${frameId ? '-' + frameId : ''}`; - get = (id) => this.store[id]; + has = storeId => !!this.store[storeId]; - delete = (id) => delete this.store[id]; + get = storeId => this.store[storeId]; + + delete = storeId => delete this.store[storeId]; doIt = (id, taskData) => { if (!taskData) { return Promise.resolve(); } @@ -76,15 +83,17 @@ export class MessageStore { }; // 处理任务队列 - dealWith = (id) => { - return this.dealWithOnce(id).then(() => { - this.store[id].queue.length > 0 && this.dealWithOnce(id); // 如果队列不为空 + dealWith = (id, frameId) => { + const storeId = this.createStoreId(id, frameId); + return this.dealWithOnce(id, frameId).then(() => { + this.store[storeId] && this.store[storeId].queue.length > 0 && this.dealWithOnce(id); // 如果队列不为空 }); }; - dealWithOnce = (id) => { - if (this.has[id] === false) { return Promise.resolve(console.error(`Invalid tab id ${id}`)); } - const {state, queue} = this.store[id]; + dealWithOnce = (id, frameId) => { + const storeId = this.createStoreId(id, frameId); + if (this.has[storeId] === false) { return Promise.resolve(console.error(`Invalid store id ${storeId}`)); } + const {state, queue} = this.store[storeId]; if (state && queue.length > 0) { return this.doIt(id, queue.shift()).catch((error) => console.error(error)); } else { return Promise.resolve(); } diff --git a/src/js/modules/danmu/UI/danmu.js b/src/js/modules/danmu/UI/danmu.js index c169a6f..16daf5f 100644 --- a/src/js/modules/danmu/UI/danmu.js +++ b/src/js/modules/danmu/UI/danmu.js @@ -181,6 +181,11 @@ export default () => { componentDidMount() { chrome.runtime.sendMessage({command: 'danmuDOMInitialized'}); + $('.player-sidebar-list-item-inner, .bnj-player-single-item-mask').click(() => { + setTimeout(() => { + chrome.runtime.sendMessage({command: 'danmuDOMInitialized'}); + }, 500); + }); } addListener = () => { diff --git a/src/js/modules/danmu/index.js b/src/js/modules/danmu/index.js index cad2056..fa0966c 100644 --- a/src/js/modules/danmu/index.js +++ b/src/js/modules/danmu/index.js @@ -42,7 +42,6 @@ export class Danmu extends Feature { chrome.webRequest.onSendHeaders.addListener((details) => { const {tabId, initiator, requestHeaders} = details; const fromHelper = !_.isEmpty(_.find(requestHeaders, ({name, value}) => name === 'From' && value === 'bilibili-helper')); - console.warn(details); if (/^chrome-extension:\/\//.test(initiator) || fromHelper) { return; } @@ -99,7 +98,7 @@ export class Danmu extends Feature { const url = (window.URL ? URL : window.webkitURL).createObjectURL(new Blob([message.danmuDocumentStr], { type: 'application/xml', })); - const filename = `${message.filename}.${message.cid}.${message.date}.xml`; + const filename = `${message.filename ? message.filename + '.' : ''}${message.cid}.${message.date}.xml`; chrome.downloads.download({ saveAs: true, url, @@ -116,7 +115,7 @@ export class Danmu extends Feature { const url = (window.URL ? URL : window.webkitURL).createObjectURL(new Blob([assData], { type: 'application/octet-stream', })); - const filename = `${message.filename}.${message.cid}.${message.date}.ass`; + const filename = `${message.filename ? message.filename + '.' : ''}${message.cid}.${message.date}.ass`; chrome.downloads.download({ saveAs: true, url, diff --git a/src/js/modules/pictureInPicture/UI/PIP.js b/src/js/modules/pictureInPicture/UI/PIP.js index 7ef000a..ae56edb 100644 --- a/src/js/modules/pictureInPicture/UI/PIP.js +++ b/src/js/modules/pictureInPicture/UI/PIP.js @@ -42,7 +42,8 @@ export default () => { const that = this; this.video = document.querySelector('#bofqi .bilibili-player-video video'); this.addListener(this.video); - document.querySelector('#bofqi').addEventListener('DOMNodeInserted', function(e) { + const player = document.querySelector('#bofqi'); + player && player.addEventListener('DOMNodeInserted', function(e) { if (e.target.localName === 'video' && that.video !== e.target) { that.video = e.target; that.addListener(that.video); diff --git a/src/js/modules/videoAnchor/UI/index.js b/src/js/modules/videoAnchor/UI/index.js index cc6b0ce..9e58875 100644 --- a/src/js/modules/videoAnchor/UI/index.js +++ b/src/js/modules/videoAnchor/UI/index.js @@ -26,7 +26,7 @@ export class VideoAnchorUI extends UI { '#arc_toolbar_report', '#viewlater-app .video-toolbar-module', ]; - const newPage = document.querySelector('.video-data, .stardust-player'); + const newPage = document.querySelector('.video-data, .stardust-player, iframe.bnj-player-main'); const addUI = (container, callback) => { if (document.querySelector('.bilibili-helper')) return; const helperDOM = document.createElement('span'); diff --git a/src/js/modules/videoDownload/UI/videoDownload.js b/src/js/modules/videoDownload/UI/videoDownload.js index b3fa896..7ec0261 100644 --- a/src/js/modules/videoDownload/UI/videoDownload.js +++ b/src/js/modules/videoDownload/UI/videoDownload.js @@ -145,6 +145,11 @@ export default () => { }, (settings) => { this.setState({settings}); }); + $('.player-sidebar-list-item-inner, .bnj-player-single-item-mask').click(() => { + setTimeout(() => { + chrome.runtime.sendMessage({command: 'videoDownloadDOMInitialized'}); + }, 500); + }); } getContainer = (type, currentCid, currentQuality, data) => { @@ -217,11 +222,16 @@ export default () => { sendResponse(true); } else if (message.command === 'videoDownloadCid' && message.cid) { // 本地script加载视频数据时,需要检测cid const {videoData} = this.state; - if (_.isEmpty(videoData) && !_.isEmpty(this.originVideoData)) { - const {quality} = this.originVideoData; + if (_.isEmpty(videoData)) { + const {quality = 80} = this.originVideoData; this.currentAvid = message.avid; - if (this.originVideoData.dash) { - + if (!_.isEmpty(this.originVideoData) && this.originVideoData.durl) { + const currentData = {...this.originVideoData}; + const cidData = videoData[message.cid] || {}; + cidData[quality] = currentData; + videoData[message.cid] = cidData; + this.setState({currentCid: message.cid, videoData, currentQuality: quality}); + } else { let url = null; if (location.href.indexOf('bangumi') >= 0) { url = new Url(bangumiFlvDownloadURL); @@ -231,12 +241,6 @@ export default () => { url.set('query', {cid: message.cid, avid: message.avid, qn: quality, otype: 'json'}); this.setState({currentCid: message.cid}); this.getFlvResponse('get', url.toString()); - } else { - const currentData = {...this.originVideoData}; - const cidData = videoData[message.cid] || {}; - cidData[quality] = currentData; - videoData[message.cid] = cidData; - this.setState({currentCid: message.cid, videoData, currentQuality: quality}); } } sendResponse(true); diff --git a/src/js/modules/videoDownload/index.js b/src/js/modules/videoDownload/index.js index d458e91..195d1e3 100644 --- a/src/js/modules/videoDownload/index.js +++ b/src/js/modules/videoDownload/index.js @@ -56,8 +56,8 @@ export class VideoDownload extends Feature { '*://api.bilibili.com/pgc/player/web/playurl?avid=*', // 新番剧页面 '*://api.bilibili.com/x/player/playurl*', // 新版页面切换清晰度时调用,返回字段和上面相同 - '*://interface.bilibili.com/player?id=cid:*', - '*://api.bilibili.com/x/player.so?id=cid:*', + '*://interface.bilibili.com/player?id=cid*', + '*://api.bilibili.com/x/player.so?id=cid*', '*://api.bilibili.com/x/web-interface/view?*', // 获取cid和aid ], }; diff --git a/src/js/modules/videoHideDanmu/UI/index.js b/src/js/modules/videoHideDanmu/UI/index.js index 4b3b407..2f411fc 100644 --- a/src/js/modules/videoHideDanmu/UI/index.js +++ b/src/js/modules/videoHideDanmu/UI/index.js @@ -22,7 +22,8 @@ export class VideoHideDanmuUI extends UI { } return new Promise(resolve => { this.hide(); - new MutationObserver((mutationList) => { + const player = document.querySelector('#bofqi'); + player && new MutationObserver((mutationList) => { mutationList.forEach((mutation) => { if (mutation.addedNodes.length > 0) { mutation.addedNodes.forEach((dom) => { @@ -34,7 +35,7 @@ export class VideoHideDanmuUI extends UI { }); } }); - }).observe(document.querySelector('#bofqi'), { + }).observe(player, { subtree: true, childList: true, }); diff --git a/src/js/modules/videoWiden/UI/index.js b/src/js/modules/videoWiden/UI/index.js index 1d8e707..06396ca 100644 --- a/src/js/modules/videoWiden/UI/index.js +++ b/src/js/modules/videoWiden/UI/index.js @@ -15,21 +15,27 @@ export class VideoWidenUI extends UI { } load = (containers, settings) => { - if (!settings.on) return Promise.resolve(); + if (!settings.on) { + return Promise.resolve(); + } return new Promise(resolve => { const option = settings.subPage.value; this.setWide(option); - new MutationObserver((mutationList) => { - _.map(mutationList, (mutation) => { - if (mutation.oldValue) { - this.setWide(option); - } + const player = document.querySelector('#bofqi'); + if (player) { + + new MutationObserver((mutationList) => { + _.map(mutationList, (mutation) => { + if (mutation.oldValue) { + this.setWide(option); + } + }); + }).observe(player, { + attributes: true, + attributeOldValue: true, + subtree: true, }); - }).observe(document.querySelector('#bofqi'), { - attributes: true, - attributeOldValue: true, - subtree: true, - }); + } resolve(); }); }; diff --git a/src/js/utils/functions.js b/src/js/utils/functions.js index b10a41d..2e31664 100644 --- a/src/js/utils/functions.js +++ b/src/js/utils/functions.js @@ -84,8 +84,8 @@ export const getLink = (url_name) => { export const getFilename = (doc) => { const partDOM = doc.querySelector('#v_multipage a.on, #multi_page .cur-list li.on a, #eplist_module .list-wrapper ul .cursor'); const partName = partDOM ? partDOM.innerText : ''; - const title = doc.querySelector('#viewbox_report h1, .header-info h1, .media-wrapper > h1, h1.video-title').getAttribute('title'); - return `${title}${partName ? `_${partName}` : ''}`.replace(/\s/g, '').replace(/[|"*?:<>\s~/]/g, '_'); + const title = doc.querySelector('#viewbox_report h1, .header-info h1, .media-wrapper > h1, h1.video-title'); + return `${title ? title.getAttribute('title') : ''}${partName ? `_${partName}` : ''}`.replace(/\s/g, '').replace(/[|"*?:<>\s~/]/g, '_'); }; /** diff --git a/src/manifest.json b/src/manifest.json index c581a58..e3d3f8c 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,5 +1,5 @@ { - "version": "1.2.14", + "version": "1.2.16.1", "update_url": "https://clients2.google.com/service/update2/crx", "manifest_version": 2, "minimum_chrome_version": "56.0.0", @@ -45,7 +45,8 @@ "*://*.bilibili.com/bangumi/play/ep*", "*://*.bilibili.com/video/av*", "*://www.bilibili.com/watchlater/*", - "*://www.bilibili.com/medialist/*" + "*://www.bilibili.com/medialist/*", + "*://www.bilibili.com/blackboard/*" ], "run_at": "document_end" },