SSL Accelerator

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

  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.8
  6. // @license CC0 1.0 Universal; http://creativecommons.org/publicdomain/zero/1.0/
  7. // @include *
  8. // @require https://cdnjs.cloudflare.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. // @namespace https://greasyfork.org/users/4614
  12. // ==/UserScript==
  13.  
  14. var alreadyHandshakedWith = {};
  15. var requestStartTime = {};
  16. var handshakeStartDelayTimerID = 0;
  17.  
  18. var currentHostname = (new URI(window.location.href)).hostname();
  19.  
  20. $("body").on("mouseenter mouseover", "a", function (e)
  21. {
  22. if (e.target.href == undefined)
  23. {
  24. //console.log("Ignoring link with undefined HREF property.");
  25. return;
  26. }
  27. var targetURI = new URI(e.target.href);
  28. var targetProtocol = targetURI.protocol();
  29. var targetHostname = targetURI.hostname();
  30. if (targetProtocol != "https" ||
  31. targetHostname == currentHostname)
  32. {
  33. return;
  34. }
  35. if (alreadyHandshakedWith[targetHostname])
  36. {
  37. //console.log("Already started or completed a handshake with \"" + targetHostname + "\".");
  38. return;
  39. }
  40. clearTimeout(handshakeStartDelayTimerID);
  41. handshakeStartDelayTimerID = setTimeout(function ()
  42. {
  43. console.log("Handshaking with \"" + targetHostname + "\"..");
  44. GM_xmlhttpRequest({
  45. method: "HEAD",
  46. url: "https://" + targetHostname,
  47. onload: function()
  48. {
  49. console.log("Successfully handshaked with \"" + targetHostname + "\" in " + (Date.now() - requestStartTime[targetHostname]) + "ms.");
  50. requestStartTime[targetHostname] = undefined;
  51. },
  52. });
  53. requestStartTime[targetHostname] = Date.now();
  54. alreadyHandshakedWith[targetHostname] = true;
  55. }, 100);
  56. });
  57.  
  58. $("body").on("mouseout", "a", function (e)
  59. {
  60. clearTimeout(handshakeStartDelayTimerID);
  61. });