Enforce HTTPS

Automatically change HTTP URLs to HTTPS, when possible.

  1. // ==UserScript==
  2. // @name Enforce HTTPS
  3. // @namespace i2p.schimon.enforce-https
  4. // @description Automatically change HTTP URLs to HTTPS, when possible.
  5. // @author Schimon Jehudah, Adv.
  6. // @homepageURL https://gf.qytechs.cn/en/scripts/465953-enforce-https
  7. // @supportURL https://gf.qytechs.cn/en/scripts/465953-enforce-https/feedback
  8. // @copyright 2023 - 2024, Schimon Jehudah (http://schimon.i2p)
  9. // @license MIT; https://opensource.org/licenses/MIT
  10. // @run-at document-start
  11. // @match http://*/*
  12. // @connect self
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM.xmlHttpRequest
  15. // @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjRtbSIgaGVpZ2h0PSI2NG1tIiB2aWV3Qm94PSIwIDAgNjQgNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHRleHQgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgc3R5bGU9ImZvbnQtd2VpZ2h0OjQwMDtmb250LXNpemU6MTkycHg7bGluZS1oZWlnaHQ6MDt0ZXh0LWluZGVudDowO3RleHQtYWxpZ246c3RhcnQ7dGV4dC1kZWNvcmF0aW9uLXN0eWxlOnNvbGlkO3RleHQtZGVjb3JhdGlvbi1jb2xvcjojMDAwO3dyaXRpbmctbW9kZTpsci10YjtkaXJlY3Rpb246bHRyO3RleHQtb3JpZW50YXRpb246bWl4ZWQ7ZG9taW5hbnQtYmFzZWxpbmU6YXV0bztiYXNlbGluZS1zaGlmdDpiYXNlbGluZTt0ZXh0LWFuY2hvcjpzdGFydDtzaGFwZS1wYWRkaW5nOjA7c2hhcGUtbWFyZ2luOjA7aW5saW5lLXNpemU6MDtvcGFjaXR5OjE7ZmlsbDojMDAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZS13aWR0aDoxLjI3OTgyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxO3N0b3AtY29sb3I6IzAwMDtzdG9wLW9wYWNpdHk6MSIgeD0iMTcuMDA1MjQ1IiB5PSIzMS42NTg0MDUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC00LjQzNjg1NjQgNDAuODk0OTQpIHNjYWxlKC4yNjQ1OCkiPjx0c3BhbiB4PSIxNy4wMDUyNDUiIHk9IjMxLjY1ODQwNSIgc3R5bGU9ImZvbnQtc2l6ZToxOTJweCI+8J+boe+4jzwvdHNwYW4+PC90ZXh0Pjwvc3ZnPgo=
  16. // @version 24.04
  17. // ==/UserScript==
  18.  
  19. // @makyen
  20. // /greasemonkey/greasemonkey/issues/3160#issuecomment-1456758080
  21. const gmXmlhttpRequest = typeof GM_xmlhttpRequest === 'function' ? GM_xmlhttpRequest : GM.xmlHttpRequest;
  22.  
  23. if (!location.protocol.startsWith('http:')) return; // exit (else, continue)
  24.  
  25. var newURL = location.href.replace('http:','https:');
  26.  
  27. gmXmlhttpRequest({
  28. method: 'GET',
  29. url: newURL,
  30. onprogress: console.log('Checking for https...'),
  31. onload: function(response) {
  32. if (response.finalUrl == newURL && response.status == 200) {
  33. location.href = newURL;
  34. console.info(`Successfully redirected to https (Response status: ${response.status}).`);
  35. } else {
  36. console.log(`No https access available (Response status: ${response.status}).`);
  37. }
  38. },
  39. onerror: function(response) {
  40. console.log('Error requesting for https.')
  41. }
  42. })
  43.  
  44. /*
  45. fetch(newURL)
  46. .then((response) => {
  47. if (request.reseponseURL == newURL) {
  48. window.open(newURL,'_self');
  49. }
  50. })
  51. */

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址