Greasy Fork is available in English.

Google Cache Redirect Remover

Removes the Google redirect in cached links

  1. // Google Cache Redirect Remover
  2. // GNU General Public License
  3.  
  4. // ==UserScript==
  5. // @name Google Cache Redirect Remover
  6. // @namespace http://qixinglu.com
  7. // @description Removes the Google redirect in cached links
  8. // @include http://www.google.*/search?*
  9. // @include https://encrypted.google.*/search?*
  10. // @version 0.0.1.20140517140357
  11. // ==/UserScript==
  12.  
  13. var USE_HTTPS = true;
  14. var REMOVE_SEARCH_LINKS = false;
  15. var APPEND_SEARCH_LINKS = false;
  16.  
  17. var snapshotLinksNode = document.getElementsByClassName("gl");
  18. for (var i = 0; i < snapshotLinksNode.length; i++) {
  19. try {
  20. var linkNode = snapshotLinksNode[i].childNodes[0];
  21. linkNode.removeAttribute("onmousedown");
  22. if (USE_HTTPS) {
  23. linkNode.href = linkNode.href.replace("http://", "https://");
  24. }
  25. } catch (e) {
  26. continue;
  27. }
  28. }
  29.  
  30. var previewLinksNode = document.getElementsByClassName("f");
  31. for (var i = 0; i < previewLinksNode.length; i++) {
  32. try {
  33. var linkNode = previewLinksNode[i].nextElementSibling;
  34. linkNode.removeAttribute("onmousedown");
  35. if (USE_HTTPS) {
  36. linkNode.href = linkNode.href.replace("http://", "https://");
  37. }
  38. } catch (e) {
  39. continue;
  40. }
  41. }
  42.  
  43. if (REMOVE_SEARCH_LINKS) {
  44. var searchLinksNode = document.getElementsByClassName("l");
  45. for (var i = 0; i < searchLinksNode.length; i++) {
  46. try {
  47. var linkNode = searchLinksNode[i];
  48. linkNode.removeAttribute("onmousedown");
  49. } catch (e) {
  50. continue;
  51. }
  52. }
  53. }
  54.  
  55. if (APPEND_SEARCH_LINKS) {
  56. var searchLinksNode = document.getElementsByClassName("l");
  57. for (var i = 0; i < searchLinksNode.length; i++) {
  58. try {
  59. var linkNode = searchLinksNode[i];
  60. var newLinkNode = document.createElement("a");
  61. newLinkNode.href = linkNode.href;
  62. newLinkNode.textContent = "SourceLink";
  63. if (document.location.href.indexOf('https') == 0) {
  64. var additionLinkNodes = linkNode.parentNode.parentNode.getElementsByClassName("gl");
  65. } else {
  66. var additionLinkNodes = linkNode.parentNode.parentNode.parentNode.getElementsByClassName("gl");
  67. }
  68. for (var j = 0; j < additionLinkNodes.length; j++) {
  69. try {
  70. var snapshotLinkNode = additionLinkNodes[j].firstChild;
  71. if (snapshotLinkNode.href.indexOf("webcache.googleusercontent.com") != -1) {
  72. var additionLinkNode = snapshotLinkNode.parentNode;
  73. additionLinkNode.appendChild(document.createTextNode(" - "));
  74. additionLinkNode.appendChild(newLinkNode);
  75. }
  76. } catch (e) {
  77. continue;
  78. }
  79. }
  80. } catch (e) {
  81. continue;
  82. }
  83. }
  84. }