User:Fæ/Geek/QR from category
Appearance
//<code><pre>/* -- Source code starts -- */
/* iMacro Script
You must be running this script in iMacro for it to work
Grab currently visible category items (not the whole category!)
and generate QR codes.
10 Feb 2011 (beta version)
http://enwp.org/User_talk:Fae
*/
var rundate=new Date();
function main(){ // Embed in a loop so we can quit on error
// Grab category title
iimPlay("CODE:\n\
' Grab title of category\n\
TAG POS=1 TYPE=H1 ATTR=* EXTRACT=TXT");
var catTitle=iimGetLastExtract();
if(catTitle.search(/Category/)==-1){alert("You should be on a category page!");return;};
iimPlay("CODE:\n\
' Grab category members visible\n\
TAG POS=1 TYPE=DIV ATTR=ID:mw-pages EXTRACT=HTM");
var cats=iimGetLastExtract().split('<li'), qrCat=new Array();
cats.shift(); // drop first element
for (var i in cats){
cats[i]=cats[i].replace(/.*>(.*?)<.a>.*/,"$1");
var url=cats[i].replace(/ /g,"_");
qrCat[i]=(i>1 && i%10==0?"<tr style='page-break-before:always'></tr>":"")+ // Break every 10 images
(i%2==0?"<tr>":"")+ // Double column
"<td style='border:solid silver 1px;padding:1px 8px 8px 6px;width:50%'>"+
"<img src=http://chart.apis.google.com/chart?chs=100x100&cht=qr&chl=http:%25%25wiki.riteme.site%25wiki%25"+url+" >"+
"<br><b>"+cats[i]+"</b><br><div style='font-size:75%'><a href=http://wiki.riteme.site/wiki/"+
url+" >http://wiki.riteme.site/wiki/"+cats[i]+"</a></div></td>"+
(i%2==1?"</tr>":"");
}
//alert(cats.join(' : '));
// Create output page
var pagehead="<h3>QR Codes for "+catTitle+"</h3><i>List length = "+cats.length+
"</i> (<a href=http://wiki.riteme.site/wiki/"+
catTitle.replace(/\s/g,'_')+">link</a>) "+rundate+"<br><hr>\n<table cellspacing=0 >",
pageend="</table><hr>";
var result=pagehead+qrCat.join('\n')+pageend;
// Display results in pop-up window
newWin = window.open("", "resultsWindow", 'toolbar,width=1200,height=900,left=100,top=100,scrollbars,resizable=1');
newWin.document.title="QR Codes for "+catTitle;
newWin.document.bgColor="white";
newDiv=newWin.document.createElement("DIV");
newDiv.innerHTML=result;
newWin.document.body.appendChild(newDiv);
}
main();
/* Source code ends */