I use a site that looks like this:
...
<body>
<iframe src="blabla/blabla..."></iframe>
</body>
...
The iframe loads a different HTML file from the same domain; it has it’s own body
In Firebug, it looks like this:
...
<body>
<iframe src="blabla/blabla...">
...
<body class="classname ">
...
</body>
</iframe>
</body>
...
The problem is this: the site would be way easier to view, if I could add a second class name to the second body, like this:
...
<body>
<iframe src="blabla/blabla...">
...
<body class="classname classname2">
...
</body>
</iframe>
</body>
...
I do not own the domain, I just want to ‘remix’ the web content.
I tried stuff like this:
// ==UserScript==
// @name descr
// @namespace http://localhost
// @description descr
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// @include http://web.site/sub.ab*
// ==/UserScript==
$("iframe").load(function(){
alert(document.getElementById('frameid').contentDocument);
});
They idea was to use
document.getElementById('frameid').contentDocument.document.getElementsByTagName('body')[0].addClass('classname2')
But it does not work. Tried the same using contentwindow, nothing again. Alert tells me there is a element specified: [object HTMLDocument] but when I type anything beyond that, like .document the alert becomes empty, or won’t show at all.
What am I doing wrong?
Edit: Not sure if this has anything to do with it, but I forgot to tell there are actually 2 iframes: one is being blocked by Adblocker, this is why I did not mention this before.
In Greasemonkey it’s really easy. A GM script will fire on an iFrame, much like it would on the containing page.
So, if you create a second GM script like this:
It will work with no fuss.
Note that you can do everything with only one GM script, but that can get tricky if you’re not careful. Keep it simple, for now.