mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Filter IME compose in search suggestions
This commit is contained in:
parent
1bb36ced26
commit
0b29828d87
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
min/custom-navbar.min.js
vendored
2
min/custom-navbar.min.js
vendored
File diff suppressed because one or more lines are too long
@ -705,22 +705,22 @@ class SearchBox extends NavbarComponent {
|
|||||||
}
|
}
|
||||||
async init () {
|
async init () {
|
||||||
const form = await SpinQuery.select("#custom-navbar-search");
|
const form = await SpinQuery.select("#custom-navbar-search");
|
||||||
const keyword = form.querySelector("input[name='keyword']");
|
const keywordInput = form.querySelector("input[name='keyword']");
|
||||||
form.addEventListener("submit", e => {
|
form.addEventListener("submit", e => {
|
||||||
if (keyword.value === "") {
|
if (keywordInput.value === "") {
|
||||||
if (!settings.hideTopSearch) {
|
if (!settings.hideTopSearch) {
|
||||||
form.querySelector(".recommended-target").click();
|
form.querySelector(".recommended-target").click();
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const historyItem = settings.searchHistory.find(item => item.keyword === keyword.value)
|
const historyItem = settings.searchHistory.find(item => item.keyword === keywordInput.value)
|
||||||
if (historyItem) {
|
if (historyItem) {
|
||||||
historyItem.count++
|
historyItem.count++
|
||||||
} else {
|
} else {
|
||||||
settings.searchHistory.push({
|
settings.searchHistory.push({
|
||||||
count: 1,
|
count: 1,
|
||||||
keyword: keyword.value
|
keyword: keywordInput.value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
settings.searchHistory = settings.searchHistory // save history
|
settings.searchHistory = settings.searchHistory // save history
|
||||||
@ -729,7 +729,7 @@ class SearchBox extends NavbarComponent {
|
|||||||
if (!settings.hideTopSearch) {
|
if (!settings.hideTopSearch) {
|
||||||
const json = await Ajax.getJson("https://api.bilibili.com/x/web-interface/search/default");
|
const json = await Ajax.getJson("https://api.bilibili.com/x/web-interface/search/default");
|
||||||
if (json.code === 0) {
|
if (json.code === 0) {
|
||||||
keyword.setAttribute("placeholder", json.data.show_name);
|
keywordInput.setAttribute("placeholder", json.data.show_name);
|
||||||
let href;
|
let href;
|
||||||
if (json.data.url !== "") {
|
if (json.data.url !== "") {
|
||||||
href = json.data.url;
|
href = json.data.url;
|
||||||
@ -754,7 +754,7 @@ class SearchBox extends NavbarComponent {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submit (value) {
|
submit (value) {
|
||||||
keyword.value = value
|
keywordInput.value = value
|
||||||
form.submit()
|
form.submit()
|
||||||
// submit method will not trigger submit event
|
// submit method will not trigger submit event
|
||||||
// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
||||||
@ -771,7 +771,7 @@ class SearchBox extends NavbarComponent {
|
|||||||
if (item) {
|
if (item) {
|
||||||
item.focus()
|
item.focus()
|
||||||
} else {
|
} else {
|
||||||
keyword.focus()
|
keywordInput.focus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -784,7 +784,7 @@ class SearchBox extends NavbarComponent {
|
|||||||
const { debounce } = await import('debounce');
|
const { debounce } = await import('debounce');
|
||||||
let lastQueuedRequest = ''
|
let lastQueuedRequest = ''
|
||||||
const updateSuggest = async () => {
|
const updateSuggest = async () => {
|
||||||
const text = keyword.value
|
const text = keywordInput.value
|
||||||
searchList.isHistory = text === ''
|
searchList.isHistory = text === ''
|
||||||
if (searchList.isHistory) {
|
if (searchList.isHistory) {
|
||||||
searchList.items = settings.searchHistory.sort((a, b) => b.count - a.count).map(item => {
|
searchList.items = settings.searchHistory.sort((a, b) => b.count - a.count).map(item => {
|
||||||
@ -814,8 +814,19 @@ class SearchBox extends NavbarComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateSuggest()
|
updateSuggest()
|
||||||
keyword.addEventListener('input', debounce(updateSuggest, 200))
|
const debouncedSuggest = debounce(updateSuggest, 200)
|
||||||
keyword.addEventListener('keydown', e => {
|
let composing = false
|
||||||
|
keywordInput.addEventListener('compositionstart', () => composing = true)
|
||||||
|
keywordInput.addEventListener('compositionend', () => {
|
||||||
|
composing = false
|
||||||
|
raiseEvent(keywordInput, 'input')
|
||||||
|
})
|
||||||
|
keywordInput.addEventListener('input', () => {
|
||||||
|
if (!composing) {
|
||||||
|
debouncedSuggest()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
keywordInput.addEventListener('keydown', e => {
|
||||||
if (e.key === 'ArrowDown' && searchList.items.length > 0) {
|
if (e.key === 'ArrowDown' && searchList.items.length > 0) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
dq('.custom-navbar .search-list-item:first-child').focus()
|
dq('.custom-navbar .search-list-item:first-child').focus()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user