Objective :
replace the mouse with the keyboard, do a quiet brush to know the beauty of male (female) son!
features :
Function |
Keys |
Description |
Navigate directly to the search box |
Q |
|
Open Home |
W |
|
Open Topic |
E |
|
Open discovery |
R |
|
Open message |
M |
|
Open personal page |
U |
|
Open my draft. |
C |
|
Open My Collection |
S |
|
Open issues of concern |
G |
|
Open the question that asked me to answer |
Y |
|
Open the first question in the currently visible range |
Enter |
< Latest news for < home > only > |
Auto Load more |
Space or ↓ |
Only for page load mode when scrolling is loaded |
Previous page or next page |
←or→ |
Page load only for paging |
When you forget these shortcuts, tapping the H key directly pops up the help message. |
Implementation code
only two key points were introduced:
1) Auto load more
Note : When the latest dynamic, in the process of continuous scrolling, the bottom will appear the ' More ' button, each time you need to click with the mouse
idea : When each scroll to the bottom, the ' more ' button is automatically triggered by the Click event.
Implementation Code :
if (e.keycode==40| | E.KEYCODE==32) { //down ARROW | | space var scrolltop = $ (window). scrolltop (); var scrollheight = $ (document). Height (); var windowheight = $ (window). Height (); if (scrolltop + windowheight = = scrollheight) { document.getElementById (' Zh-load-more '). Click (); } }
2) Open the first question in the currently visible range
Note : Brush the latest dynamic, see the problem of interest, each time you need to manually click, can you directly hit enter, a key to open this problem? The answer is yes.
idea : Through the analysis of HTML source code, know that each problem is a fixed height of the div. So you can get the target by getting the y-coordinate of the current scroll bar, divided by the height of the div.
Implementation Code :
if (e.keycode==13) {//ENTER: Directly open the problem closest to the top//height==219 var y= getpagescroll () per question. Y Position of the scroll bar var index =parseint (parseint (y)/220); The current div var title= $ (' #js-home-feed-list div.feed-item '). EQ (index). Find (' H2 '). html (); var a_href = $ (' #js-home-feed-list div.feed-item '). EQ (index). Find (' H2 '). Find (' a '). attr (' href '); window.open (' https://www.zhihu.com ' +a_href);
}function Getpagescroll () {var x, y;
if (Window.pageyoffset) {
All except IE y = window.pageyoffset; x = Window.pagexoffset; }
else if (document.documentelement && document.documentElement.scrollTop) {
IE 6 Strict y = document.documentElement.scrollTop; x = Document.documentElement.scrollLeft; }
else if (document.body) {
All other IE y = document.body.scrollTop; x = Document.body.scrollLeft; } return {x:x, y:y};}
Full code: = Please click on me =
V1.0 : just simple implementation of the previous page, the next page function, please click me for details!
"Face original" Google expansion--V2.0