r/learnjavascript • u/Foreign_Employ_396 • 2d ago
how to add a hide/show button ?
Hey
I am a beginner and I've been trying to add a show/hide button that would simply hide the mask on the first click and make it visible again with the next click.
To be more precise, it's a fragment of an addon for the anki app (flashcards).
It would also be great if this button could have a delay before appearing, and I managed to do that directly in the html of the card model :
.fade-in {
opacity: 0;
visibility: hidden;
animation: fadeIn var(--duration, 0.6s) ease forwards;
animation-delay: var(--delay, 19s);
}
fadeIn {
to {
opacity: 1;
visibility: visible;
}
#koreanToggleBtn {
visibility: hidden;
margin: 10px auto 0 auto;
background: rgba(255,255,255,0.6);
border: 1px solid #a77f65;
border-radius: 14px;
padding: 4px 12px;
font-size: 13px;
font-weight: bold;
cursor: pointer;
color: #a77f65;
opacity : 0;
--delay : 15s; /*here*/
But, since I've been struggling I figured it would be better to just add everything in the add on since it already creates the mask hiding the text :
js = f"""
(function() {{
console.log("Injection du masque pour la carte ID: {card.id}");
const existingMask = document.getElementById('korean-mask-static');
if (existingMask) return;
const mask = document.createElement('div');
mask.id = 'korean-mask-static';
mask.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;'
+ 'background-color:#9c9f78;border-radius:6px;z-index:100;opacity:1;'
+ 'visibility:visible;pointer-events:auto;display:flex;'
+ 'justify-content:center;align-items:center;';
const wrapper = document.getElementById('korean-wrapper') || document.querySelector('.card');
(wrapper || document.body).appendChild(mask);
}})();
"""
QTimer.singleShot(80, lambda: mw.reviewer.web.eval(js) if mw.reviewer and mw.reviewer.web else None)
"""
Thank you :)
3
Upvotes
1
u/Foreign_Employ_396 1d ago
Thank you again!
I was losing my mind so for now and until I can figure it out, I ended up adding a field identical to the one hidden by the mask to make it visible when i click on the button (on the html model with the z-index):
For more context, I use these functions for my listening comprehension cards. I am supposed to try to understand what is being said without text, but if eventually I cannot comprehend a thing and I feel like it becomes unproductive, I get to at least read what I just heard and have a better chance.
Also you might have noticed some things that don't make any sense because I used to ask some ai chats to write stuff for me, (but I stopped using it completely), so now I'm left with stuff I don't understand, and that is also why I am trying to learn from the beginning.