I'm trying to enhance a GUI of one of our tools, but I'm failing miserably. The UI consists of a body with multiple iFrames from which I want to select one and change the content a bit.
The problem is that when using my selector frame = $("iframe[src*='/vs/virt.jsp']");
it looks like it can't find the element.
Here's the code (doesn't do anything else than log):
// ==UserScript==
// @name UI Tweaks
// @version 0.2
// @description Does stuff
// @match https://*.local/vs/*
// @run-at document-end
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
console.log(window.location);
console.log("before");
console.log($());
frame = $("iframe[src*='/vs/virt.jsp']");
console.log(frame.attr("id"));
console.log("after");
When running this on the page I get two page loads and it shows the location object, before and after. But the frame object is totally empty.
However, when running the same thing in Chrome developer console after the page has loaded I get the elements I'm looking for.
I've tried different ways to only load the script after page load etc, but it still does not work.
Update:
I added:
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
Then tried this:
waitForKeyElements (
"iframe[src*='/vs/virt.jsp']",
test()
);
function test(){
frame = $("iframe[src*='/vs/virt.jsp']");
console.log(frame.attr("id"));
}
Still the same result. Worth noting is that I use Tampermonkey, but perhaps it's the same?
Edit 2:
function timer() {
frame = $("iframe[src*='/vs/virt.jsp']");
console.log(frame.attr("id"));
setTimeout(timer, 1000);
}
timer();
It keeps outputting "undefined" whereas if I try it in Chrome developer console I get the object. It's like Tampermonkey does not have access?