Google Tracking-B-Gone

Strips click tracking from Google search results

目前为 2017-04-19 提交的版本。查看 最新版本

  1. // Google Tracking-B-Gone
  2. // version 2.4
  3. // Release Date: 2017-04-19
  4. // https://gf.qytechs.cn/en/scripts/1810-google-tracking-b-gone
  5. // https://github.com/stacybrock/google-tracking-b-gone
  6. //
  7. // ===== INSTRUCTIONS =====
  8. //
  9. // This is a Greasemonkey user script.
  10. //
  11. // To use this script, get Greasemonkey: http://www.greasespot.net
  12. // After you've installed it, come back to this page. A dialog box will
  13. // appear asking you if you want to install this script.
  14. //
  15. // To uninstall, go to Tools->Greasemonkey->Manage User Scripts, select
  16. // "Google Tracking-B-Gone" from the list on the left, and click
  17. // Uninstall.
  18. //
  19. //
  20. // ==UserScript==
  21. // @name Google Tracking-B-Gone
  22. // @namespace http://notoriety.org
  23. // @version 2.4
  24. // @description Strips click tracking from Google search results
  25. //
  26. // @include http://www.google.*
  27. // @include https://www.google.*
  28. //
  29. // @grant none
  30. // ==/UserScript==
  31.  
  32. var debug = false;
  33.  
  34. if (debug) { console.log("Google Tracking-B-Gone initialized."); }
  35.  
  36. var changeObserver = new MutationObserver(function(mutations) {
  37. mutations.forEach(function(mutation) {
  38. if ((mutation.target.nodeName == 'BODY' && mutation.target.attributes.getNamedItem('id').value == 'gsr') ||
  39. (mutation.target.nodeName == 'DIV' && mutation.target.attributes.getNamedItem('id').value == 'taw')) {
  40. doIt();
  41. }
  42. });
  43. });
  44. changeObserver.observe(document.documentElement, { childList: true, subtree: true });
  45.  
  46.  
  47. function doIt() {
  48. if (debug) { console.log("doIt() called..."); }
  49. var resultLinks = $x("//a[@onmousedown]", XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
  50. resultLinks.forEach(function(link) { // loop over links
  51. if (link.getAttribute('onmousedown')) {
  52. link.removeAttribute('onmousedown');
  53. }
  54. });
  55.  
  56. resultLinks = $x("//a");
  57. resultLinks.forEach(function(link) { // loop over links
  58. var oldLink = link.href;
  59. if (/^http:\/\/www.google.co/.test(oldLink) || /^https:\/\/encrypted.google.co/.test(oldLink)) {
  60. var matches = /url\?(url|q)=(.+?)&/.exec(oldLink);
  61. if (matches != null) {
  62. link.href = unescape(matches[2]);
  63. }
  64. } else if ((/pdf$/i).test(oldLink)) {
  65. link.href = oldLink;
  66. }
  67. });
  68. }
  69.  
  70.  
  71. // XPath helper, from
  72. // https://wiki.greasespot.net/XPath_Helper
  73. function $x() {
  74. var x='';
  75. var node=document;
  76. var type=0;
  77. var fix=true;
  78. var i=0;
  79. var cur;
  80.  
  81. function toArray(xp) {
  82. var final=[], next;
  83. while (next=xp.iterateNext()) {
  84. final.push(next);
  85. }
  86. return final;
  87. }
  88.  
  89. while (cur=arguments[i++]) {
  90. switch (typeof cur) {
  91. case "string": x+=(x=='') ? cur : " | " + cur; continue;
  92. case "number": type=cur; continue;
  93. case "object": node=cur; continue;
  94. case "boolean": fix=cur; continue;
  95. }
  96. }
  97.  
  98. if (fix) {
  99. if (type==6) type=4;
  100. if (type==7) type=5;
  101. }
  102.  
  103. // selection mistake helper
  104. if (!/^\//.test(x)) x="//"+x;
  105.  
  106. // context mistake helper
  107. if (node!=document && !/^\./.test(x)) x="."+x;
  108.  
  109. var result=document.evaluate(x, node, null, type, null);
  110. if (fix) {
  111. // automatically return special type
  112. switch (type) {
  113. case 1: return result.numberValue;
  114. case 2: return result.stringValue;
  115. case 3: return result.booleanValue;
  116. case 8:
  117. case 9: return result.singleNodeValue;
  118. }
  119. }
  120.  
  121. return fix ? toArray(result) : result;
  122. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址