SSL Accelerator

Speculatively performs SSL/TLS handshakes for hovered links to speed up browsing.

目前为 2014-08-22 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SSL Accelerator
  3. // @description Speculatively performs SSL/TLS handshakes for hovered links to speed up browsing.
  4. // @author Anon
  5. // @version 0.1.4
  6. // @license Public domain
  7. // @include *
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.11.2/URI.min.js
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_log
  12. // @namespace https://greasyfork.org/users/4614
  13. // ==/UserScript==
  14.  
  15. var alreadyHandshakedWith = {};
  16. var requestStartTime = {};
  17. var handshakeStartDelayTimerID = 0;
  18.  
  19. var currentHostname = (new URI(window.location.href)).hostname();
  20.  
  21. $("body").on("mouseenter mouseover", "a", function (e)
  22. {
  23. var targetURI = new URI(e.target.href);
  24. var targetProtocol = targetURI.protocol();
  25. var targetHostname = targetURI.hostname();
  26. if (targetProtocol != "https" ||
  27. targetHostname == currentHostname)
  28. {
  29. return;
  30. }
  31. if (alreadyHandshakedWith[targetHostname])
  32. {
  33. GM_log("Already handshaked with " + targetHostname);
  34. return;
  35. }
  36.  
  37. clearTimeout(handshakeStartDelayTimerID);
  38. handshakeStartDelayTimerID = setTimeout(function ()
  39. {
  40. GM_log("Handshaking with \"" + targetHostname + "\"..");
  41. GM_xmlhttpRequest({
  42. method: "HEAD",
  43. url: "https://" + targetHostname,
  44. onload: function()
  45. {
  46. GM_log("Successfuly handshaked with \"" + targetHostname + "\" in " + (Date.now() - requestStartTime[targetHostname]) + "ms.");
  47. requestStartTime[targetHostname] = undefined;
  48. },
  49. });
  50. requestStartTime[targetHostname] = Date.now();
  51. alreadyHandshakedWith[targetHostname] = true;
  52. }, 100);
  53. });
  54.  
  55. $("body").on("mouseout", "a", function (e)
  56. {
  57. clearTimeout(handshakeStartDelayTimerID);
  58. });