YouTube Sticky LiveChat

Pin the latest message written by Live owner or moderator to the top

目前為 2020-05-05 提交的版本,檢視 最新版本

// ==UserScript==
// @name         YouTube Sticky LiveChat
// @namespace    https://i544c.github.io
// @version      0.3.1
// @description  Pin the latest message written by Live owner or moderator to the top
// @author       i544c
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(() => {
    let chatframe = null;
    const main = () => {
        console.log('Found LiveChat frame');
        const style = document.createElement('style');
        style.textContent = `
yt-live-chat-app {
/* Global variables */
--line-length: 3;
--message-height: calc(1em * var(--line-length) + 4px);
}

#item-offset {
overflow: visible !important;
}

#items {
transform: none !important;
}

yt-live-chat-text-message-renderer[author-type="owner"],
yt-live-chat-text-message-renderer[author-type="moderator"] {
background: var(--yt-spec-general-background-b);
position: sticky;
top: -1px;
z-index: 1;
height: var(--message-height);
min-height: var(--message-height);
}

yt-live-chat-text-message-renderer[author-type="owner"]:hover,
yt-live-chat-text-message-renderer[author-type="moderator"]:hover {
height: 100% !important;
}

yt-live-chat-text-message-renderer[author-type="owner"] #content,
yt-live-chat-text-message-renderer[author-type="moderator"] #content {
align-self: normal;
/* String truncate */
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: var(--line-length);
overflow: hidden;
}

yt-live-chat-text-message-renderer[author-type="owner"] #content:hover,
yt-live-chat-text-message-renderer[author-type="moderator"] #content:hover {
-webkit-box-orient: inline-axis;
}
`;
        chatframe.contentDocument.body.appendChild(style);
    };

    const findInterval = window.setInterval(() => {
        console.log('Search LiveChat frame');
        chatframe = document.querySelector('#chatframe');
        if (chatframe) {
            chatframe.onload = main;
            window.clearInterval(findInterval);
        }
    }, 1000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址