SSL Accelerator

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

目前為 2014-08-29 提交的版本,檢視 最新版本

  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.7
  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. // @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. if (e.target.href == undefined)
  24. {
  25. //GM_log("Ignoring link with undefined HREF property.");
  26. return;
  27. }
  28. var targetURI = new URI(e.target.href);
  29. var targetProtocol = targetURI.protocol();
  30. var targetHostname = targetURI.hostname();
  31. if (targetProtocol != "https" ||
  32. targetHostname == currentHostname)
  33. {
  34. return;
  35. }
  36. if (alreadyHandshakedWith[targetHostname])
  37. {
  38. //GM_log("Already started or completed a handshake with \"" + targetHostname + "\".");
  39. return;
  40. }
  41. clearTimeout(handshakeStartDelayTimerID);
  42. handshakeStartDelayTimerID = setTimeout(function ()
  43. {
  44. GM_log("Handshaking with \"" + targetHostname + "\"..");
  45. GM_xmlhttpRequest({
  46. method: "HEAD",
  47. url: "https://" + targetHostname,
  48. onload: function()
  49. {
  50. GM_log("Successfully handshaked with \"" + targetHostname + "\" in " + (Date.now() - requestStartTime[targetHostname]) + "ms.");
  51. requestStartTime[targetHostname] = undefined;
  52. },
  53. });
  54. requestStartTime[targetHostname] = Date.now();
  55. alreadyHandshakedWith[targetHostname] = true;
  56. }, 100);
  57. });
  58.  
  59. $("body").on("mouseout", "a", function (e)
  60. {
  61. clearTimeout(handshakeStartDelayTimerID);
  62. });