Go To Review

Adds a "G+R" shortcut to go to review

  1. // ==UserScript==
  2. // @name Go To Review
  3. // @namespace https://github.com/AstroCB
  4. // @author Cameron Bernhardt (AstroCB)
  5. // @version 1.1
  6. // @description Adds a "G+R" shortcut to go to review
  7. // @include *://*.stackexchange.com/*
  8. // @include *://*stackoverflow.com/*
  9. // @include *://*serverfault.com/*
  10. // @include *://*superuser.com/*
  11. // @include *://*askubuntu.com/*
  12. // @include *://*stackapps.com/*
  13. // @include *://*mathoverflow.net/*
  14. // ==/UserScript==
  15.  
  16. function listenForKeys(e) {
  17. if (e.keyCode === 114 && lastKey === 103) {
  18. var review;
  19. var links = $(".topbar-menu-links")[0].children;
  20. for (var i = 0; i < links.length; i++) {
  21. if (links[i].href && (links[i].href.indexOf("review") + 6 === links[i].href.length)) {
  22. review = links[i];
  23. }
  24. }
  25. review.click();
  26. }
  27. lastKey = e.keyCode;
  28. }
  29.  
  30. function stopListeningForKeys() {
  31. $("body").unbind("keypress", listenForKeys);
  32. };
  33.  
  34. function attachListener() {
  35. var lastKey;
  36. $("body").keypress(listenForKeys);
  37. }
  38.  
  39. var main = function () {
  40. attachListener();
  41. window.setInterval(function () { // Some text fields are created dynamically
  42. $("input").focus(stopListeningForKeys).keypress(stopListeningForKeys);
  43. $("input").blur(attachListener);
  44.  
  45. $("textarea").focus(stopListeningForKeys).keypress(stopListeningForKeys);
  46. $("textarea").blur(attachListener);
  47. }, 1000);
  48. };
  49.  
  50. var listen = document.createElement("script");
  51. listen.type = "text/javascript";
  52. listen.textContent = listenForKeys.toString();
  53. document.body.appendChild(listen);
  54.  
  55. var stop = document.createElement("script");
  56. stop.type = "text/javascript";
  57. stop.textContent = stopListeningForKeys.toString();
  58. document.body.appendChild(stop);
  59.  
  60. var attach = document.createElement("script");
  61. attach.type = "text/javascript";
  62. attach.textContent = attachListener.toString();
  63. document.body.appendChild(attach);
  64.  
  65. var script = document.createElement("script");
  66. script.type = "text/javascript";
  67. script.textContent = "(" + main.toString() + ")();";
  68. document.body.appendChild(script);