Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update bookmarklet to support iframes in shadow dom #101

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions tests/tsbookmarklet.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<meta charset="UTF-8">

<title>text spacing bookmarklet</title>


<link rel="stylesheet prefetch" href="tsbookmarklet_files/styles.css">

<style>
Expand All @@ -21,27 +21,28 @@
margin-bottom: 2em !important;
} */
</style>

</head>

<body translate="no">

<h1>text spacing bookmarklet</h1>
<p>Last updated 3rd September 2021. Now recursively traverses through the Shadow DOM. <b>Thanks to Steven A. Hoffing</b></p>
<p>Last updated 11th October 2022. It now handles iframes located within in a Shadow DOM. <b>Thanks to Elliot Nahman</b></p>
<p>updated 3rd September 2021. Now recursively traverses through the Shadow DOM. <b>Thanks to Steven A. Hoffing</b></p>
<p>updated 18th May 2021. Now toggles on/off (first time you run it, it adds the styles ... second time, it removes them again) <b>Thanks to Patrick H. Lauke</b></p>
<p>updated 26th of March 2020. Now works on content inside same-origin first level <code>iframe</code>s - i.e. it doesn't then work if there's an <code>iframe</code> inside another <code>iframe</code>. <b>Thanks to Patrick H. Lauke</b></p>

<p>Quick and dirty testing of <a href="https://www.w3.org/TR/WCAG21/#text-spacing">WCAG 2.1 Success Criterion 1.4.12 Text Spacing</a>.

</p><p>Experimental:<strong>use at own risk!</strong>
</p><p>Bookmarklet: <a href="javascript:(function(){var d=document,id='phltsbkmklt',el=d.getElementById(id),f=d.querySelectorAll('iframe'),i=0,l=f.length;if(el){function removeFromShadows(root){for(var el of root.querySelectorAll('*')){if(el.shadowRoot){el.shadowRoot.getElementById(id).remove();removeFromShadows(el.shadowRoot);}}}el.remove();if(l){for(i=0;i<l;i++){try{f[i].contentWindow.document.getElementById(id).remove();removeFromShadows(f[i].contentWindow.document);}catch(e){console.log(e)}}}removeFromShadows(d);}else{s=d.createElement('style');s.id=id;s.appendChild(d.createTextNode('*{line-height:1.5 !important;letter-spacing:0.12em !important;word-spacing:0.16em !important;}p{margin-bottom:2em !important;}'));function applyToShadows(root){for(var el of root.querySelectorAll('*')){if(el.shadowRoot){el.shadowRoot.appendChild(s.cloneNode(true));applyToShadows(el.shadowRoot);}}}d.getElementsByTagName('head')[0].appendChild(s);for(i=0;i<l;i++){try{f[i].contentWindow.document.getElementsByTagName('head')[0].appendChild(s.cloneNode(true));applyToShadows(f[i].contentWindow.document);}catch(e){console.log(e)}}applyToShadows(d);}})();">Text Spacing</a> (drag to bookmarklets bar or right click and save as bookmark)
</p><p>Bookmarklet: <a href="javascript:(function(){var d=document,id='phltsbkmklt',el=d.getElementById(id),f=d.querySelectorAll('iframe'),i=0;if(el){function removeFromShadows(root){for(var el of root.querySelectorAll('*')){if(el.shadowRoot){el.shadowRoot.getElementById(id).remove();const frames = el.shadowRoot.querySelectorAll('iframe');removeFromIFrames(frames);removeFromShadows(el.shadowRoot);}}} function removeFromIFrames(frames){for(i=0;i<frames.length;i++){try{frames[i].contentWindow.document.getElementById(id).remove();removeFromShadows(frames[i].contentWindow.document);}catch(e){console.log(e)}}}el.remove();removeFromIFrames(f);removeFromShadows(d);}else{s=d.createElement('style');s.id=id;s.appendChild(d.createTextNode('*{line-height:1.5 !important;letter-spacing:0.12em !important;word-spacing:0.16em !important;}p{margin-bottom:2em !important;}'));function applyToShadows(root){for(var el of root.querySelectorAll('*')){if(el.shadowRoot){el.shadowRoot.appendChild(s.cloneNode(true));const frames = el.shadowRoot.querySelectorAll('iframe');applyToIFrames(frames);applyToShadows(el.shadowRoot);}}} function applyToIFrames(frames){for(i=0;i<frames.length;i++){try{frames[i].contentWindow.document.getElementsByTagName('head')[0].appendChild(s.cloneNode(true));applyToShadows(frames[i].contentWindow.document);}catch(e){console.log(e)}}}d.getElementsByTagName('head')[0].appendChild(s);applyToIFrames(f);applyToShadows(d);}})();">Text Spacing</a> (drag to bookmarklets bar or right click and save as bookmark)

</p><p><a href="https://codepen.io/stevef/pen/YLMqbo">Edit this</a> on codepen








Expand Down