Skip to content

Commit

Permalink
Used storage values to reduce querySelector requests until necessary …
Browse files Browse the repository at this point in the history
…for checks.
  • Loading branch information
kjonathan024 committed Feb 7, 2024
1 parent c153207 commit 03e0502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
21 changes: 10 additions & 11 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,11 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () {
var otherButton = document.querySelector('#it-repeat-button');

function matchLoopState(opacity) {
var otherButton = document.querySelector('#it-repeat-button');
if (otherButton) {
if (ImprovedTube.storage.player_repeat_button === true) {
var otherButton = document.querySelector('#it-repeat-button');
otherButton.children[0].style.opacity = opacity;
svg.style.opacity = opacity;
}
else {
svg.style.opacity = opacity;
}
svg.style.opacity = opacity;
}

button.onclick = function () {
Expand All @@ -373,11 +370,13 @@ ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer = function () {
svg.appendChild(path); button.appendChild(svg);
section.insertAdjacentElement('afterend', button)

if(otherButton && otherButton.children[0].style.opacity === '1') {
var video = ImprovedTube.elements.video;
matchLoopState('1');
if (!video.hasAttribute('loop')) {
video.setAttribute('loop', '');
if(ImprovedTube.storage.player_repeat_button === true) {
if (document.querySelector('#it-repeat-button').style.opacity === '1') {
matchLoopState('1');
var video = ImprovedTube.elements.video;
if (!video.hasAttribute('loop')) {
video.setAttribute('loop', '');
}
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,13 @@ ImprovedTube.playerRepeatButton = function (node) {
svg.setAttributeNS(null, 'viewBox', '0 0 24 24');
path.setAttributeNS(null, 'd', 'M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4zm-4-2V9h-1l-2 1v1h1.5v4H13z');
svg.appendChild(path);
var otherButton = document.querySelector('#it-below-player-loop');

function matchLoopState(opacity) {
var otherButton = document.querySelector('#it-below-player-loop');
if (otherButton) {
if (ImprovedTube.storage.below_player_loop !== false) {
var otherButton = document.querySelector('#it-below-player-loop');
otherButton.children[0].style.opacity = opacity;
svg.style.opacity = opacity;
}
else {
svg.style.opacity = opacity;
}
svg.style.opacity = opacity;
}

this.createPlayerButton({
Expand All @@ -711,11 +707,13 @@ ImprovedTube.playerRepeatButton = function (node) {
},
title: 'Repeat',
});

if(otherButton && otherButton.children[0].style.opacity === '1') {
matchLoopState('1');
if (!video.hasAttribute('loop')) {
video.setAttribute('loop', '');
if(ImprovedTube.storage.below_player_loop !== false) {
var otherButton = document.querySelector('#it-below-player-loop');
if (document.querySelector('#it-below-player-loop').style.opacity === '1') {
matchLoopState('1');
if (!video.hasAttribute('loop')) {
video.setAttribute('loop', '');
}
}
}

Expand Down

0 comments on commit 03e0502

Please sign in to comment.