FastNav

Quickly navigate to the next page with your keyboard. Press n to go to the next page, press p to go to the previous page.

  1. // ==UserScript==
  2. // @name FastNav
  3. // @namespace hugsmile.eu
  4. // @include *
  5. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wYBBicLUdqBwAAAA1lJREFUWMPFl0tIVFEYx39nug46qE1DYoWU1KJAKZHEoEVRLhwXQUFGKG6CHpsy7KlEi/BJA7myxyKoGSKDAhfpwoIWQWJgQzNQQTZa9DJKKjTG0dPijDo6984cG6UPLsy9c875/8/3/oSUEl15FITuF8iBIQiNwOiY+u50QP5KKMoH9xZEWaH2kQgdAie9yPZukBHASLI4uqa2HBoPIBz2FAg0dyHrfRqgVjIBTdVwfg9iwQQKzyKDw4CN1GQKCtZC/yVEup04JnEEJibBdRj5+w+LKpnpEGpHuDLnkogjkHVo8cFjSXztQGTE+IVtvtqXChzg9x8oucCcG9tiHS44nCLCpApJItZLgsMKK45AvTd1h3MXw48bcO0IELZYZIN6H4yFYwicvI0kzWKDVDfTeVY51ZbDu8BXm4CEAQ13lRaElBJbFebBOAmXayDPBToJc0MulKyffX/wHPa1gdnlBDDlQxi9AesM5y6Guop/N8nerVC9E7xPTRQbgd4AGD1+pFWmexSEgRCsWaEHmGGH7IzZ99A36OyzNkOPH2kMDFkfGI5A8ZmojTWkugxuH1O/33yCTacgkeUGhsAIjSQ5Nc3chqYOHk1xL9/D5rNgXQGiGhoBY7qkLobcegLjYbj3LDk4qHKuH/kS9peq4mKtArjXpwc+s8Xp0AP3t0DncajZsXgaczrAyM+Bwa+JF77ywMbV0eoqAd16sSyx/+TngKjzSul5aL7AbsBrj2q3puXnuLKzjnz8Adsuqmgyk7oKMMq3IDxd5rmgsnQuOKg4j431RJK7HHYXQLffvHUrL0IkTsUTcP807C2Z/dQ/CG+/aDSbAj58h1O3oqawSsUAJ8rhSo95DtjXBt5aqNquPnX0ws3Hui5uDg5wwh1TDZsOICxruB2qr8D1KOjn0eihOo+w7pwbK9W/My1ZSxfy/J0EPUEEnNkw+sv6VrpNavNBOLdnHoGZTvgDSyoFeRBondXNHALjE5B7FPnrfzWl6Wnwrh2Rlb404KF2NRuYNqXToeHKhC9XEYV5SfL+QgaTPHXz+TMBZi4ngIw0eNmKaD6YuMNNKhHlcIFWpXbxL8PpWBgaOhc2nApD5ZaUh9O4Fi0A3X7kiyF4N388z4GideAuQpQV6CvpLyjrNaUqOdRiAAAAAElFTkSuQmCC
  6. // @description Quickly navigate to the next page with your keyboard. Press n to go to the next page, press p to go to the previous page.
  7. // @version 0.5.0
  8. // @grant none
  9. // ==/UserScript==
  10. (function(){
  11. var pagenum;
  12. var typeahead_value;
  13.  
  14. window.addEventListener("keyup", function (event) {
  15. if (event.defaultPrevented) {
  16. return;
  17. }
  18. // check if modifier is pressed (ctrl, shift)
  19. // if pressed, return
  20. if(event.getModifierState("Shift") || event.getModifierState("Control") || event.getModifierState("Meta") || event.getModifierState("OS") || event.getModifierState("AltGraph")){
  21. return;
  22. }
  23. if(event.getModifierState("Alt") && (typeahead_value == false || isMediaWiki() == true )){
  24. return;
  25. }
  26.  
  27. switch (event.keyCode) {
  28. case 78:
  29. // order is important here
  30. if(document.hasFocus() && document.activeElement.tagName == "BODY"){
  31. generic("next");
  32. }else{
  33. return;
  34. }
  35. break;
  36. case 66:
  37. case 80:
  38. // order is important here
  39. if(document.hasFocus() && document.activeElement.tagName == "BODY"){
  40. generic("prev");
  41. }else{
  42. return;
  43. }
  44. break;
  45. case 79:
  46. if(document.hasFocus() && document.activeElement.tagName == "BODY"){
  47. genericOpen();
  48. }else{
  49. return;
  50. }
  51. break;
  52. default:
  53. return;
  54. }
  55.  
  56. // don't allow for double actions for a single event
  57. event.preventDefault();
  58. }, true);
  59.  
  60. function isMediaWiki(){
  61. //generator
  62. var counter;
  63. var metaTags = window.document.getElementsByTagName("meta");
  64. for(counter = 0; counter < metaTags.length; counter++){
  65. if(metaTags[counter].getAttribute("name") == "generator"){
  66. if(metaTags[counter].getAttribute("content").indexOf("MediaWiki") > -1){
  67. return true;
  68. }else{
  69. return false;
  70. }
  71. }
  72. }
  73. return false;
  74. }
  75.  
  76. function cleanurl(url){
  77. return decodeURIComponent(url.replace("&amp;", "&"))
  78. }
  79.  
  80. function replacelocation(value, website){
  81. //alert(value + " - " + website);
  82. window.location.href = value;
  83. }
  84.  
  85. function generic(mode){
  86. var location= window.location.href;
  87. var lastIndex = location.lastIndexOf("=");
  88. var pageNumber = location.substring(lastIndex+1);
  89. var stringlength = 1;
  90. var i = 0;
  91.  
  92. // phoronix.com, http://punbb.informer.com, FluxBB
  93. // http://www.phoronix.com/forums/forum/phoronix/latest-phoronix-articles/823939-the-best-most-efficient-graphics-cards-for-1080p-linux-gamers/page2
  94. var linkTags = window.document.getElementsByTagName("link");
  95. for(i = 0; i < linkTags.length; i++){
  96. if(linkTags[i].getAttribute("rel") == mode){
  97. replacelocation(linkTags[i].getAttribute("href"), "<link rel");
  98. return;
  99. }
  100. }
  101. // reddit.com, phpBB
  102. var atags = document.getElementsByTagName("a");
  103. for(i = 0; i < atags.length; i++){
  104. if(atags[i].hasAttribute("rel")){
  105. if(atags[i].getAttribute("rel").indexOf(mode) > -1){
  106. replacelocation(atags[i].href, "<a rel");
  107. return;
  108. }
  109. }
  110. }
  111. // MyBB
  112. if(mode == "next"){
  113. var value = document.getElementsByClassName("pagination_next")[0];
  114. if(value != undefined){
  115. replacelocation(document.getElementsByClassName("pagination_next")[0], "mybb (pagination_next)");
  116. return;
  117. }
  118. }
  119. if(location.indexOf("techradar.com") > -1){
  120. if (mode == "next" && location.lastIndexOf("/") < location.length - 3){ // there is no page filled in, add it
  121. replacelocation(window.location.href + "/2", "techradar.com");
  122. return;
  123. }
  124.  
  125. if(location.lastIndexOf("/") > -1 && location.lastIndexOf("/") > location.length - 3){
  126. // increment or decrement
  127. lastIndex = location.lastIndexOf("/");
  128. pageNumber = location.substring(lastIndex+1);
  129. if(mode == "next"){
  130. window.location.href = window.location.href.substring(0, lastIndex) + "/" + (parseInt(pageNumber) + 1)
  131. }else{
  132. if(parseInt(pageNumber) == 2){
  133. window.location.href = window.location.href.substring(0, lastIndex) // there is a page filled in, remove it
  134. }else{
  135. window.location.href = window.location.href.substring(0, lastIndex) + "/" + (parseInt(pageNumber) - 1)
  136. }
  137. }
  138. return;
  139. }
  140. }
  141. // webwereld.nl, computerworld.nl etc.
  142. var paginatorNext = window.document.getElementsByClassName("paginator-next")[0];
  143. var paginatorPrevious = window.document.getElementsByClassName("paginator-previous")[0];
  144. if(mode == "next"){
  145. if(paginatorNext != undefined){
  146. replacelocation(paginatorNext.href, "webwereld next");
  147. }
  148. }else{
  149. if(paginatorPrevious != undefined){
  150. replacelocation(paginatorPrevious.href, "webwereld previous");
  151. }
  152. }
  153. // jenkov.com
  154. var nextPageJenkovCom = window.document.getElementsByClassName("nextArticleInCategory")[0];
  155. if(nextPageJenkovCom != null){
  156. if(mode == "next"){
  157. replacelocation(nextPageJenkovCom.parentElement.href, "jenkov.com");
  158. return;
  159. }else{
  160. window.history.back();
  161. return;
  162. }
  163. }
  164. // waarmaarraar.nl (prev/next article)
  165. if(location.indexOf("waarmaarraar.nl") > -1){
  166. var container = document.getElementsByClassName("span7")[0];
  167. var ahrefs = container.getElementsByTagName("a");
  168. var newahrefs = [];
  169. for(counter = 0; counter < ahrefs.length; counter++){
  170. var hrefattribute = ahrefs[counter].getAttribute("href");
  171. if(hrefattribute == null){
  172. continue;
  173. }
  174. if(hrefattribute.indexOf("/pages/re") > -1){
  175. newahrefs.push(ahrefs[counter]);
  176. }
  177. }
  178.  
  179. if(newahrefs.length == 2){
  180. if(mode == "next" ){
  181. replacelocation(newahrefs[1].getAttribute("href"), "waarmaarraar.nl next");
  182. }else{
  183. replacelocation(newahrefs[0].getAttribute("href"), "waarmaarraar.nl prev");
  184. }
  185. return;
  186. }
  187. if(newahrefs.length == 1){
  188. // there is no previous/next page?
  189. replacelocation(newahrefs[0].getAttribute("href"), "waarmaarraar.nl next/prev");
  190. return;
  191. }
  192. }
  193.  
  194. // chm
  195. var ahrefs = window.document.getElementsByClassName("a");
  196. var i = 0;
  197. for(i = 0; i < ahrefs.length; i++){
  198. if(ahrefs[i].getAttribute("alt") == "Next Page" && mode == "next"){
  199. }
  200. if(ahrefs[i].getAttribute("alt") == "Previous Page" && mode == "prev"){
  201. window.location.href = ahrefs[i];
  202. }
  203. return;
  204. }
  205. // clixsense adgrid
  206. if(location.indexOf("clixsense.com/en/ClixGrid") > -1){
  207. // /10/7?69738**
  208. var lastIndexSlash = location.lastIndexOf("/");
  209. var lastQuestionMark = location.lastIndexOf("?");
  210. var indexSlash = location.indexOf("/", lastIndexSlash - 6);
  211. var column = parseInt(location.substring(indexSlash+1,lastIndexSlash));// 1-30
  212. var row = parseInt(location.substring(lastIndexSlash+1, lastQuestionMark)); // 1-20
  213. var userid = location.substring(lastQuestionMark + 1)
  214. if(mode == "next"){
  215. if(column < 30){
  216. column = column + 1;
  217. }else{
  218. if(row < 20){
  219. row = row + 1;
  220. }
  221. }
  222. }else{
  223. if(column > 1){
  224. column = column - 1;
  225. }else{
  226. if(row > 1){
  227. row = row - 1;
  228. }
  229. }
  230. }
  231. window.location.href = "http://www.clixsense.com/en/ClixGrid/" + column + "/" + row + "?" + userid;
  232. return;
  233. }
  234. // generic
  235. if(lastIndex == -1){
  236. //page-1
  237. stringlength = 5
  238. lastIndex = location.lastIndexOf("page-");
  239. pageNumber = location.substring(lastIndex+stringlength);
  240. }
  241. if (isNaN(parseInt(pageNumber) + 1) == false){
  242. if(mode == "next"){
  243. pagenum = parseInt(pageNumber) + 1;
  244. }else{
  245. // prev
  246. pagenum = parseInt(pageNumber) - 1;
  247. }
  248. var addendum = location.substring(lastIndex + stringlength+1);
  249. if(!isNaN(addendum)){
  250. addendum = "";
  251. }
  252. replacelocation(location.substring(0,lastIndex + stringlength) + pagenum + addendum, "generic");
  253. }
  254. }
  255. function genericOpen(){
  256. var i = 0;
  257. var location= window.location.href;
  258. if(location.indexOf("twoo.com") > -1){
  259. var photoCover = document.getElementsByClassName("photoCover")[0];
  260. var linkToProfile = "https://www.twoo.com/" + photoCover.getAttribute("data-user-info");
  261. //window.location.href = linkToProfile;
  262. /*var photoCoverTitle = document.getElementsByClassName("photoCover__info__title")[0];
  263. var profileAhref = photoCoverTitle.getElementsByTagName("a");
  264. profileAhref.setAttribute("href", linkToProfile);*/
  265. window.open(linkToProfile);
  266. return;
  267. }
  268. // waarmaarraar.nl
  269. if(location.indexOf("waarmaarraar.nl") > -1){
  270. // Read more
  271. var nextPageWMR = window.document.getElementsByClassName("readmore")[0];
  272. if(nextPageWMR != null){
  273. var alink = nextPageWMR.getElementsByTagName("a")[0];
  274. if(mode == "next"){
  275. window.location.href = alink.href;
  276. return;
  277. }
  278. }
  279. // Bronsite
  280. var alinks = document.getElementsByTagName("a");
  281. for(i = 0; i < alinks.length; i++){
  282. // ©
  283. var onclick = "";
  284. try{
  285. onclick = alinks[i].getAttribute("onclick");
  286. }catch(e){
  287. continue;
  288. }
  289. if(onclick == null){
  290. continue;
  291. }
  292. if(onclick.indexOf("/bronsite/") > -1){
  293. window.location.href = alinks[i].getAttribute("href");
  294. return;
  295. }
  296. }
  297. }
  298. // reddit interstitial page
  299. var interstitial = document.getElementsByClassName("interstitial")[0];
  300. if(interstitial != undefined){
  301. var buttons = document.getElementsByTagName("button");
  302. for(i = 0; i < buttons.length; i++){
  303. if(buttons[i].getAttribute("value") == "yes"){
  304. buttons[i].click();
  305. return;
  306. }
  307. }
  308. }
  309. if(location.indexOf("reddit.com") > -1){
  310. var titles = document.getElementsByClassName("title");
  311. for(i = 0; i < titles.length; i++){
  312. if(titles[i].hasAttribute("href")){
  313. window.location.href = titles[i].getAttribute("href");
  314. return;
  315. }
  316. }
  317. }
  318. }
  319.  
  320. })();