Guest User

Untitled

a guest
Aug 16th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Direct Links in Google Search
  3. // @namespace https://github.com/astanin
  4. // @description Remove indirections from Google search results on all TLDs.
  5. // @include https://www.google.tld/*output=search*
  6. // @include http://www.google.tld/*output=search*
  7. // @include https://www.google.tld/search*
  8. // @include http://www.google.tld/search*
  9. // @include https://www.google.tld/#*
  10. // @include http://www.google.tld/#*
  11. // @include https://www.google.tld/webhp*
  12. // @include http://www.google.tld/webhp*
  13. // @include https://www.google.tld/
  14. // @include http://www.google.tld/
  15. // @include https://encrypted.google.com/*
  16. // @version 2.2
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. // Version 2.2
  21. // - rewrite using DOMNodeInserted and getElements* to support Chromium too
  22. // - enable on encrypted.google.com
  23. // - try to fix new-style classless links in search results (/url?q=...)
  24. //
  25. // Version 2.1
  26. // - enable on plain Google search page, now it works with Instant too
  27. //
  28. // Version 2.0 (Direct Links in Google Search)
  29. // - fork "Less Google", which is not working any more, and rename
  30. // - enable on all Google top-level domains (only .com and .ca in Less Google)
  31. // - enable on new HTTPS search pages (HTTP still supported, just in case)
  32. // - remove deprecated @exclude patterns (search URLs have been changed)
  33. // - don't allow any "onmousedown" link modifications
  34. //
  35. // Version 1.1 (Less Google by @clump)
  36. // - change include to only apply to search results
  37. // (maps and images are too slow)
  38. //
  39. // Version 1.0 (Less Google by @clump)
  40.  
  41. function fixLinksOfClassL() {
  42. // fix old-style class="l" links
  43. var ts = document.getElementsByClassName("l");
  44. for (var i=0; i < ts.length; i++) {
  45. var t = ts[i];
  46. if (t.tagName == "A") {
  47. // remove javascript callback first
  48. t.removeAttribute("onmousedown");
  49. // fix link if necessary
  50. var href = t.getAttribute("href");
  51. var m = href.match(/&url=([^&]*)/);
  52. if (m) {
  53. t.setAttribute('href',decodeURIComponent(m[1]));
  54. }
  55. }
  56. }
  57. return ts.length;
  58. }
  59.  
  60. function fixClasslessLinks() {
  61. // fix new classless links (noticed in some search results)
  62. var results = document.getElementById("search");
  63. var ts = results.getElementsByTagName("A");
  64. for (var i=0; i < ts.length; i++) {
  65. t = ts[i];
  66. t.removeAttribute("onmousedown");
  67. var href = t.getAttribute("href");
  68. var m = href.match(/\/url?.*q=([^&]*)/)
  69. if (m) {
  70. t.setAttribute('href',decodeURIComponent(m[1]));
  71. }
  72. }
  73. return ts.length;
  74. }
  75.  
  76. function cleanPage() {
  77. var n = fixLinksOfClassL();
  78. if (n == 0) {
  79. fixClasslessLinks();
  80. }
  81. }
  82.  
  83. document.addEventListener('DOMNodeInserted',cleanPage,false);
  84. cleanPage();
  85.  
Add Comment
Please, Sign In to add comment