google_direct_link

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

目前為 2017-01-08 提交的版本,檢視 最新版本

  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.4
  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. }
  40. }
  41. }
  42.  
  43. function main() {
  44. $("a").each( function() {
  45. replacelink(this);
  46. });
  47. }
  48.  
  49.  
  50. var observer = new MutationObserver(function(mutations) {
  51. observer.disconnect();
  52. main();
  53. observer.observe( document, config);
  54. });
  55.  
  56. var config = { attributes: true, childList: true, characterData: true, subtree:true };
  57.  
  58. observer.observe( document, config);
  59.  
  60.