mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add bvid convert
This commit is contained in:
parent
4621ac0a24
commit
64c97402ac
2
@types/global/index.d.ts
vendored
2
@types/global/index.d.ts
vendored
@ -165,6 +165,7 @@ declare global {
|
||||
interface Window {
|
||||
aid: string | undefined
|
||||
cid: string | undefined
|
||||
bvid: string | undefined
|
||||
pageno: string | number | undefined
|
||||
$: JQueryStatic
|
||||
[key: string]: any
|
||||
@ -442,6 +443,7 @@ declare global {
|
||||
recordLiveDanmaku: boolean,
|
||||
foregroundColorMode: '自动' | '白色' | '黑色'
|
||||
preserveEventBanner: boolean
|
||||
bvidConvert: boolean
|
||||
latestVersionLink: string,
|
||||
currentVersion: string,
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -18,6 +18,8 @@
|
||||
"blackboard.vue.min.js": "84A30D5A6F322A3C083FC1100E9FF51233ECD08AFBD89A6449AD2388ACCC8522",
|
||||
"blur-video-control.min.css": "B72FA7AD198ED1C9A9620A83881441F96F9FF3083ED12203A324B9753A7CCFFD",
|
||||
"blur-video-control.min.js": "00A2AC837FC455DF2AED7D0C350265C7438CC6F5C203F085E19639DDB86D0E11",
|
||||
"bvid-convert.min.css": "DC588791A7A191BCBAFD3C166523413101FA992EDEB24B81892D06B9868D67E1",
|
||||
"bvid-convert.min.js": "0D7F799AD10FCD94C0C451264E03FAFF786F0BB9919E9AE6E10D13FD3957B849",
|
||||
"category-regions.min.js": "59666AFFFA63B942AC05B05C95E22BF6D655E3BA7DE3E46D8F86CEC79D0CA904",
|
||||
"clear-cache.min.js": "9AB1536D8278DA681831A589AD1414425BF206B36AE109FB4EC1E8A685BB2A9F",
|
||||
"collapse-live-side-bar.min.css": "22348786547D2D8DB659A306AF2E9C1F2050D66488778C71545AAEF785FD57E6",
|
||||
@ -30,7 +32,7 @@
|
||||
"compact-layout.min.js": "B20609A7CBBDB1845FA0156FB5BE6B1E1A1B8B069EA85F65D16241DD2C12D738",
|
||||
"custom-control-background.min.css": "1981FD2BF3B17ECF33F98D5DEDAF0D32ACBE9532A51FDB70822286991AB98EF3",
|
||||
"custom-control-background.min.js": "2A439B045A51D24F5115DD25995ED37E3D0371A074199FE6C727F2235F39C4D9",
|
||||
"custom-navbar.min.css": "72654016093F6ABE22631C4605AF3C46EB31BF998C6863AC2F651FBE49D38EE6",
|
||||
"custom-navbar.min.css": "F17DB373E033CCBACAB332A24868FED6A010B2E5CA43396C36648D1A7093A01F",
|
||||
"custom-navbar.min.html": "FA6ACF1CA1DB6D3BD2BE310646B89B028756A36BF434BEBABE2BF00789581A09",
|
||||
"custom-navbar.min.js": "8AB481710497558D4A152A6D7E0226FDA78675729A3EFC6AA6AC5B0AA5404D17",
|
||||
"custom-navbar-activities.min.js": "DEC76A6C7527330CAA0B89B400C071E155B64D602A6A118A96BCAC451ED6FDBF",
|
||||
@ -42,7 +44,7 @@
|
||||
"custom-navbar-iframe.min.js": "DBE5844C2AA36057DBD33BBC5724D7D7F881AB15EC45A80228961942CD810A32",
|
||||
"custom-navbar-logo.min.js": "236CCC887A3917A6D4840889B7380B648197765B8CDA27CB233F3F1E3215F7BB",
|
||||
"custom-navbar-messages.min.js": "D7B315A4D8FD9E2EF9C1E40C1F3CA7EC18C5A87AC7A9410049061A0D851868DE",
|
||||
"custom-navbar-search-box.min.js": "3543FE8F7F87E8C8C96CB799A7CBCDA4BE5DB863BD97BC1CF37C2657DCF3AE72",
|
||||
"custom-navbar-search-box.min.js": "36C9187C51A0715BACC9D9E82D6B0733D6C818453D1150F235E9C649E5529E2C",
|
||||
"custom-navbar-settings.min.js": "474924B0C90EE6B3DF924D73DFD02DFC2BCF5BAD1F6A4E539A6263D3A751506C",
|
||||
"custom-navbar-simple-link.min.js": "0960197FB525733551435B07D7B024272C21BDD2D8B4F47027046FCE7B3468C5",
|
||||
"custom-navbar-subscriptions.min.js": "8664608EA96BA5E3CC0202F3ED095823B8D2A3DFCDC6D87C192FEA652D0DD554",
|
||||
|
||||
BIN
min/bundle.zip
BIN
min/bundle.zip
Binary file not shown.
1
min/bvid-convert.min.css
vendored
Normal file
1
min/bvid-convert.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.bvid-convert{border:2px solid #8882;border-radius:8px;padding:6px 8px;margin:4px 0;order:-1;width:100%;box-sizing:border-box}.bvid-convert-item{font-size:14px}
|
||||
1
min/bvid-convert.min.js
vendored
Normal file
1
min/bvid-convert.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(()=>{return(i,n)=>{return{widget:{content:`<div class="bvid-convert"></div>`,condition:async()=>{if(["https://www.bilibili.com/video/","https://www.bilibili.com/bangumi/"].some(i=>document.URL.startsWith(i))){return Boolean(await SpinQuery.select(()=>unsafeWindow.aid||unsafeWindow.bvid))}else{return false}},success:()=>{n.applyStyle("bvidConvertStyle");const i=dq(".bvid-convert");i.innerHTML=`\n<div class="bvid-convert-item">av${unsafeWindow.aid}</div>\n<div class="bvid-convert-item">${unsafeWindow.bvid}</div>\n`}}}}})();
|
||||
2
min/custom-navbar-search-box.min.js
vendored
2
min/custom-navbar-search-box.min.js
vendored
File diff suppressed because one or more lines are too long
2
min/custom-navbar.min.css
vendored
2
min/custom-navbar.min.css
vendored
File diff suppressed because one or more lines are too long
@ -850,5 +850,12 @@ Resource.manifest = {
|
||||
downloadLiveRecords: '下载直播录像',
|
||||
},
|
||||
},
|
||||
bvidConvert: {
|
||||
path: 'bvid-convert.min.js',
|
||||
style: true,
|
||||
displayNames: {
|
||||
bvidConvert: 'BV号转换',
|
||||
},
|
||||
},
|
||||
}
|
||||
export const resourceManifest = Resource.manifest
|
||||
|
||||
@ -218,6 +218,7 @@ export const settings = {
|
||||
foregroundColorMode: '自动',
|
||||
preserveEventBanner: false,
|
||||
about: true,
|
||||
bvidConvert: true,
|
||||
cache: {},
|
||||
}
|
||||
const fixedSettings = {
|
||||
|
||||
@ -844,6 +844,22 @@ li.nav-item[report-id="playpage_dynamic"] .i-frame,
|
||||
color: var(--theme-color);
|
||||
font-style: normal;
|
||||
}
|
||||
.copy-tip {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
left: 50%;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(-8px);
|
||||
border-radius: 4px;
|
||||
background-color: #000a;
|
||||
color: #fff;
|
||||
padding: 6px 8px;
|
||||
&.show {
|
||||
transform: translateX(-50%) translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.search-list-item {
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@ -46,6 +46,35 @@ const originalHistory = new class {
|
||||
}
|
||||
}
|
||||
}
|
||||
const getIdJump = (text: string) => {
|
||||
const avMatch = text.match(/^av([\d]+)$/i)
|
||||
if (avMatch) {
|
||||
return {
|
||||
success: true,
|
||||
text,
|
||||
link: `https://www.bilibili.com/av${avMatch[1]}`,
|
||||
aid: avMatch[1],
|
||||
bvid: ''
|
||||
}
|
||||
}
|
||||
const bvidMatch = text.match(/^bv[\da-zA-Z]+$/i)
|
||||
if (bvidMatch) {
|
||||
return {
|
||||
success: true,
|
||||
text,
|
||||
link: `https://www.bilibili.com/${text.replace(/^bv/i, 'BV')}`,
|
||||
aid: '',
|
||||
bvid: text.replace(/^bv/i, 'BV'),
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
text,
|
||||
link: '',
|
||||
aid: '',
|
||||
bvid: '',
|
||||
}
|
||||
}
|
||||
export class SearchBox extends NavbarComponent {
|
||||
constructor() {
|
||||
super()
|
||||
@ -92,9 +121,12 @@ export class SearchBox extends NavbarComponent {
|
||||
@keydown.enter="clearSearchHistory()"
|
||||
@keydown.down.prevent="nextItem(items.length)"
|
||||
@keydown.up.prevent="previousItem(items.length)">
|
||||
<i class="mdi mdi-18px mdi-delete-sweep"></i>
|
||||
清除搜索历史
|
||||
</div>
|
||||
<i class="mdi mdi-18px mdi-delete-sweep"></i>
|
||||
清除搜索历史
|
||||
</div>
|
||||
<div class="copy-tip" :class="{show: showCopyTip}">
|
||||
已复制
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
this.init()
|
||||
@ -110,22 +142,12 @@ export class SearchBox extends NavbarComponent {
|
||||
e.preventDefault()
|
||||
return false
|
||||
}
|
||||
if (/^av[\d]+$/i.test(keywordInput.value)) {
|
||||
window.open(`https://www.bilibili.com/${keywordInput.value.toLowerCase()}`, '_blank')
|
||||
const idJump = getIdJump(keywordInput.value)
|
||||
if (idJump.success) {
|
||||
window.open(idJump.link, '_blank')
|
||||
e.preventDefault()
|
||||
return false
|
||||
}
|
||||
if (/^bv[\da-zA-Z]+$/i.test(keywordInput.value)) {
|
||||
window.open(`https://www.bilibili.com/${keywordInput.value.replace(/^bv/i, 'BV')}`, '_blank')
|
||||
e.preventDefault()
|
||||
return false
|
||||
}
|
||||
// const now = Number(new Date())
|
||||
// if (keywordInput.value === '拜年祭' && Number(new Date('2020-01-17')) < now && now < Number(new Date('2020-02-01'))) {
|
||||
// window.open(`https://www.bilibili.com/blackboard/xianxing2020bnj.html`)
|
||||
// e.preventDefault()
|
||||
// return false
|
||||
// }
|
||||
const historyItem = settings.searchHistory.find(item => item.keyword === keywordInput.value)
|
||||
if (historyItem) {
|
||||
historyItem.count++
|
||||
@ -168,14 +190,25 @@ export class SearchBox extends NavbarComponent {
|
||||
data: {
|
||||
items: [] as SuggestItem[],
|
||||
isHistory: true,
|
||||
showCopyTip: false,
|
||||
},
|
||||
methods: {
|
||||
closeCopyTip: _.debounce(function () { this.showCopyTip = false }, 2000),
|
||||
copy(value: string) {
|
||||
GM.setClipboard(value, 'text')
|
||||
this.showCopyTip = true
|
||||
this.closeCopyTip()
|
||||
},
|
||||
submit(value: string) {
|
||||
keywordInput.value = value
|
||||
form.submit()
|
||||
// submit method will not trigger submit event
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
||||
raiseEvent(form, 'submit')
|
||||
if (getIdJump(value).success) {
|
||||
this.copy(value)
|
||||
} else {
|
||||
keywordInput.value = value
|
||||
form.submit()
|
||||
// submit method will not trigger submit event
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
||||
raiseEvent(form, 'submit')
|
||||
}
|
||||
},
|
||||
nextItem(index: number) {
|
||||
const item = dq(`.custom-navbar .search-list-item:nth-child(${index + 2})`) as HTMLElement
|
||||
@ -193,6 +226,9 @@ export class SearchBox extends NavbarComponent {
|
||||
}
|
||||
},
|
||||
deleteItem(item: SuggestItem, index: number) {
|
||||
if (keywordInput.value !== '') {
|
||||
return
|
||||
}
|
||||
const historyIndex = settings.searchHistory.findIndex(it => it.keyword === item.value)
|
||||
const [historyItem] = settings.searchHistory.splice(historyIndex, 1)
|
||||
// originalHistory.remove(historyItem)
|
||||
@ -210,6 +246,7 @@ export class SearchBox extends NavbarComponent {
|
||||
const updateSuggest = async () => {
|
||||
const text = keywordInput.value
|
||||
searchList.isHistory = text === ''
|
||||
const idJump = getIdJump(text)
|
||||
if (searchList.isHistory) {
|
||||
// searchList.items = originalHistory.merge(settings.searchHistory)
|
||||
searchList.items = settings.searchHistory
|
||||
@ -224,6 +261,39 @@ export class SearchBox extends NavbarComponent {
|
||||
html: item.keyword,
|
||||
}
|
||||
}).slice(0, 10)
|
||||
} else if (idJump.success) {
|
||||
searchList.items = []
|
||||
const url = idJump.aid ? `https://api.bilibili.com/x/web-interface/view?aid=${idJump.aid}` : `https://api.bilibili.com/x/web-interface/view?bvid=${idJump.bvid}`
|
||||
const json = await Ajax.getJson(url)
|
||||
if (idJump.aid) {
|
||||
const bvid = _.get(json, 'data.bvid', null)
|
||||
if (bvid !== null) {
|
||||
searchList.items = [
|
||||
{
|
||||
value: bvid,
|
||||
html: `复制BV号: ${bvid}`,
|
||||
},
|
||||
// {
|
||||
// value: `https://www.bilibili.com/${bvid}`,
|
||||
// html: `复制BV号链接: https://.../${bvid}`,
|
||||
// }
|
||||
]
|
||||
}
|
||||
} else if (idJump.bvid) {
|
||||
const aid = _.get(json, 'data.aid', null)
|
||||
if (aid !== null) {
|
||||
searchList.items = [
|
||||
{
|
||||
value: 'av' + aid,
|
||||
html: `复制AV号: av${aid}`,
|
||||
},
|
||||
// {
|
||||
// value: `https://www.bilibili.com/av${aid}`,
|
||||
// html: `复制AV号链接: https://.../av${aid}`,
|
||||
// }
|
||||
]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const url = `https://s.search.bilibili.com/main/suggest?func=suggest&suggest_type=accurate&sub_type=tag&main_ver=v1&highlight=&userid=${getUID()}&bangumi_acc_num=1&special_acc_num=1&topic_acc_num=1&upuser_acc_num=3&tag_num=10&special_num=10&bangumi_num=10&upuser_num=3&term=${text}`
|
||||
lastQueuedRequest = url
|
||||
|
||||
12
src/video/bvid-convert/bvid-convert.scss
Normal file
12
src/video/bvid-convert/bvid-convert.scss
Normal file
@ -0,0 +1,12 @@
|
||||
.bvid-convert {
|
||||
border: 2px solid #8882;
|
||||
border-radius: 8px;
|
||||
padding: 6px 8px;
|
||||
margin: 4px 0;
|
||||
order: -1;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
&-item {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
23
src/video/bvid-convert/bvid-convert.ts
Normal file
23
src/video/bvid-convert/bvid-convert.ts
Normal file
@ -0,0 +1,23 @@
|
||||
export default {
|
||||
widget: {
|
||||
content: /*html*/`<div class="bvid-convert"></div>`,
|
||||
condition: async () => {
|
||||
if ([
|
||||
'https://www.bilibili.com/video/',
|
||||
'https://www.bilibili.com/bangumi/',
|
||||
].some(it => document.URL.startsWith(it))) {
|
||||
return Boolean(await SpinQuery.select(() => unsafeWindow.aid || unsafeWindow.bvid))
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
success: () => {
|
||||
resources.applyStyle('bvidConvertStyle')
|
||||
const label = dq('.bvid-convert') as HTMLDivElement
|
||||
label.innerHTML = /*html*/`
|
||||
<div class="bvid-convert-item">av${unsafeWindow.aid}</div>
|
||||
<div class="bvid-convert-item">${unsafeWindow.bvid}</div>
|
||||
`
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user