Skip to content

Commit

Permalink
Suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
hoothin committed Sep 10, 2024
1 parent 5e89f4e commit 62e57d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
40 changes: 29 additions & 11 deletions searchJumper.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6540,12 +6540,8 @@
if (searchData.prefConfig.defaultPicker) {
this.togglePicker();
}
if (!this.searchJumperInputKeyWords.value && currentSite) {
if (!this.searchJumperInputKeyWords.value) {
this.searchJumperInputKeyWords.value = getKeywords() || cacheKeywords;
this.searchJumperInputKeyWords.focus();
this.searchJumperInputKeyWords.select();
} else {
this.searchInput.focus();
}
let firstType = this.bar.querySelector('.search-jumper-needInPage:not(.notmatch)>span');
if (firstType && !firstType.parentNode.classList.contains('search-jumper-open')) {
Expand All @@ -6559,8 +6555,9 @@
if (cacheFilter) {
this.searchInput.value = cacheFilter;
this.searchInput.dispatchEvent(new Event("input"));
this.searchJumperInputKeyWords.focus();
}
this.searchJumperInputKeyWords.focus();
this.searchJumperInputKeyWords.select();
} else if (this.searchInPageTab.checked) {
this.con.classList.add("in-find");
this.searchJumperInPageInput.focus();
Expand Down Expand Up @@ -7338,7 +7335,7 @@
clearTimeout(inputTimer);
inputTimer = setTimeout(() => {
self.getSuggest(self.searchJumperInputKeyWords.value)
}, 500);
}, 200);
});
this.searchJumperInputKeyWords.addEventListener("keydown", e => {
e.stopPropagation();
Expand Down Expand Up @@ -7846,18 +7843,27 @@
let suggestDatalist = this.suggestDatalist;
suggestDatalist.innerHTML = createHTML();
if (!searchWords) return;
let requestSuggest = (api, cb) => {
let requestSuggest = (api, cb, charset) => {
_GM_xmlhttpRequest({
method: 'GET',
url: api,
responseType: charset ? 'blob' : '',
headers: {
referer: api,
origin: api
},
onload: function(d) {
let response = d.response;
if (d.status >= 400 || !response) return;
cb(response);
if (charset) {
let reader = new FileReader();
reader.onload = () => {
cb(reader.result);
}
reader.readAsText(response, charset);
} else {
cb(response);
}
},
onerror: function(e){
debug(e);
Expand Down Expand Up @@ -7899,7 +7905,7 @@
suggestDatalist.appendChild(option);
}
}
});
}, "GBK");
break;
case "bing":
requestSuggest("https://api.bing.com/qsonhs.aspx?type=json&q=%s".replace("%s", searchWords), res => {
Expand Down Expand Up @@ -13429,41 +13435,51 @@
if (ext) {
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.selectionText) extSelectionText = request.selectionText;
let validCommand = false;
switch (request.command) {
case "settings":
validCommand = true;
_GM_openInTab(configPage, {active: true, insert: true});
break;
case "searchInPage":
validCommand = true;
searchBar.showInPage();
searchBar.showInPageSearch();
break;
case "filterSearch":
validCommand = true;
searchBar.showInPage();
searchBar.showFilterSearch();
break;
case "search":
validCommand = true;
if (request.name) {
searchBar.searchBySiteName(request.name, request.key || {});
} else {
searchBar.searchAuto(request.index || 0, request.key || {});
}
break;
case "searchAll":
validCommand = true;
if (request.name) {
searchBar.searcAllhByTypeName(request.name);
}
break;
case "toggle":
validCommand = true;
location.reload();
break;
case "streamUpdate":
validCommand = true;
searchBar.streamUpdate(request.detail);
break;
case "showAll":
validCommand = true;
searchBar.toggleShowAll();
break;
case "addSearchEngine":
{
validCommand = true;
if (shareEngines) return;
let openSearch = document.head.querySelector('[rel="search"]');
if (openSearch) {
Expand All @@ -13485,7 +13501,9 @@
default:
break;
}
sendResponse({ msg: "ok" });
if (validCommand) {
sendResponse({ msg: "ok" });
}
});
}
document.addEventListener('searchJumper', e => {
Expand Down
2 changes: 1 addition & 1 deletion src/page/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function About() {
<Card component="pre" style={{padding: '15px', lineHeight: 1.5, width: '90%', whiteSpace: 'pre-wrap', textAlign: 'left', marginTop: '0px', marginBottom: '10px'}}>
<img align='left' style={{width: '100px', maxWidth: '50%', boxShadow: 'rgb(0 0 0) 0px 0px 15px', marginRight: '20px', height: 'fit-content'}} src='avatar.jpg' alt='donate' loading="lazy"/>{window.i18n("donate")}
<Box sx={{m: 1, display: /^(http|ftp)/i.test(window.location.protocol) ? "none" : ""}}>
<StarRateIcon/> <Link href='https://chrome.google.com/webstore/detail/hgepmblbgodbilmfdjkalkgofdcipkhh/reviews' style={{verticalAlign: 'top'}} target="_blank">{window.i18n('rate')}</Link>
<b><StarRateIcon/> <Link href='https://chrome.google.com/webstore/detail/hgepmblbgodbilmfdjkalkgofdcipkhh/reviews' style={{verticalAlign: 'top'}} target="_blank">{window.i18n('rate')}</Link></b>
</Box>
</Card>
<VolunteerActivismIcon fontSize="large" />
Expand Down

0 comments on commit 62e57d8

Please sign in to comment.