mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
fix: get suggestion not working
This commit is contained in:
@@ -2,8 +2,12 @@ import browser from 'webextension-polyfill'
|
||||
|
||||
function handleMessage(message: any) {
|
||||
if (message.contentScriptQuery === 'getSearchSuggestion') {
|
||||
const url = `https://s.search.bilibili.com/main/suggest?term=${message.term}`
|
||||
return fetch(url)
|
||||
// https://s.search.bilibili.com/main/suggest?func=suggest&suggest_type=accurate&sub_type=tag&main_ver=v1&highlight=&userid=&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=d&rnd=0.7285191795638684&buvid=40F8F3A8-86A1-56D8-1441-81A406B6D83127491infoc
|
||||
const url = `https://s.search.bilibili.com/main/suggest?func=suggest&suggest_type=accurate&sub_type=tag&main_ver=v1&highlight=&userid=&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=${message.term}&buvid=40F8F3A8-86A1-56D8-1441-81A406B6D83127491infoc`
|
||||
return fetch(url, {
|
||||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => (data))
|
||||
.catch(error => console.error(error))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { watchOnce } from '@vueuse/core'
|
||||
import type { HistoryItem, SuggestionItem } from './searchHistoryProvider'
|
||||
import type { HistoryItem, SuggestionItem, SuggestionResponse } from './searchHistoryProvider'
|
||||
import {
|
||||
addSearchHistory,
|
||||
clearSearchHistory,
|
||||
@@ -30,8 +29,10 @@ function handleInput() {
|
||||
contentScriptQuery: 'getSearchSuggestion',
|
||||
term: keyword.value,
|
||||
})
|
||||
.then((res) => {
|
||||
Object.assign(suggestions, res)
|
||||
.then((res: SuggestionResponse) => {
|
||||
if (!res || (res && res.code !== 0))
|
||||
return
|
||||
Object.assign(suggestions, res.result.tag)
|
||||
})
|
||||
}
|
||||
else {
|
||||
@@ -128,9 +129,9 @@ function handleClearSearchHistory() {
|
||||
searchHistory.value = []
|
||||
}
|
||||
|
||||
watchOnce(isFocus, async (focus) => {
|
||||
watch(isFocus, async (focus) => {
|
||||
// 延后加载搜索历史
|
||||
if (focus && searchHistory.value.length === 0)
|
||||
if (focus)
|
||||
searchHistory.value = await getSearchHistory()
|
||||
})
|
||||
</script>
|
||||
@@ -175,7 +176,7 @@ watchOnce(isFocus, async (focus) => {
|
||||
transition="all duration-300"
|
||||
type="text"
|
||||
@focus="isFocus = true"
|
||||
@input="handleInput()"
|
||||
@input="handleInput"
|
||||
@keyup.enter="navigateToSearchResultPage(keyword)"
|
||||
@keyup.up.stop="handleKeyUp"
|
||||
@keyup.down.stop="handleKeyDown"
|
||||
|
||||
@@ -8,8 +8,21 @@ export interface HistoryItem {
|
||||
}
|
||||
export interface SuggestionItem {
|
||||
value: string
|
||||
term: string
|
||||
name: string
|
||||
type: string
|
||||
ref: number
|
||||
spid: number
|
||||
timestamp: number
|
||||
}
|
||||
export interface SuggestionResponse {
|
||||
code: number
|
||||
exp_str: string
|
||||
result: {
|
||||
tag: SuggestionItem[]
|
||||
}
|
||||
stoken: string
|
||||
}
|
||||
export interface StorageEvent {
|
||||
type: 'COLS_RES'
|
||||
id?: string
|
||||
|
||||
Reference in New Issue
Block a user