Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Last active December 9, 2015 17:18
Show Gist options
  • Save skratchdot/4302457 to your computer and use it in GitHub Desktop.
Save skratchdot/4302457 to your computer and use it in GitHub Desktop.
StackOverflow: Add "Select All" buttons This is a bookmarklet to add a "select all" button above every codeblock on stackoverflow.com. It will toggle selecting the text in the codeblock.
javascript:(function(){var%20b=$('<button%20style="margin:0px%200%2010px%20560px;width:100px;cursor:pointer;border-radius:5px;">Select%20All</button>'),p=$('pre.prettyprint');b.click(function(){var%20o=this,$o=$(o),p=$o.next('.prettyprint')[0],s1=document.selection,s2=window.getSelection,r;$o.toggleClass('active');if(s1){s1.empty();}else%20if(s2){s2().removeAllRanges();}if($o.hasClass('active')){if(s1){r=document.body.createTextRange();r.moveToElementText(p);r.select();}else%20if(s2){r=document.createRange();r.selectNode(p);s2().addRange(r);}}});p.before(b);}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment