组合Bookmarklets以在HTTP和HTTPS之间创建切换

Combining Bookmarklets to create a toggle between HTTP and HTTPS?

本文关键字:之间 创建 HTTPS Bookmarklets 以在 HTTP 组合      更新时间:2023-09-26

通过在这里搜索,我现在有了两个bookmarklet,它们从/切换到HTTP/HTTPS:-

javascript:location=location.href.replace(/http:/g,"https:")

而且。。。

javascript:location=location.href.replace(/https:/g,"http:")

但是,有没有办法将它们组合成一个小书签,根据当前加载的书签从一个切换到另一个?

这个线程有点旧,但我在其他任何地方都找不到更好的答案。

javascript:((function(){window.location=location.href.replace(/^http/i,"https").replace(/^http'w{2,}/i,"http");})())

是完全格式的bookmarklet代码,应该可以在任何浏览器中使用。

location.href.replace(/^http/i,"https").replace(/^http'w{2,}/i,"http")
if (window.location.protocol == 'http:') window.location.protocol = 'https:'
else window.location.protocol = 'http:'

然后你所需要做的就是将其格式化为书签。享受