Google direct Link

remove google search and image link redirection to speed up your browsing and hide referrer

当前为 2014-08-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google direct Link
  3. // @namespace http://userscripts.org/users/tommy
  4. // @author .
  5. // @description remove google search and image link redirection to speed up your browsing and hide referrer
  6. // @include *google.*/*
  7. // @exclude *userscripts.org*
  8. // @version 1.0.1
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. var hideReferer = true,
  13. newTab = true,
  14. showCache = false;
  15.  
  16. var ua = navigator.userAgent,
  17. wK = ua.toLowerCase().indexOf('webkit') > -1,
  18. S = location.protocol === 'https:';
  19.  
  20. function addEvent(a, b, c) {
  21. if (a.addEventListener) {
  22. a.addEventListener(b, c, false);
  23. }
  24. }
  25.  
  26. function removeEvent(a, b, c) {
  27. if (a.removeEventListener) {
  28. a.removeEventListener(b, c, false);
  29. }
  30. }
  31.  
  32. if (Object.defineProperty) {
  33. Object.defineProperty(window, 'rwt', {
  34. value: function () {},
  35. writable: false,
  36. configurable: false
  37. })
  38. } else {
  39. window.__defineGetter__('rwt', function () {
  40. return function () {}
  41. })
  42. }
  43.  
  44. if (showCache) {
  45. addEvent(window, 'DOMNodeInserted', cache);
  46. }
  47.  
  48. function cache() {
  49. var cc = document.querySelectorAll('.vshid');
  50. if (cc) {
  51. for (var i = 0; i < cc.length; ++i) {
  52. cc[i].style.display = 'inline';
  53. }
  54. }
  55. }
  56.  
  57. function proxy(e) {
  58. if (e && e.localName == 'a' && (e.className == 'l' || e.id == 'rg_hl' || e.className == 'rg_l' || e.className == 'rg_ilmn' || e.parentNode.className == 'vshid' || e.parentNode.className == 'gl' || e.parentNode.className == 'r')) {
  59. e.onmousedown ? e.removeAttribute('onmousedown') : 0;
  60. var m = /(&url=([^&]+)|imgurl=([^&]+))(&w=\d+&h=\d+)?&ei/g.exec(decodeURIComponent(e.href));
  61. if (m) e.href = m[2] || m[3];
  62. if (newTab) e.target = "_blank";
  63. if (hideReferer) {
  64. if (wK && !S) {
  65. e.rel = "noreferrer";
  66. } else if (!S && e.href.indexOf('http-equiv="refresh"') == -1) {
  67. e.href = 'data:text/html, <meta http-equiv="refresh" content="0;URL=' + encodeURIComponent(e.href) + '" charset="utf-8">';
  68. }
  69. }
  70. }
  71. }
  72.  
  73. function tunnel(e, f) {
  74. if (e && e.localName == 'a' && (e.className == 'l' || e.id == 'rg_hl' || e.className == 'rg_ilmn' || e.className == 'irc_but' || e.className == 'rg_l' || e.parentNode.className == 'vshid' || e.parentNode.className == 'gl' || e.parentNode.className == 'r')) {
  75. if (e.href.indexOf('http-equiv="refresh"') > -1) {
  76. var rLink = /URL=([^"]+)/g.exec(decodeURIComponent(e.href));
  77. if (rLink) {
  78. e.href = rLink[1];
  79. }
  80. }
  81. }
  82. removeEvent(f, 'mouseout', fixer);
  83. }
  84.  
  85. function fixer(e) {
  86. var a = e.target,
  87. b = a;
  88. if (a.localName != 'a') {
  89. for (; a; a = a.parentNode) {
  90. tunnel(a, b);
  91. }
  92. } else {
  93. tunnel(a, b);
  94. }
  95. }
  96.  
  97. function doStuff(e) {
  98. var a = e.target;
  99. addEvent(a, 'mouseout', fixer);
  100. if (a && a.className == 'rg_i') {
  101. a.removeAttribute('class');
  102. }
  103. if (a.localName != 'a') {
  104. for (; a; a = a.parentNode) {
  105. proxy(a);
  106. }
  107. } else {
  108. proxy(a);
  109. }
  110. }
  111.  
  112. addEvent(window, "mousedown", doStuff);