Skip to content

Instantly share code, notes, and snippets.

@nc7s
Last active October 19, 2023 07:04
Show Gist options
  • Save nc7s/4d8782b75dce60e2a6110afc8997604a to your computer and use it in GitHub Desktop.
Save nc7s/4d8782b75dce60e2a6110afc8997604a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 苹果园 HTTPS 化脚本
// @description 将页面内所有链接和表单的指向改为 HTTPS,保证全站升级到 HTTPS 前的安全性
// @match https://www.goddessfantasy.net/*
// @match http://www.goddessfantasy.net/*
// @version 0.1.3
// @updateURL https://gist.github.com/nc7s/4d8782b75dce60e2a6110afc8997604a/raw/goddessfantasy-https.user.js
// @downloadURL https://gist.github.com/nc7s/4d8782b75dce60e2a6110afc8997604a/raw/goddessfantasy-https.user.js
// ==/UserScript==
// 0.1.3 修复引用快速回复时弹出回复框依然使用 HTTP URL 发出 XHR 请求的问题
// 0.1.3 设置更新 URL
// 0.1.2 将 [...arr] 降级为 Array.from() 以兼容 TamperMonkey
const HTTP_START = 'http://www.goddessfantasy.net'
const HTTPS_START = 'https://www.goddessfantasy.net'
Array.from(document.querySelectorAll('a')).forEach(a => {
if(a.href.toLowerCase().startsWith(HTTP_START)) {
a.href = HTTPS_START + a.href.slice(HTTP_START.length)
}
});
Array.from(document.querySelectorAll('form')).forEach(f => {
if(f.action.toLowerCase().startsWith(HTTP_START)) {
f.action = HTTPS_START + f.action.slice(HTTP_START.length)
}
});
// 当 oQuickReply.bCollapsed 为 false 时,引用回复调用的 oQuickReply.quote
// 会发起一个 XHR 请求拉取回复内容,而这个请求是 HTTP 的;请求的 URL 是用
// oQuickReply.opt.sScriptUrl 组合其他参数得到的,在此将其改为 HTTPS
//
if(unsafeWindow.oQuickReply !== undefined) {
unsafeWindow.oQuickReply.opt.sScriptUrl = oQuickReply.opt.sScriptUrl
.toLowerCase()
.replace(HTTP_START, HTTPS_START)
}
@refparo
Copy link

refparo commented Jan 17, 2023

这样会把指向不支持 https 的网站的链接(尤其是指向果园 IP 的链接)也全都改成 https,导致这些链接无法正常打开。最好只修改指向果园域名的链接吧?

@nc7s
Copy link
Author

nc7s commented Jan 17, 2023

@refparo 确实,谢谢提醒。

@refparo
Copy link

refparo commented Jan 17, 2023

不知道为什么 Firefox + Tampermonkey 好像不支持 [...arr] 的语法……

@nc7s
Copy link
Author

nc7s commented Jan 17, 2023

@refparo 确实,降级到 Array.from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment