HTTP TO HTTPS with Blacklist

自动将HTTP网页跳转为HTTPS,并支持黑名单功能

  1. // ==UserScript==
  2. // @name HTTP TO HTTPS with Blacklist
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description 自动将HTTP网页跳转为HTTPS,并支持黑名单功能
  6. // @license MIT
  7. // @include /.*/
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. !function() {
  15. "use strict";
  16. const host = location.host;
  17. const isHttps = location.protocol === "https:";
  18. // 黑名单管理
  19. const blacklist = (() => {
  20. const get = () => GM_getValue("blacklist", []);
  21. const set = list => GM_setValue("blacklist", list);
  22. return { get, set };
  23. })();
  24.  
  25. // 重定向判断逻辑
  26. const shouldRedirect = () =>
  27. !blacklist.get().includes(host) &&
  28. !isHttps &&
  29. GM_getValue(host, 1) === 1;
  30.  
  31. function redirectToHttps() {
  32. if (shouldRedirect()) {
  33. location.href = location.href.replace(/^http/, "https");
  34. }
  35. }
  36.  
  37. // 菜单命令系统
  38. const createMenu = () => {
  39. const isBlacklisted = blacklist.get().includes(host);
  40. GM_registerMenuCommand(
  41. `[${host}] ${isBlacklisted ? '移除黑名单' : '加入黑名单'}`,
  42. () => {
  43. const newList = isBlacklisted
  44. ? blacklist.get().filter(h => h !== host)
  45. : [...new Set([...blacklist.get(), host])];
  46. blacklist.set(newList);
  47. alert(isBlacklisted ? '已移出黑名单' : '已加入黑名单');
  48. }
  49. );
  50. };
  51.  
  52. redirectToHttps();
  53. createMenu();
  54. }();

QingJ © 2025

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