set title text on search page

This commit is contained in:
siikamiika 2019-12-06 00:40:41 +02:00
parent 248b0f15eb
commit 14c5857dfe

View File

@ -224,6 +224,7 @@ class DisplaySearch extends Display {
sentence: {text: query, offset: 0},
url: window.location.href
});
this.setTitleText(query);
} else {
this.container.textContent = '';
}
@ -356,6 +357,14 @@ class DisplaySearch extends Display {
this.search.disabled = this.introVisible && (this.query === null || this.query.value.length === 0);
}
setTitleText(text) {
// Chrome limits title to 1024 characters
if (text.length > 1000) {
text = text.slice(0, 1000) + '...';
}
document.title = `${text} - Yomichan Search`;
}
static getSearchQueryFromLocation(url) {
const match = /^[^?#]*\?(?:[^&#]*&)?query=([^&#]*)/.exec(url);
return match !== null ? decodeURIComponent(match[1]) : null;