Skip to content

Instantly share code, notes, and snippets.

@piousdeer
Last active August 7, 2020 08:12
Show Gist options
  • Save piousdeer/ae73578c7866deadecec20c84783baa0 to your computer and use it in GitHub Desktop.
Save piousdeer/ae73578c7866deadecec20c84783baa0 to your computer and use it in GitHub Desktop.
A script/bookmarklet to reveal a YouTube video's tags (obsolete)
// Basically, this is a minimal version of this extension:
// https://chrome.google.com/webstore/detail/tags-for-youtube/dggphokdgjikekfiakjcpidcclbmkfga
void async function () {
if (!location.href.includes('/watch?v=') || window.tagsAreRevealed) return
window.tagsAreRevealed = true
const superTitle = document.querySelector('.super-title')
addEventListener('yt-page-data-updated', function cleanup () {
window.tagsAreRevealed = false
removeAllChildren(superTitle)
removeEventListener('yt-page-data-updated', cleanup)
})
const endpoint = 'https://www.googleapis.com/youtube/v3/videos'
const key = 'AIzaSyBvQ04s8qzIgDSEVXwEK4U9lEklPPxWUnQ'
// Note: the key above is NOT a secret. It was generated using these settings:
// * Where will you be calling the API from? [ Web browser (JavaScript) ]
// * What data will you be accessing? [ Public data ]
// * Only accept requests from: [ https://*.youtube.com/* ]
// It cannot be used to access user data. Google just uses it for rate limiting.
const videoId = new URLSearchParams(location.search).get('v')
const json = await (await fetch(`${endpoint}?part=snippet&fields=items(snippet(tags))&id=${videoId}&key=${key}`)).json()
const tags = (json.items[0] && json.items[0].snippet.tags) || []
for (const tag of tags) {
superTitle.innerHTML += `<a class='tag' style="margin: 0 ${superTitle.children.length > 0 ? 4 : 0}px; text-decoration: none; color: #909090;" href="/results?search_query=${tag}">${tag}</a>`
}
function removeAllChildren (node) {
while (node.firstChild) node.removeChild(node.firstChild)
}
}()
!async function(){if(!location.href.includes("/watch?v=")||window.tagsAreRevealed)return;window.tagsAreRevealed=!0;const e=document.querySelector(".super-title");addEventListener("yt-page-data-updated",function t(){window.tagsAreRevealed=!1,function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}(e),removeEventListener("yt-page-data-updated",t)});const t=new URLSearchParams(location.search).get("v"),a=await(await fetch(`https://www.googleapis.com/youtube/v3/videos?part=snippet&fields=items(snippet(tags))&id=${t}&key=AIzaSyBvQ04s8qzIgDSEVXwEK4U9lEklPPxWUnQ`)).json(),n=a.items[0]&&a.items[0].snippet.tags||[];for(const t of n)e.innerHTML+=`<a class='tag' style="margin: 0 ${e.children.length>0?4:0}px; text-decoration: none; color: #909090;" href="/results?search_query=${t}">${t}</a>`}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment