I'm trying to create a Tampermonkey script for a website running Xenforo. Specifically I'm trying to target the WYSIWYG editor iframe and run the script when I edit the content but I just don't know how to do it.
If I target the website itself, the script doesn't run when editing the content in the iframe. The source code doesn't have a src
tag, and if I check the Chrome inspector the frame in question is on about:blank
To answer my own question, here's a more detailed explanation on how I got it to work.
In the userscript header, include waitForKeyElements
:
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
Then in the code section:
waitForKeyElements (
'body',
r,
false,
'.redactor_textCtrl'
);
function r(jNode) {
'use strict';
jNode[0].addEventListener('keyup', function(e) {
console.log(e);
}, false);
}
This allowed me to act upon changes in the text editor.