Version 1 of copy wiki code examples to clipboard

Updated 2013-10-10 16:09:43 by fr

The code examples on the wiki pages are formatted inside html pre tags with a leading space. Following javascript code extracts the code into separate popup windows, where the plain text is ready to be marked and copied to your tcl interpreter.

You have to allow popup windows in your browser settings - add an exception to allow popup windows for wiki.tcl.tk.

Visit a wiki page with gray code blocks, then copy this code to your browser's console window and run it. Try F12 key to open developer tools and continue with console or scripting.

 function reap() {
   var pre=document.getElementsByTagName('pre');
   var w=[];
   var page;
   var title='';
   for (var i=0; i<pre.length; i++) {
     var raw=pre[i].innerText || pre[i].innerHTML;
     w[i]=window.open('','_blank', 'width=400,height=300,resizable=yes');
     var d=w[i].document;
     d.open('text/plain');
     d.write('<pre>'+raw+'</pre>');
     d.close();
     page=i+1;
     title=page.toString();
     title=title.concat('/',pre.length,' ',document.title);
     d.title=title;
   }
 }
 reap();

See also :