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.0
  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.  
  17. var handshakeStartDelayTimerID = 0;
  18. var currentRequest = null;
  19.  
  20. var currentHostname = (new URI(window.location.href)).hostname();
  21.  
  22. $("body").on("mouseenter", "a", function (e)
  23. {
  24. var targetURI = new URI(e.target.href);
  25. var targetProtocol = targetURI.protocol();
  26. var targetHostname = targetURI.hostname();
  27. if (targetProtocol != "https" ||
  28. targetHostname == currentHostname)
  29. {
  30. return;
  31. }
  32. if (alreadyHandshakedWith[targetHostname])
  33. {
  34. GM_log("Already handshaked with " + targetHostname);
  35. return;
  36. }
  37.  
  38. clearTimeout(handshakeStartDelayTimerID);
  39. handshakeStartDelayTimerID = setTimeout(function ()
  40. {
  41. GM_log("Handshaking with \"" + targetHostname + "\"..");
  42. currentRequest = GM_xmlhttpRequest({
  43. method: "HEAD",
  44. url: "https://" + targetHostname,
  45. onload: function()
  46. {
  47. GM_log("Successfuly handshaked with \"" + targetHostname + "\".");
  48. currentRequest = null;
  49. },
  50. });
  51. alreadyHandshakedWith[targetHostname] = true;
  52. }, 100);
  53. });
  54.  
  55. $("body").on("mouseout", "a", function (e)
  56. {
  57. clearTimeout(handshakeStartDelayTimerID);
  58. });