From 13739c6b233872e1e3821d974e59136ab65f4fb1 Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Tue, 30 Oct 2018 18:10:57 +0100 Subject: [PATCH] Fixed YouTube links were not recolored --- extension/content.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/extension/content.js b/extension/content.js index 659557c..2f94c68 100644 --- a/extension/content.js +++ b/extension/content.js @@ -25,6 +25,10 @@ if (hostname == 'twitter.com') { myself = document.querySelector('.DashUserDropdown-userInfo a'); } +if (isHostedOn(hostname, 'youtube.com')) { + setInterval(updateYouTubeChannelHeader, 300); +} + if (myself && (myself.href || myself.startsWith('http:') || myself.startsWith('https:'))) myself = getIdentifier(myself); //console.log('Myself: ' + myself) @@ -61,6 +65,38 @@ function init() { } + +var lastAppliedYouTubeUrl = null; +var lastAppliedYouTubeTitle = null; + +function updateYouTubeChannelHeader(){ + var url = window.location.href; + var title = document.getElementById('channel-title'); + var currentTitle = title ? title.textContent : null; + + if(url == lastAppliedYouTubeUrl && currentTitle == lastAppliedYouTubeTitle) return; + lastAppliedYouTubeUrl = url; + lastAppliedYouTubeTitle = currentTitle; + + if(currentTitle) { + var replacement = document.getElementById('channel-title-replacement'); + if(!replacement) { + replacement = document.createElement('A'); + replacement.id = 'channel-title-replacement' + replacement.className = title.className; + title.parentNode.insertBefore(replacement, title.nextSibling); + title.style.display = 'none'; + replacement.style.fontSize = '2.4rem'; + replacement.style.fontWeight = '400'; + replacement.style.lineHeight = '3rem'; + replacement.style.textDecoration = 'none'; + } + replacement.textContent = lastAppliedYouTubeTitle; + replacement.href = lastAppliedYouTubeUrl; + } + updateAllLabels(); +} + function updateAllLabels(refresh) { if (refresh) knownLabels = {}; var links = document.links;