This commit is contained in:
the1812 2022-01-16 00:21:41 +08:00
parent a26b1df1d7
commit de2fe7999c
4 changed files with 40 additions and 36 deletions

View File

@ -0,0 +1 @@
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["video/av-url"]=o():e["video/av-url"]=o()}(self,(function(){return function(){"use strict";var e={d:function(o,t){for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:function(e,o){return Object.prototype.hasOwnProperty.call(e,o)}},o={};e.d(o,{component:function(){return c}});var t=coreApis.lifeCycle,n=coreApis.observer,r=coreApis.spinQuery,i=coreApis.utils.urls;const c={name:"avUrl",displayName:"网址AV号转换",description:{"zh-CN":"当视频的链接是BV号时, 自动转换为AV号. 请注意这会导致浏览器历史记录出现重复的标题 (分别是转换前后的网址)."},entry:()=>{(0,t.fullyLoaded)((()=>{(0,n.urlChange)((async()=>{const e=await(0,r.select)((()=>unsafeWindow.aid));if(!e)return;if(document.URL.includes("videocard_series"))return void console.log("skip video series");const o=document.URL.replace(/\/(video|bangumi)\/(BV[\w]+)/i,((o,t)=>`/${t}/av${e}`));document.URL!==o&&window.history.replaceState({},document.title,o)}))}))},tags:[componentsTags.video,componentsTags.utils],urlInclude:i.videoUrls,commitHash:"a26b1df1d76028e59d2fd82339df44545175ea31"};return o=o.component}()}));

View File

@ -89,9 +89,7 @@ const entry = async () => {
const { fullyLoaded } = await import('@/core/life-cycle')
const { urlChange } = await import('@/core/observer')
fullyLoaded(() => {
if (document.contentType === 'text/html') {
urlChange(() => clean())
}
urlChange(() => clean())
})
}
export const component: ComponentMetadata = {
@ -99,7 +97,7 @@ export const component: ComponentMetadata = {
displayName: '网址参数清理',
entry,
description: {
'zh-CN': '自动删除网址中的多余跟踪参数.',
'zh-CN': '自动删除网址中的多余跟踪参数. 请注意这会导致浏览器历史记录出现重复的标题 (分别是转换前后的网址).',
},
tags: [
componentsTags.utils,

View File

@ -0,0 +1,37 @@
import { ComponentMetadata } from '@/components/types'
import { fullyLoaded } from '@/core/life-cycle'
import { urlChange } from '@/core/observer'
import { select } from '@/core/spin-query'
import { videoUrls } from '@/core/utils/urls'
export const component: ComponentMetadata = {
name: 'avUrl',
displayName: '网址AV号转换',
description: {
'zh-CN': '当视频的链接是BV号时, 自动转换为AV号. 请注意这会导致浏览器历史记录出现重复的标题 (分别是转换前后的网址).',
},
entry: () => {
fullyLoaded(() => {
urlChange(async () => {
const aid = await select(() => unsafeWindow.aid)
if (!aid) {
return
}
if (document.URL.includes('videocard_series')) {
// 系列视频不能转换, 否则会无限刷新
console.log('skip video series')
return
}
const newUrl = document.URL.replace(/\/(video|bangumi)\/(BV[\w]+)/i, (_, type) => `/${type}/av${aid}`)
if (document.URL !== newUrl) {
window.history.replaceState({}, document.title, newUrl)
}
})
})
},
tags: [
componentsTags.video,
componentsTags.utils,
],
urlInclude: videoUrls,
}

View File

@ -1,32 +0,0 @@
import { ComponentMetadata } from '@/components/types'
export const component: ComponentMetadata = {
name: 'avUrl',
displayName: '网址AV号转换',
description: {
'zh-CN': '当视频的链接是BV号时, 自动转换为AV号.',
},
entry: async () => {
const { select } = await import('@/core/spin-query')
const aid = await select(() => unsafeWindow.aid)
if (!aid) {
return
}
if (document.URL.includes('videocard_series')) {
// 系列视频不能转换, 否则会无限刷新
console.log('skip video series')
return
}
const newUrl = document.URL.replace(/\/(video|bangumi)\/(BV[\w]+)/i, (_, type) => `/${type}/av${aid}`)
if (document.URL !== newUrl) {
window.history.replaceState({}, document.title, newUrl)
}
},
tags: [
componentsTags.video,
componentsTags.utils,
],
urlInclude: [
/^https:\/\/www\.bilibili\.com\/video\/BV/i,
],
}