Skip to content

Instantly share code, notes, and snippets.

@azurenekowo
Last active November 22, 2023 16:32
Show Gist options
  • Save azurenekowo/0886cb68b1f658cf15e3b1beb93d0667 to your computer and use it in GitHub Desktop.
Save azurenekowo/0886cb68b1f658cf15e3b1beb93d0667 to your computer and use it in GitHub Desktop.
Replicate Genshin Impact's cutscenes with subtitles styling for video on the official channel.

GenshinCGS (CG Subtitles)

Replicate Genshin Impact's cutscenes with styled subtitles on videos.
image

Installation

Userscript

(You will need an userscripts manager like Violentmonkey to be able to use this script)

// ==UserScript==
// @name GenshinCGS
// @namespace https://me.azuree.moe
// @version 1.0
// @description Replicate Genshin Impact's cutscene experience on videos' subtitles.
// @author azuryymiko
// @match https://www.youtube.com/*
// @icon https://raw.githubusercontent.com/azurenekowo/ayaka/main/resources/favicon.ico
// @grant none
// ==/UserScript==
// Customization
const cssUrl = 'https://me.azuree.moe/rawassets/yt-genshin-subs.css'
const genshinChannels = [
'@GenshinImpact',
'@GenshinImpact_ZH',
'@GenshinImpact_KR',
'@GenshinImpact_JP'
]
// This involves using a non-standard JS event.
// Changes and breaks may occur. I will do my best to update for it.
window.addEventListener('yt-page-data-updated', onVideoLoad)
function onVideoLoad() {
if(window.location.pathname == '/watch') {
const channelHandle = `@${document.querySelector('yt-formatted-string.ytd-channel-name a').toString().split('/@')[1]}`
if(genshinChannels.includes(channelHandle)) {
console.log('%c[GenshinCGS]', 'color: #ae81ff', 'Detected video on one of Genshin\'s official channels. Injecting CSS...')
var subtitleCSS = document.createElement('link')
subtitleCSS.href = cssUrl
subtitleCSS.type = 'text/css'
subtitleCSS.rel = 'stylesheet'
subtitleCSS.id = 'subtitleCSSInjector'
document.getElementsByTagName('head')[0].appendChild(subtitleCSS)
console.log('%c[GenshinCGS]', 'color: #ae81ff', 'Successfully injected CSS into subtitles display.')
console.log('%c[GenshinCGS]', 'color: #ae81ff', 'Seems like my work here is done. Cya~')
}
else {
disableCSSInjection()
}
}
else {
disableCSSInjection()
}
}
function disableCSSInjection() {
if(document.getElementById('subtitleCSSInjector')) {
document.getElementById('subtitleCSSInjector').remove()
console.log('%c[GenshinCGS]', 'color: #ae81ff', 'Successfully un-injected GenshinCGS. You may now play the video as normal')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment