Discussions » Demandes de création de scripts
[Youtube] parse channel name into <title> tag
Here's a different approach:
// ==UserScript==
// @name YouTube Channel in Title
// @match https://*.youtube.com/*
// @grant none
// ==/UserScript==
'use strict';
let title = '';
const mo = new MutationObserver(() => {
mo.disconnect();
pinTitle();
});
pinTitle();
function pinTitle() {
title = document.title.replace(' - YouTube', '');
if (location.pathname.startsWith('/watch')) {
const owner = document.querySelector('ytd-channel-name').innerText;
const date2 = document.querySelector('#date > yt-formatted-string.ytd-video-primary-info-renderer').innerText;
title = `- ${title} -- ${owner}- -- ${date2}`;
}
document.title = title;
mo.observe(document.querySelector('title'), {
characterData: true,
childList: true,
});
}
hi. thank you
unfortunately nothing is happening.
I'm on firefox Version 88.0.1, Build ID 20210504152106
It works for me in Firefox + Greasemonkey/Violentmonkey/Tampermonkey.
Just created a fresh profile. Out of 50 opened tabs it maybe worked three times :S
unfortunately it didn't work once during the video
here's a video https://vimeo.com/545810573
password is: aaaaaaaaaaaa
I was testing in one tab... If no one else posts their solution, I'll make another try later.
alright thanks man
Why have you posted a video from Vimeo?
This script is only supposed to work on YT, maybe that's why you're saying it doesn't work
this was just to show how it works.
This seems to work correctly:
// ==UserScript==
// @name YouTube Channel in Title
// @match https://*.youtube.com/*
// @grant none
// ==/UserScript==
'use strict';
const mo = new MutationObserver(pinTitle);
const $ = (sel, node = document) => node.querySelector(sel);
pinTitle();
document.addEventListener('yt-navigate-finish', pinTitle);
function pinTitle() {
let title = document.title.replace(' - YouTube', '');
if (location.pathname.startsWith('/watch')) {
const name = $('.title')?.innerText || title;
const owner = $('ytd-channel-name')?.innerText;
const date2 = $('#date > yt-formatted-string.ytd-video-primary-info-renderer')?.innerText;
title = `- ${name || ''} -- ${owner || ''}- -- ${date2 || ''}`;
}
if (document.title !== title) {
mo.disconnect();
document.title = title;
mo.observe($('title'), {characterData: true, childList: true});
}
}
nvm. solved it. thank you very much
const owner = $('a.yt-simple-endpoint.style-scope.yt-formatted-string')?.innerText;
also it seems like your script doesn't make the title vanish. because that's the problem I had with the other one.
after about ten minutes the title would refresh and I had to trigger the script by either pressing the bell,
right-clicking the video or hovering around the video timeline. (that's why the weird mouse movements in the video above.)
where can I send dono?
hey. just wanted to drop by and give you another thanks. the script works wonderfully.
now not even the title changes when the bell has notifications.
It used to prefix the title with the amount of notifications pending in the inbox like: (6) -title-
thanks man
hello
Up until today I ran the following script but it seems Youtube must've changed something bc the script goes into an endless loop now.
Could someone revise the code and help me out?