zengyunsi
(运思 曾)
September 15, 2023, 2:34pm
1
I want to change a style for video in discourse, how to embed JavaScript script before ,</body>
tag
Tried editing it in the HEAD, it doesn’t work perfectly!
Thanks!
<script src="/plyr.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const player = new Plyr('video');
});
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Video Player</title>
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.12/plyr.css">
<script src="https://cdn.plyr.io/3.6.12/plyr.js"></script>
</head>
<body>
<video controls>
<source src="your-video.mp4" type="video/mp4">
</video>
<script>
document.addEventListener('DOMContentLoaded', function () {
const player = new Plyr('video');
});
</script>
</body>
</html>
pfaffman
(Jay Pfaffman)
September 15, 2023, 3:54pm
2
Where are you changing it? In a theme component that you created in the UX? (I don’t know what that image is.)
Lhc_fl
(Linca)
September 16, 2023, 2:06pm
4
It is most likely because you have not added this domain name to the CSP Policy.
很有可能是因为你没有把这个域名加入CSP Policy。
And to be honest, I recommend you to copy this js file directly and throw it in the <script>
tag to prevent users from loading js from an external website. This is not safe - unless you completely trust this website.
而且说实话,我更推荐你直接把这个js文件复制过来扔在<script>
标签里,以免用户还要加载外部网站的js,这并不能说安全——除非你完全信任这个网站
1 Like
zengyunsi
(运思 曾)
September 16, 2023, 3:38pm
5
主要是这一句啊,前面的都不是问题
<script>
document.addEventListener('DOMContentLoaded', function () {
const player = new Plyr('video');
});
</script>
</body>
zengyunsi
(运思 曾)
September 16, 2023, 3:40pm
6
只能放在body结尾,这个是等页面加载完了,初始化播放器的
Lhc_fl
(Linca)
September 16, 2023, 3:41pm
7
你可以用一下discourse plugin-api
You can use the discourse plugin api.
<script type="text/discourse-plugin" version="0.8">
api.decorateCookedElement((elem, helper) => {
const player = new Plyr('video');
}, {id: "beauitfy-video"})
</script>
Ah, you only need to load once? Then pretend I didn’t say it
啊你只需要一次load?那当我没说
运思 曾:
只能放在body结尾
这毫无关系。你不是有eventListener吗?
It makes no difference. Don’t you have an eventListener?
system
(system)
Closed
October 17, 2023, 3:31am
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.