r/learnjavascript • u/Foreign_Employ_396 • 29d ago
How to add elements (child) over an overlay ?
This function was initially creating an overlay appearing while I was modifying a card on anki.
For context, I started using the yomilens addon on anki which allows you to select some text and have a pop up show you the translation. The thing is, it only works on the "main" reviewer windows of the anki app. And what I want i to be able to select an english word and add many (if not all) of the ways to say it in korean in my card.
My first thought was to try to "force" the current card to keep showing me it's back with all the texts I need, but I couldn't.
Now I am trying to add the content of the two fields (id"korean" and id"SizeBump"=english) on the overlay, but being selectable to see if yomilens will react to it.
def pause_audio_for_edit():
/* Irrelevant I think
global _audio_paused_for_edit, _pending_audio_tags
print("[pause_audio] pause_audio_for_edit() appelée")
_audio_paused_for_edit = True
_pending_audio_tags = None
_force_stop_current_audio()*/
_show_edit_pause_overlay()
_EDIT_PAUSE_OVERLAY_JS = """
(function(){
var ov = document.getElementById('_editPauseOverlay');
/* Added
var butt = document.getElementById('button');
var board = document.getElementById('_editboard');
var kor = document.getElementById('korean');
var eng = document.getElementById('SizeBump'); */
if (ov) return;
ov = document.createElement('div');
ov.id = '_editPauseOverlay';
ov.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;'
+ 'background:rgba(20,20,20,0.96);color:#f7b799;display:flex;'
+ 'align-items:center;justify-content:center;text-align:center;'
+ 'font-family:sans-serif;font-size:16px;z-index:99999;cursor:pointer;'
+ 'padding:20px;box-sizing:border-box;';
ov.innerHTML = '\\u23F8\\uFE0F En pause \\u2014 modification en cours<br>'
+ '<span style="font-size:12px;opacity:0.7;">(cliquez n\\'importe o\\u00f9 pour reprendre)</span>';
/*added
+ '<span id='korean'</span> <span id='SizeBump'</span>';
butt = document.createElement('button');
butt.id
= 'button';
butt.style.cssText = 'position:fixed;top:10;left:0;width:10%;height:8%;'
+ 'background:rgba(255,255,255,0.6);color:#a77f65;display:flex;'
+ 'font-family:sans-serif;font-size:16px;font-weight: bold;z-index:99999;cursor:pointer;'
+ 'padding: 4px 12px;box-sizing:border-box;border-radius: 14px;margin: 10px auto 0 auto;border: 1px solid #a77f65;'
+ 'cursor: pointer;';
+ 'hover {background: rgba(255,255,255,0.9);}
butt.innerHTML = 'click when finished'*/// Used to be ov.addEventListener...butt.addEventListener('click', function(){if (typeof pycmd === 'function') pycmd('editpause:dismiss');ov.remove();
/*added thisbutt.remove();*/});document.body.appendChild(ov);
/*And thisdocument.body.appendChild(butt);or ov.appendChild(butt) ?*/
})();"""
def _show_edit_pause_overlay():if not mw.reviewer or not mw.reviewer.web:returnQTimer.singleShot(20, lambda: mw.reviewer.web.eval(_EDIT_PAUSE_OVERLAY_JS))
And as you can probably guess the overlay is not working at all now. Do you guys know what I have to fix to make it work ?
Thank you