Skip to content

Commit

Permalink
bugfix(shields): Fix pulse on some subreddits with Shields and Night …
Browse files Browse the repository at this point in the history
…Mode enabled on iOS (#27240)

* Avoid loop for any element moving below our stylesheet.
  • Loading branch information
StephenHeaps authored Jan 16, 2025
1 parent 9aee54d commit 20cf651
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,24 @@ window.__firefox__.execute(function($) {
styleElm.setAttribute('type', 'text/css')
targetElm.appendChild(styleElm)
CC.cosmeticStyleSheet = styleElm
// The previous `nextElementSibling` we moved our stylesheet below
var prevNextElementSibling = null;

// Start a timer that moves the stylesheet down
window.setInterval(() => {
if (styleElm.nextElementSibling === null || styleElm.parentElement !== targetElm) {
return
}
if (styleElm.nextElementSibling !== null) {
// if we already moved below this element
if (prevNextElementSibling === styleElm.nextElementSibling) {
// Avoid a loop where we are repeatedly swapping places with another
// element. This can happen with `darkreader` (night mode) for
// example and cause unwanted animations to repeat.
return
}
prevNextElementSibling = styleElm.nextElementSibling;
}
moveStyle()
}, 1000)
}
Expand Down

0 comments on commit 20cf651

Please sign in to comment.