delay buildChannelButton to account for UI refresh on YT

This commit is contained in:
Simon 2023-11-03 12:05:17 +07:00
parent 976fefbf89
commit aaa04a43b5
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 22 additions and 15 deletions

View File

@ -6,6 +6,7 @@ module.exports = {
}, },
env: { env: {
browser: true, browser: true,
es6: true,
}, },
globals: { globals: {
browser: 'readonly', browser: 'readonly',

View File

@ -124,13 +124,13 @@ function isElementVisible(element) {
function ensureTALinks() { function ensureTALinks() {
let channelContainerNodes = getChannelContainers(); let channelContainerNodes = getChannelContainers();
for (let channelContainer of channelContainerNodes) { for (let channelContainer of channelContainerNodes) {
channelContainer = adjustOwner(channelContainer); channelContainer = adjustOwner(channelContainer);
if (channelContainer.hasTA) continue; if (channelContainer.hasTA) continue;
let channelButton = buildChannelButton(channelContainer);
channelContainer.appendChild(channelButton);
channelContainer.hasTA = true; channelContainer.hasTA = true;
buildChannelButton(channelContainer).then(channelButton => {
channelContainer.appendChild(channelButton);
});
} }
let titleContainerNodes = getTitleContainers(); let titleContainerNodes = getTitleContainers();
@ -150,19 +150,25 @@ function adjustOwner(channelContainer) {
} }
function buildChannelButton(channelContainer) { function buildChannelButton(channelContainer) {
let channelHandle = getChannelHandle(channelContainer); return new Promise(resolve => {
let buttonDiv = buildChannelButtonDiv(); let buttonDiv;
let channelSubButton;
let spacer;
let channelDownloadButton;
let channelSubButton = buildChannelSubButton(channelHandle); // Delayed execution for interface to refresh
buttonDiv.appendChild(channelSubButton); setTimeout(() => {
const channelHandle = getChannelHandle(channelContainer);
let spacer = buildSpacer(); buttonDiv = buildChannelButtonDiv();
buttonDiv.appendChild(spacer); channelSubButton = buildChannelSubButton(channelHandle);
spacer = buildSpacer();
let channelDownloadButton = buildChannelDownloadButton(); channelDownloadButton = buildChannelDownloadButton();
buttonDiv.appendChild(channelDownloadButton); buttonDiv.appendChild(channelSubButton);
buttonDiv.appendChild(spacer);
return buttonDiv; buttonDiv.appendChild(channelDownloadButton);
resolve(buttonDiv);
}, 2000);
});
} }
function getChannelHandle(channelContainer) { function getChannelHandle(channelContainer) {