google_direct_link

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

当前为 2016-11-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name google_direct_link
  3. // @namespace http://catherine.v0cyc1pp.com/google_direct_link.user.js
  4. // @include https://www.google.co.jp/search*
  5. // @run-at document-end
  6. // @author greg10
  7. // @license GPL 3.0
  8. // @version 1.3
  9. // @require http://code.jquery.com/jquery-3.1.1.min.js
  10. // @grant none
  11. // @description Google direct link for avoiding laggy '/url?' link.
  12. // ==/UserScript==
  13.  
  14. // [desctiption details]
  15. // This script will replace link google search results.
  16. //
  17. //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
  18. // to
  19. //http://www.nyc.gov/
  20. //
  21. // for avoiding laggy '/url?' link.
  22.  
  23. this.$ = this.jQuery = jQuery.noConflict(true);
  24. //console.log("google_direct_link start");
  25.  
  26. function replacelink(target) {
  27. var str = $(target).attr("href");
  28. //console.log("str="+str);
  29. if ( str === null || str === undefined ) {
  30. return;
  31. }
  32. var result = str.match( /&url=([^&]+)&/ );
  33. if ( result !== null && result !== undefined ) {
  34. var direct = result[1];
  35. if ( direct !== null && direct !== undefined ) {
  36. var decoded = decodeURIComponent( direct );
  37. $(target).attr("href", decoded);
  38. /*
  39. var decoded = decodeURI( direct );
  40. var decoded_str2 = decoded.replace( /%3A/g , ":" ) ;
  41. var decoded_str3 = decoded_str2.replace( /%2F/g , "/" ) ;
  42. var decoded_str4 = decoded_str3.replace( /%3F/g , "?" ) ;
  43. var decoded_str5 = decoded_str4.replace( /%3D/g , "=" ) ;
  44. var decoded_str6 = decoded_str5.replace( /%23/g , "#" ) ;
  45. $(target).attr("href", decoded_str6);
  46. */
  47. }
  48. }
  49. }
  50.  
  51. function main() {
  52. $("h3 > a").each( function() {
  53. replacelink(this);
  54. });
  55. $("div > a").each( function() {
  56. replacelink(this);
  57. });
  58. }
  59.  
  60.  
  61. var observer = new MutationObserver(function(mutations) {
  62. observer.disconnect();
  63. main();
  64. observer.observe( document, config);
  65. });
  66.  
  67. var config = { attributes: true, childList: true, characterData: true, subtree:true };
  68.  
  69. observer.observe( document, config);
  70.  
  71.