Permalink
Browse files

Add CSS: recurse for frames and iframes

  • Loading branch information...
1 parent b0a4883 commit 51380bd98fe81c2e789789c563660deb6d1c98a7 @janmoesen committed Jul 2, 2012
Showing with 13 additions and 4 deletions.
  1. +2 −2 bookmarks.html
  2. +11 −2 development/addcss.js
View
@@ -42,12 +42,12 @@
See COPYING for licence details. Or "license details", if you are so inclined.
-These bookmarks were exported on Fri, 2012/05/11 07:15:20 +0200.</P>
+These bookmarks were exported on Mon, 2012/07/02 16:05:16 +0200.</P>
<DL><P>
<DT><H3>Development</H3>
<DD><P>Tools to help development.</P>
<DL><P>
- <DT><A HREF="javascript:%28function%20addcss%28%29%20%7Bvar%20s%20%3D%20%28%3C%3E%3C%21%5BCDATA%5B%s%5D%5D%3E%3C%2F%3E%20%2B%20%27%27%29.replace%28%2F%5Cu0025s%2F%2C%20%27%27%29%20%7C%7C%20getSelection%28%29%20%2B%20%27%27%20%7C%7C%20prompt%28%27Please%20enter%20your%20CSS%20code%3A%27%29%3Bif%20%28s%29%20%7Bdocument.head.appendChild%28document.createElement%28%27style%27%29%29.textContent%20%3D%20s%3B%7D%7D%29%28%29%3B" ADD_DATE="1322171557" LAST_MODIFIED="1322171557" SHORTCUTURL="addcss">Add CSS</A>
+ <DT><A HREF="javascript:%28function%20addcss%28document%29%20%7Bvar%20s%20%3D%20%28%3C%3E%3C%21%5BCDATA%5B%s%5D%5D%3E%3C%2F%3E%20%2B%20%27%27%29.replace%28%2F%5Cu0025s%2F%2C%20%27%27%29%20%7C%7C%20getSelection%28%29%20%2B%20%27%27%20%7C%7C%20prompt%28%27Please%20enter%20your%20CSS%20code%3A%27%29%3Bif%20%28s%29%20%7Bdocument.head.appendChild%28document.createElement%28%27style%27%29%29.textContent%20%3D%20s%3B%7Dtry%20%7BArray.prototype.slice.call%28document.querySelectorAll%28%27frame%2C%20iframe%2C%20object%5Btype%5E%3D%22text%2Fhtml%22%5D%2C%20object%5Btype%5E%3D%22application%2Fxhtml%2Bxml%22%5D%27%29%29.forEach%28function%20%28elem%29%20%7Baddcss%28elem.contentDocument%29%3B%7D%29%3B%7D%20catch%20%28e%29%20%7B%7D%7D%29%28document%29%3B" ADD_DATE="1322171557" LAST_MODIFIED="1341236147" SHORTCUTURL="addcss">Add CSS</A>
<DD><P>Add the specified CSS to the current document.</P></DD>
<DT><A HREF="javascript:%28function%20b64%28%29%20%7Bvar%20s%20%3D%20%28%3C%3E%3C%21%5BCDATA%5B%s%5D%5D%3E%3C%2F%3E%20%2B%20%27%27%29.replace%28%2F%5Cu0025s%2F%2C%20%27%27%29%20%7C%7C%20getSelection%28%29%20%2B%20%27%27%20%7C%7C%20prompt%28%27Please%20enter%20your%20text%3A%27%29%2C%20result%2C%20operation%3Bif%20%28s%29%20%7Btry%20%7Bif%20%28%21s.trim%28%29.match%28%2F%5E%5BA-Za-z0-9%2B%2F%5D%2B%28%5BA-Z%5D%5Ba-z%5D%7C%5Ba-z%5D%5BA-Z%5D%29%5BA-Za-z0-9%2B%2F%5D%2A%3D%7B0%2C2%7D%24%2F%29%29%20%7Bthrow%20%27I%20guess%20this%20should%20be%20encoded%2C%20rather%20than%20encoded.%27%3B%7Ds%20%3D%20s.trim%28%29%3Bresult%20%3D%20atob%28s%29%3Boperation%20%3D%20%27decoded%27%3B%7Dcatch%20%28e%29%20%7Bresult%20%3D%20btoa%28s%29%3Boperation%20%3D%20%27encoded%27%3B%7Dopen%28%27data%3Atext%2Fplain%3Bcharset%3DUTF-8%2C%27%20%2B%20encodeURIComponent%28%27The%20Base64%20%27%20%2B%20operation%20%2B%20%27%20string%20of%20%22%27%20%2B%20s%20%2B%20%27%22%20is%3A%5Cn%5Cn%27%20%2B%20result%29%29%3B%7D%7D%29%28%29%3B" ADD_DATE="1308256372" LAST_MODIFIED="1314697217" SHORTCUTURL="b64">Base64</A>
<DD><P>Convert plain text to Base64 and back. It determines which conversion to do.</P></DD>
View
@@ -3,9 +3,18 @@
*
* @title Add CSS
*/
-(function addcss() {
+(function addcss(document) {
var s = (<><![CDATA[%s]]></> + '').replace(/\u0025s/, '') || getSelection() + '' || prompt('Please enter your CSS code:');
if (s) {
document.head.appendChild(document.createElement('style')).textContent = s;
}
-})();
+
+ /* Recurse for frames and iframes. */
+ try {
+ Array.prototype.slice.call(document.querySelectorAll('frame, iframe, object[type^="text/html"], object[type^="application/xhtml+xml"]')).forEach(function (elem) {
+ addcss(elem.contentDocument);
+ });
+ } catch (e) {
+ /* Catch exceptions for out-of-domain access, but do not do anything with them. */
+ }
+})(document);

0 comments on commit 51380bd

Please sign in to comment.