I'm trying this code to apply new design on the Google Tasks page with the extension Tampermonkey.
When I try html{ display: none !important }
then It displays nothing as the html
tag is not under iframe
.
however, I couldn't modify under iframe[src="about:blank"]
element.
How should I modify to make it work?
shot 1. : Doesn't work for inside of iframe[src="about:blank"]
// ==UserScript==
// @name test
// @match https://mail.google.com/tasks/canvas
// @match about:blank
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle ( `
* {color: red !important}
` );
Yes, scripting for iframes with
src="about:blank"
can be tricky as the normal userscript mechanisms do not work the same. (Currently,@match about:blank
does not work, but it would be a bad idea to use it here anyway, since it would have global side effects.)Fortunately, on Chrome, iframes with
src="about:blank"
almost always have adocumentElement
by the time a Tampermonkey script runs, so you do not normally need to wait if you are just adding CSS.Here is a complete working script, that styles that first iframe:
If the
<iframe>
tag is javascript created, or other delays hamper the above...Use the
iframeSelector
parameter ofwaitForKeyElements
to work around that.The trick is to pick a node that always appears in the finished iframe, and pass that to waitForKeyElements.
The node should be unique.
But for the following example I used
.goog-toolbar:first
as a quick first attempt.Here is that complete working script:
Notes:
GM_addStyle()
will not work in this case, so we add styles with a frame-aware function.