Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions js&css/extension/www.youtube.com/appearance/sidebar/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,27 @@ html[it-livechat='collapsed'] #chat-container::before {
align-items: center !important;
}

html[it-livechat='collapsed'] #chat-container:not([it-activated]) > ytd-live-chat-frame#chat,
html[it-livechat='collapsed'][it-livechat='hidden'] ytd-live-chat-frame#chat {
/* #4199 - YouTube stretches #chat-container to the player height. Cap the
collapsed shell at the 48px "Show live chat" bar so the column under it
does not stay blank. [it-activated] stays unconstrained so the bar can
restore YouTube's chat height. */
html[it-livechat='collapsed'] #chat-container:not([it-activated]) {
height: 48px !important;
max-height: 48px !important;
min-height: 0 !important;
flex: 0 0 auto !important;
overflow: hidden !important;
top: auto !important;
bottom: auto !important;
}

html[it-livechat='collapsed'] #chat-container:not([it-activated]) ytd-live-chat-frame#chat,
html[it-livechat='collapsed'] #chat-container:not([it-activated]) iframe#chatframe {
display: none !important;
}

html[it-livechat='collapsed']
#chat-container:not([it-activated])::before,
#chat-container[it-activated]::before {
html[it-livechat='collapsed'] #chat-container:not([it-activated])::before,
html[it-livechat='collapsed'] #chat-container[it-activated]::before {
background-color: #272727 !important;
border-radius: 8px !important;
cursor: pointer;
Expand Down
4 changes: 2 additions & 2 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ ImprovedTube.ytElementsHandler = function (node) {
ImprovedTube.elements.subscribe_button = node;
ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer();
} else if (id === 'chat-messages') {
this.elements.livechat.button = document.querySelector('[aria-label="Close"]');
// console.log(document.querySelector('[aria-label="Close"]'))
var chatRoot = node.closest('yt-live-chat-renderer, ytd-live-chat-frame, #chat-container');
this.elements.livechat.button = chatRoot ? chatRoot.querySelector('button[aria-label="Close"]') : null;
this.livechat();
} else if (name === 'YTD-MASTHEAD') {
if (!this.elements.masthead) {
Expand Down
17 changes: 7 additions & 10 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,14 @@ ImprovedTube.chapters = function (el) { if (ImprovedTube.storage.chapters === tr
------------------------------------------------------------------------------*/
ImprovedTube.livechat = function () {
if (this.storage.livechat === "collapsed") {
if (typeof isCollapsed === 'undefined') { var isCollapsed = false; }
if (ImprovedTube.elements.livechat && !isCollapsed) {
ImprovedTube.elements.livechat.button.click();
isCollapsed = true
var button = this.elements.livechat && this.elements.livechat.button;
if (button && !this.elements.livechat.collapsed) {
button.click();
this.elements.livechat.collapsed = true;
}
} /* else{
if(isCollapsed){
ImprovedTube.elements.livechat.button.click();
isCollapsed = false
}
} */
} else if (this.elements.livechat) {
this.elements.livechat.collapsed = false;
}
};
/*------------------------------------------------------------------------------
DETAILS
Expand Down
97 changes: 97 additions & 0 deletions tests/unit/livechat-collapsed.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Test for Issue #4199: collapsed live chat leaves a blank column

const fs = require('fs');
const path = require('path');

describe('Collapsed live chat shell (#4199)', () => {
let sidebarCss;
let appearanceJs;
let functionsJs;

beforeAll(() => {
sidebarCss = fs.readFileSync(
path.join(__dirname, '../../js&css/extension/www.youtube.com/appearance/sidebar/sidebar.css'),
'utf8'
);
appearanceJs = fs.readFileSync(
path.join(__dirname, '../../js&css/web-accessible/www.youtube.com/appearance.js'),
'utf8'
);
functionsJs = fs.readFileSync(
path.join(__dirname, '../../js&css/web-accessible/functions.js'),
'utf8'
);
});

test('should cap an inactive collapsed chat shell at the show-live-chat bar', () => {
const rule = sidebarCss.match(
/html\[it-livechat='collapsed'\] #chat-container:not\(\[it-activated\]\)\s*\{([^}]*)\}/
);
expect(rule).not.toBeNull();
const body = rule[1];
expect(body).toMatch(/height:\s*48px\s*!important/);
expect(body).toMatch(/max-height:\s*48px\s*!important/);
expect(body).toMatch(/min-height:\s*0\s*!important/);
expect(body).toMatch(/flex:\s*0\s+0\s+auto\s*!important/);
expect(body).toMatch(/overflow:\s*hidden\s*!important/);
expect(body).toMatch(/top:\s*auto\s*!important/);
expect(body).toMatch(/bottom:\s*auto\s*!important/);
expect(sidebarCss).toContain("content: 'Show live chat' !important;");
});

test('should hide a nested live chat frame and chatframe while the shell is collapsed', () => {
expect(sidebarCss).toMatch(
/html\[it-livechat='collapsed'\] #chat-container:not\(\[it-activated\]\) ytd-live-chat-frame#chat\s*,\s*html\[it-livechat='collapsed'\] #chat-container:not\(\[it-activated\]\) iframe#chatframe\s*\{[^}]*display:\s*none\s*!important/
);
expect(sidebarCss).not.toContain("html[it-livechat='collapsed'][it-livechat='hidden']");
});

test('should drop the shell cap once the bar sets it-activated', () => {
expect(sidebarCss).not.toMatch(
/html\[it-livechat='collapsed'\] #chat-container\[it-activated\]\s*\{[^}]*height\s*:/
);
expect(sidebarCss).not.toMatch(
/html\[it-livechat='collapsed'\] #chat-container\[it-activated\]\s*\{[^}]*display\s*:\s*none/
);
});

test('should scope both live chat bar backgrounds to collapsed mode', () => {
expect(sidebarCss).toMatch(
/html\[it-livechat='collapsed'\] #chat-container:not\(\[it-activated\]\)::before\s*,\s*html\[it-livechat='collapsed'\] #chat-container\[it-activated\]::before\s*\{[^}]*background-color/
);
expect(sidebarCss).not.toMatch(/(?:^|\n)[ \t]*#chat-container\[it-activated\]::before/);
});

test('should keep hidden mode and the theatre full-bleed collapse, and add nothing for normal', () => {
expect(sidebarCss).toContain("html[it-livechat='hidden'] ytd-live-chat-frame#chat");
expect(sidebarCss).toMatch(
/html\[it-livechat='hidden'\] ytd-watch-flexy\[theater\] #panels-full-bleed-container:not\(:has\(ytd-engagement-panel-section-list-renderer\[visibility='ENGAGEMENT_PANEL_VISIBILITY_EXPANDED'\]\)\)/
);
expect(sidebarCss).toContain(
"html[it-livechat='collapsed'] ytd-watch-flexy[theater]:has(#chat-container:not([it-activated])) #panels-full-bleed-container"
);
expect(sidebarCss).toContain(
"html[it-livechat='collapsed'] ytd-watch-flexy[fixed-panels] #columns.ytd-watch-flexy:has(#chat-container:not([it-activated]) > ytd-live-chat-frame#chat)"
);
expect(sidebarCss).not.toMatch(/it-livechat='normal'/);
});

test('should click a chat-scoped Close button at most once while collapsed', () => {
const livechat = appearanceJs.match(/ImprovedTube\.livechat\s*=\s*function\s*\(\)\s*\{([\s\S]*?)\n\};/);
expect(livechat).not.toBeNull();
const body = livechat[1];
expect(body).not.toContain('isCollapsed');
expect(body).toMatch(
/if\s*\(\s*this\.storage\.livechat === "collapsed"\s*\)\s*\{[\s\S]*if\s*\(\s*button && !this\.elements\.livechat\.collapsed\s*\)\s*\{[\s\S]*button\.click\(\);[\s\S]*this\.elements\.livechat\.collapsed = true;[\s\S]*\}\s*else if\s*\(\s*this\.elements\.livechat\s*\)\s*\{[\s\S]*this\.elements\.livechat\.collapsed = false;/
);

const chatBranch = functionsJs.match(/else if \(id === 'chat-messages'\) \{([\s\S]*?)\n\t\} else if/);
expect(chatBranch).not.toBeNull();
const branch = chatBranch[1];
expect(branch).toContain("node.closest('yt-live-chat-renderer, ytd-live-chat-frame, #chat-container')");
expect(branch).toContain('button[aria-label="Close"]');
expect(branch).toContain(': null');
expect(branch).toContain('this.livechat()');
expect(branch).not.toContain('document.querySelector');
});
});
Loading