Skip to content

Commit

Permalink
delay buildChannelButton to account for UI refresh on YT
Browse files Browse the repository at this point in the history
  • Loading branch information
bbilly1 committed Nov 3, 2023
1 parent 976fefb commit aaa04a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
env: {
browser: true,
es6: true,
},
globals: {
browser: 'readonly',
Expand Down
36 changes: 21 additions & 15 deletions extension/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ function isElementVisible(element) {

function ensureTALinks() {
let channelContainerNodes = getChannelContainers();

for (let channelContainer of channelContainerNodes) {
channelContainer = adjustOwner(channelContainer);
if (channelContainer.hasTA) continue;
let channelButton = buildChannelButton(channelContainer);
channelContainer.appendChild(channelButton);
channelContainer.hasTA = true;
buildChannelButton(channelContainer).then(channelButton => {
channelContainer.appendChild(channelButton);
});
}

let titleContainerNodes = getTitleContainers();
Expand All @@ -150,19 +150,25 @@ function adjustOwner(channelContainer) {
}

function buildChannelButton(channelContainer) {
let channelHandle = getChannelHandle(channelContainer);
let buttonDiv = buildChannelButtonDiv();

let channelSubButton = buildChannelSubButton(channelHandle);
buttonDiv.appendChild(channelSubButton);

let spacer = buildSpacer();
buttonDiv.appendChild(spacer);

let channelDownloadButton = buildChannelDownloadButton();
buttonDiv.appendChild(channelDownloadButton);
return new Promise(resolve => {
let buttonDiv;
let channelSubButton;
let spacer;
let channelDownloadButton;

return buttonDiv;
// Delayed execution for interface to refresh
setTimeout(() => {
const channelHandle = getChannelHandle(channelContainer);
buttonDiv = buildChannelButtonDiv();
channelSubButton = buildChannelSubButton(channelHandle);
spacer = buildSpacer();
channelDownloadButton = buildChannelDownloadButton();
buttonDiv.appendChild(channelSubButton);
buttonDiv.appendChild(spacer);
buttonDiv.appendChild(channelDownloadButton);
resolve(buttonDiv);
}, 2000);
});
}

function getChannelHandle(channelContainer) {
Expand Down

0 comments on commit aaa04a4

Please sign in to comment.