google_direct_link

Google direct link for avoiding laggy '/url?' link.

  1. // ==UserScript==
  2. // @name google_direct_link
  3. // @namespace http://catherine.v0cyc1pp.com/google_direct_link.user.js
  4. // @match https://www.google.tld/search*
  5. // @match https://www.google.com/?*
  6. // @run-at document-end
  7. // @author greg10
  8. // @license GPL 3.0
  9. // @version 2.2
  10. // @grant none
  11. // @description Google direct link for avoiding laggy '/url?' link.
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. // [desctiption details]
  16. // This script will replace links on google search results.
  17. // from
  18. // https://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjzmeD83cnQAhVBPpQKHQtkC6wQFggbMAA&url=http%3A%2F%2Fwww.nyc.gov%2F&usg=AFQjCNGtbMsqtosAyddPnaeiyyG142mO3A&bvm=bv.139782543,d.dGo
  19. // to
  20. //http://www.nyc.gov/
  21. //
  22. // for avoiding laggy '/url?' link.
  23.  
  24.  
  25. function replacelink(elem) {
  26. var str = elem.getAttribute("href");
  27. //console.log("str="+str);
  28. if ( str == null || str == undefined ) {
  29. return;
  30. }
  31. var result = str.match( /&url=([^&]+)&/ );
  32. if ( result == null || result == undefined ) {
  33. return;
  34. }
  35. var direct = result[1];
  36. if ( direct == null || direct == undefined ) {
  37. return;
  38. }
  39.  
  40. var decoded = decodeURIComponent( direct );
  41. elem.setAttribute("href", decoded);
  42. elem.setAttribute("ping", str);
  43.  
  44. }
  45.  
  46. function main() {
  47. document.querySelectorAll('a').forEach( function(elem) {
  48. replacelink(elem);
  49. });
  50. }
  51.  
  52.  
  53. var observer = new MutationObserver(function(mutations) {
  54. observer.disconnect();
  55. main();
  56. observer.observe( document, config);
  57. });
  58.  
  59. var config = { attributes: true, childList: true, characterData: true, subtree:true };
  60.  
  61. observer.observe( document, config);
  62.  
  63.  
  64.