我刚刚从 2.5.0.beta4 更新到了 2.5.0.beta5,现在我的主题中原本运行的两个脚本似乎无法执行了。我在浏览器控制台中看到了以下信息:
Content Security Policy: Sivuston asetukset estivät resurssin lataamisen osoitteesta inline ("script-src"). injectGlobalHook.js:1:1760
Content Security Policy: Sivuston asetukset estivät resurssin lataamisen osoitteesta inline ("script-src"). pagewrap.bundle.js:1:1151
编辑:看起来我在另一个没有使用相同主题的网站上也遇到了同样的问题,所以这应该不是主题的问题。那么是不是主题 API 发生了变化?尽管这个主题帖并没有更新:Using the JS API
基本上,似乎是新的 Discourse 更新使得 CSP(内容安全策略)变得更加严格了。
我该如何解决这个问题?我在发布说明中没有找到任何关于 CSP 或主题变更的说明。
这是我想要运行的脚本:
<script type="text/discourse-plugin" version="0.0.1">
api.onPageChange(() => {
checkMainPageLoadFeeds();
});
function checkMainPageLoadFeeds() {
// 仅在主页加载
// 由于 Discourse 的工作方式,这似乎并不能完美生效,
// 但至少不会引起任何问题...
if(/https?:\/\/[^\/]+\/(categories)?$/.test(window.location.href) ){
// 这些文件是由运行在与本论坛相同服务器上的机器人创建的
if($("#development-info").text() == ""){
$("#development-info").load("/thrive-feed-bot/devforum-and-github");
$("#announcement-contents").load("/thrive-feed-bot/community-announcements");
}
}
$("#development-heading").off("click").on("click", expandTheFeeds);
$("#announcement-heading").off("click").on("click", expandTheFeeds);
}
function expandTheFeeds(){
let target = $("#development-feed").height() == 200 ? 450 : 200;
$('#development-feed').animate({ height: target + "px" });
$('#development-info').animate({ height: (target - 95) + "px" });
$('#announcement-feed').animate({ height: target + "px" });
$('#announcement-contents').animate({ height: (target - 95) + "px" });
}
$( document ).ready(function(){
checkMainPageLoadFeeds();
})
</script>
这是第二个脚本:
<script type="text/discourse-plugin" version="0.0.1">
api.onAppEvent('modal:body-shown', (data) => {
if(data.title){
if(data.title.match(/.*create.*account.*/)){
$(".create-account.fixed-modal .modal-footer").prepend(getEmailSpamCheckMessage(true));
}
} else {
// 可能是忘记密码的情况
let element = $(".fixed-modal .forgot-password-modal")
if(element){
element.append(getEmailSpamCheckMessage(false));
}
}
});
function getEmailSpamCheckMessage(register){
return $.parseHTML("<p class='EmailNoteMessage'>如果你没有收到邮件 " +
(register ? "确认" : "") + "请检查你的垃圾邮件文件夹。<br>" +
"如果遇到问题,你也可以访问我们的 <a href='https://discordapp.com/invite/FZxDQ4H'>Discord</a> " +
(register ? "注册" : "接收我们的邮件") + "。</p>");
}
</script>
我确定我之前在这里的 Meta 上发布过这些内容,但现在找不到那个帖子了。
