Invisible Macro/Meme: STFU
Summary:
For more than 10 years it was possible to troll your coworkers with
infinite audio loops, by typing a macro/meme in a comment box,
previewing, and then writing something else. This was happening
since macros may become hidden but still loaded in the DOM and,
in that case, they may play forever, until the page is destroyed.
The annoying sounds were also continuing when enjoying a meme and then
clicking on a different link, since page loads are often done by ajax,
effectively causing invisible memes in the DOM playing rickroll forever.
After this patch, no more audio from invisible macro/meme, effectively
implementing the beloved "STFU" alghorithm.
https://en.wikipedia.org/wiki/STFU
Note: you may appreciate that the audio volume still decreases
if you scroll up/down distant from a meme.
So, sounds are not really that annoying. Not even audio loops!
If a particular macro is annoying, then scroll down, or file a
severe complaint to your favorite Phorge admin to de-activate
that audio.
This patch is designed after D26674, to be not destructive.
Additionally, done small refactor to avoid 'statics.items[ii].element',
which can be written as just 'item.element'.
Closes T16486
Closes T16451
Test Plan:
Preamble: always click somewhere in the page for all tests,
otherwise modern browser webs like Firefox will likely deny audio,
even if you scroll straight to a meme.
-----
Locally, create a weird image macro (http://phorge.localhost/macro/create/)
for example called "freebird" and upload the sound of an epic
mp3 file, like the solo of Free Bird by Lynyrd Skynyrd, which is
somehow long. Example mp3:
https://quicksounds.com/sound/23840/free-bird-solo
Now, do the tests:
Write 'freebird' in a comment in a preview. Enjoy audio.
Remove 'freebird' from the preview, enjoy NO AUDIO \o/
Write 'freebird' in a comment and save. Enjoy audio.
Click a different link (e.g. 'Edit Task'). enjoy NO AUDIO \o/
Check for regressions in normal workflows:
Write 'freebird' in a comment and save. Enjoy audio.
Scroll distant from the meme, enjoy decreasing volume.
Scroll nearby the meme, enjoy increasing volume.
If it's a loop, the audio continues.
If it's not a loop, the audio terminates after the first run.
Reviewers: aklapper, O1 Blessed Committers
Reviewed By: aklapper, O1 Blessed Committers
Subscribers: tobiaswiese, Matthew, Cigaryno
Maniphest Tasks: T16451, T16486
Differential Revision: https://we.phorge.it/D26722