如何使用没有YouTube API的JavaScript获取YouTube视频的标题?

发布于 2025-02-07 00:56:22 字数 170 浏览 3 评论 0原文

我正在制作Chrome扩展名,我需要获取YouTube视频的标题。我不想使用YouTube API。

这是我的内容脚本中的代码

I am making a chrome extension and I need to grab the title of youtube videos. I don't want to use the youtube api.

Here is the code in my content script

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琴流音 2025-02-14 00:56:22

通过执行var videotitle = document.title.split(“ - youtube”)[0];来解决它。

Solved it by doing var videotitle = document.title.split(" - YouTube")[0];

岛歌少女 2025-02-14 00:56:22

您可以在后台获取标题标题。JS,它将返回YouTube视频标题

chrome.tabs.onActivated.addListener(function (activeInfo) {
chrome.tabs.get(activeInfo.tabId, function (tab) {
    console.log("Title: " + tab.title);
});

});

You can grab the tab title in the background.js, it will return the youtube video title

chrome.tabs.onActivated.addListener(function (activeInfo) {
chrome.tabs.get(activeInfo.tabId, function (tab) {
    console.log("Title: " + tab.title);
});

});

晒暮凉 2025-02-14 00:56:22

您还可以在F12开发人员工具中使用此代码线:

ytinitialplayersponse.videodetails.title

同样的代码也应在您的扩展程序上工作。

You can also use this line of code in the F12 developer tools:

ytInitialPlayerResponse.videoDetails.title

The same line of code should work on your extension as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文