유튜브 채널 아이디 확인용
// 유튜브 채널에서 channelId 추출 (콘솔용)
(function(){
// 1. <meta itemprop="channelId" ...>
let meta = document.querySelector('meta[itemprop="channelId"]');
if (meta && meta.content) {
console.log("[channelId]", meta.content);
alert("채널ID: " + meta.content);
return meta.content;
}
// 2. ytInitialData/ytcfg 등에서 찾기 (핸들형 등 최신채널)
let m = document.documentElement.innerHTML.match(/"channelId":"(UC[a-zA-Z0-9_-]{21,})"/);
if (m && m[1]) {
console.log("[channelId]", m[1]);
alert("채널ID: " + m[1]);
return m[1];
}
// 3. <link rel="canonical" ...>에서 추출 (채널 URL에 포함될 경우)
let link = document.querySelector('link[rel="canonical"]');
if (link && link.href) {
let uc = link.href.match(/\/channel\/(UC[a-zA-Z0-9_-]{21,})/);
if (uc && uc[1]) {
console.log("[channelId]", uc[1]);
alert("채널ID: " + uc[1]);
return uc[1];
}
}
alert("채널ID를 찾을 수 없습니다. 채널 홈/정보/스트림 탭에서 다시 시도해 보세요.");
return null;
})();
#유튭채널id확인용 #메모