You've already forked bilibili-subtitle
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["https://www.bilibili.com/video/*"],
|
"matches": ["https://www.bilibili.com/video/*", "https://www.bilibili.com/list/watchlater*"],
|
||||||
"js": ["src/chrome/content-script.cjs"]
|
"js": ["src/chrome/content-script.cjs"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
const {TOTAL_HEIGHT_DEF, HEADER_HEIGHT, TOTAL_HEIGHT_MIN, TOTAL_HEIGHT_MAX} = require("../const");
|
const {TOTAL_HEIGHT_DEF, HEADER_HEIGHT, TOTAL_HEIGHT_MIN, TOTAL_HEIGHT_MAX, IFRAME_ID} = require("../const");
|
||||||
var totalHeight = TOTAL_HEIGHT_DEF
|
var totalHeight = TOTAL_HEIGHT_DEF
|
||||||
|
|
||||||
const getVideoElement = () => {
|
const getVideoElement = () => {
|
||||||
@@ -23,7 +23,7 @@ setInterval(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const iframe = document.createElement('iframe')
|
const iframe = document.createElement('iframe')
|
||||||
iframe.id = 'bilibili-subtitle-iframe'
|
iframe.id = IFRAME_ID
|
||||||
iframe.src = chrome.runtime.getURL('index.html')
|
iframe.src = chrome.runtime.getURL('index.html')
|
||||||
iframe.style = 'border: none; width: 100%; height: 44px;'
|
iframe.style = 'border: none; width: 100%; height: 44px;'
|
||||||
iframe.allow = 'clipboard-read; clipboard-write;'
|
iframe.allow = 'clipboard-read; clipboard-write;'
|
||||||
@@ -43,15 +43,24 @@ let pagesMap = {}
|
|||||||
|
|
||||||
let lastAidOrBvid = null
|
let lastAidOrBvid = null
|
||||||
const refreshVideoInfo = async () => {
|
const refreshVideoInfo = async () => {
|
||||||
const iframe = document.getElementById('bilibili-subtitle-iframe')
|
const iframe = document.getElementById(IFRAME_ID)
|
||||||
if (!iframe) return
|
if (!iframe) return
|
||||||
|
|
||||||
|
// fix: https://github.com/IndieKKY/bilibili-subtitle/issues/5
|
||||||
|
// 处理稍后再看的url( https://www.bilibili.com/list/watchlater?bvid=xxx&oid=xxx )
|
||||||
|
const pathSearchs = {}
|
||||||
|
location.search.slice(1).replace(/([^=&]*)=([^=&]*)/g, (matchs, a, b, c) => pathSearchs[a] = b)
|
||||||
|
|
||||||
|
// bvid
|
||||||
|
let aidOrBvid = pathSearchs.bvid // 默认为稍后再看
|
||||||
|
if (!aidOrBvid) {
|
||||||
let path = location.pathname
|
let path = location.pathname
|
||||||
if (path.endsWith('/')) {
|
if (path.endsWith('/')) {
|
||||||
path = path.slice(0, -1)
|
path = path.slice(0, -1)
|
||||||
}
|
}
|
||||||
const paths = path.split('/')
|
const paths = path.split('/')
|
||||||
const aidOrBvid = paths[paths.length - 1]
|
aidOrBvid = paths[paths.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
if (aidOrBvid !== lastAidOrBvid) {
|
if (aidOrBvid !== lastAidOrBvid) {
|
||||||
// console.debug('refreshVideoInfo')
|
// console.debug('refreshVideoInfo')
|
||||||
@@ -100,7 +109,7 @@ const refreshVideoInfo = async () => {
|
|||||||
let lastAid = null
|
let lastAid = null
|
||||||
let lastCid = null
|
let lastCid = null
|
||||||
const refreshSubtitles = () => {
|
const refreshSubtitles = () => {
|
||||||
const iframe = document.getElementById('bilibili-subtitle-iframe')
|
const iframe = document.getElementById(IFRAME_ID)
|
||||||
if (!iframe) return
|
if (!iframe) return
|
||||||
|
|
||||||
const urlSearchParams = new URLSearchParams(window.location.search)
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
||||||
@@ -135,7 +144,7 @@ window.addEventListener("message", (event) => {
|
|||||||
const {data} = event
|
const {data} = event
|
||||||
|
|
||||||
if (data.type === 'fold') {
|
if (data.type === 'fold') {
|
||||||
const iframe = document.getElementById('bilibili-subtitle-iframe')
|
const iframe = document.getElementById(IFRAME_ID)
|
||||||
iframe.style.height = (data.fold ? HEADER_HEIGHT : totalHeight) + 'px'
|
iframe.style.height = (data.fold ? HEADER_HEIGHT : totalHeight) + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
export const APP_DOM_ID = 'bilibili-subtitle'
|
export const APP_DOM_ID = 'bilibili-subtitle'
|
||||||
|
|
||||||
|
export const IFRAME_ID = 'bilibili-subtitle-iframe'
|
||||||
|
|
||||||
export const STORAGE_ENV = 'bilibili-subtitle_env'
|
export const STORAGE_ENV = 'bilibili-subtitle_env'
|
||||||
|
|
||||||
export const EVENT_EXPAND = 'expand'
|
export const EVENT_EXPAND = 'expand'
|
||||||
|
Reference in New Issue
Block a user