The following code is for changing the innerHTML of an element ( myNote
) to the value of another element ( myInput
), each time Returning strong>:
setTimeout(()=>{
let myInput = document.querySelector('._7q434._1qCW5._2fPEB._3_NyK._1Juqt._3WbPm');
let myNote = document.createElement('div');
document.body.appendChild(myNote);
myNote.setAttribute("style", "position: fixed; bottom: 0; right: 0; display: block; width: 400px; height: 400px; background: orange; color: #000");
myInput.addEventListener('keydown', (k)=>{
if ( k.keyCode === 13 ) {
myNote.innerHTML += myInput.value + '<br>';
}
});
}, 2000);
purpose
I run the code in Greasemonkey on duolingo.com (a site for learning mind2mind languages such as French), in textual sessions of questions such as “translate this sentence”.
The purpose of the code is to create a small orange frame containing the inputs that I have already tried on Duolingo questions, given that Duolingo does not save them.
With a script, I could save them and then use them if I answer a language question, as it will save me some time by renaming most of the sentence.
Problem
, innerHTML
. , Return, .
, Greasemonkey ( ) duolingo.com.
innerHTML
? , addEventListener
, ?
return
return false
.
, , , .
Mobius:
Mobius, , , :
setTimeout(()=>{
window.myCss =`.note {position: fixed; bottom: 0; right: 0; width: 400px; height: 400px; background: orange}`;
style = document.createElement("style");
style.type = "text/css";
style.styleSheet ? style.styleSheet.cssText = myCss : style.appendChild(document.createTextNode(myCss) );
head = document.head || document.getElementsByTagName("head")[0];
head.appendChild(style);
let note = document.createElement('div');
note.classList.add('note');
document.querySelector('body').appendChild(note);
let savedValue;
document.addEventListener('keydown', (e)=>{
let target = e.target;
if (target.nodeName === 'textarea') {
savedValue = e.target.value;
}
});
if (k.keyCode === 13) {
setTimeout(()=>{
document.querySelector('textarea').value = savedValue;
}, 100);
}
}, 2500);
.
, , ( , html
textarea
, , . , , ...