Skip to content

Commit

Permalink
better iframe searching
Browse files Browse the repository at this point in the history
  • Loading branch information
mart2070 committed May 3, 2024
1 parent eb20a22 commit 86232c6
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions tdx-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,21 @@
}

function injectOtherStyles(element) {
//find iframes - likely text editors
if (element.tagName == "IFRAME") {
let frame = element.contentWindow.document

let e = frame.querySelector("head")
console.warn("Got iframe!",frame)
console.log("Found iFrame:",frame)

let s = document.createElement("style")
s.innerText = customStyles
//check for existing style block
if (!frame.querySelector("#customStyles")) {
let head = frame.querySelector("head")
let s = document.createElement("style")
s.id = "customStyles"
s.innerText = customStyles

e.appendChild(s)
head.appendChild(s)
}
}
}

Expand All @@ -341,13 +346,12 @@
parseTable(mutation)
}

let editor = t.querySelector(".cke_wysiwyg_frame")
let editorDrop = t.querySelector(".cke_panel_frame")
if (editor) {
injectOtherStyles(editor)
}
if (editorDrop) {
injectOtherStyles(editorDrop)
//search whole document, frames may reset when reopened
let frames = document.querySelectorAll("iframe")
if (frames) {
[...frames].forEach(frame=>{
injectOtherStyles(frame)
});
}
});
});
Expand Down

0 comments on commit 86232c6

Please sign in to comment.