Skip to content

Commit

Permalink
搜索支持直接粘贴;优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
penghaifeng committed Apr 1, 2019
1 parent f109828 commit bd57bb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ body {
padding: 0.5rem 1rem;
font-style: italic;
cursor: pointer;
}

.suggestions-ctn li span:hover {
text-decoration: underline;
}
17 changes: 6 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ function initSearch(){
suggestionsCtn.innerHTML = '';
}
}
$('body').onkeydown = function(e){
if(e.keyCode == 17 || e.keyCode == 91 || e.keyCode == 93){
//Control or Command
searchInput.focus();
}
}
$('body').onkeypress = function(e){
searchInput.focus();
}
Expand Down Expand Up @@ -201,20 +207,9 @@ function onSuggestionReceived(r){
suggestionsCtn.innerHTML = suggestionsHtml;
$$('.suggestions-ctn li span').forEach(function(v, i){
v.onclick = function(){doSearch(this.innerText)};
v.onmouseover = function(){searchItemHover(this)};
v.onmouseout = function(){searchItemMouseout(this)};
});
}
}
function searchItemHover(item){
if(currentSelectSuggestionIndex >= 0 && currentSelectSuggestionIndex < suggestionsCtn.childNodes.length){
suggestionsCtn.childNodes[currentSelectSuggestionIndex].childNodes[0].classList.remove('clear-box-shadow');
}
item.classList.add('clear-box-shadow');
};
function searchItemMouseout(item){
item.classList.remove('clear-box-shadow');
};
function doSearch(keyword){
window.location.href = SearchEngines[Settings.searchEngine].replace('{keyword}', keyword);
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_pluginName__",
"short_name": "__MSG_shortName__",
"version": "1.0.5",
"version": "1.0.6",
"description": "__MSG_pluginDesc__",
"icons":
{
Expand Down

0 comments on commit bd57bb2

Please sign in to comment.