User:Fæ/BM refs/imacro

Description
British Museum iMacro script to extract information from on-line collection records.

Ensure that:
 * 1) the script code is saved as a JavaScript (.js) file rather than a default iMacro (.iim).
 * 2) you are running iMacro in Firefox.
 * 3) you are looking at a page from the BM collections database showing a record about an artefact (not the same thing as a BM article or highlights page).

The normal policies for use of templates apply, results may need copy editing before use.

Please contact User talk:Fæ for reporting bugs (include a sample url) and suggesting improvements.

Example output
British Museum infobox

Footer

Link

Script code
/* iMacro File:BM_object.js  Contact: http://en.wikipedia.org/User_talk:Fæ Created: 11 June 2010 Last edit: 14 June 2010

Description: Wikipedia - British Museum script. Script to extract values from records on the on-line British Museum collections database and display and other templates. Text is displayed in a browser alert and can be cut & paste into articles. Warnings: - Do not paste into articles willy-nilly, templates must be appropriate. - Ensure the information extracted displays correctly and is relevant to the article. The script may extract more data than is useful, be prepared to trim or    copy edit the text.

/* bmget: Get a value Find text with a matching attribute (such as class, style or text value). // T is HTML tag, A is attributes to find and H is "TXT" or "HTM" for the format required function bmget(T,A,H){ if(H==null){H="TXT"}; iimPlay("CODE:\n\ ' "+T+"\n\ SET !TIMEOUT_TAG 1\n\ TAG POS=1 TYPE="+T+" ATTR="+A.replace(/ /g,"")+" EXTRACT="+H+"\n\ "); return iimGetLastExtract=="#EANF#"?"":iimGetLastExtract; }

/* bmgetset: Get set of values These look like " title value 1 value 2 ". // T is HTML tag, A is title text to find function bmgetset(T,A){ iimPlay("CODE:\n\ ' "+T+"\n\ SET !TIMEOUT_TAG 1\n\ TAG POS=1 TYPE="+T+" ATTR=TXT:*"+A.replace(/ /g,"")+"* EXTRACT=HTM\n\ "); var r=iimGetLastExtract.replace(/<\/?a .*?>/g,"").replace(/<\/?p>/g,"").split(A)[1]; if(r==""||r==undefined){return ""}; r=r.split(/<.?strong>/)[1]; if(r==""){return r}; var rArr=r.split(" "); rArr.shift; r=rArr.join(", ").replace(/ \((scope|all).*?\)/g,"") .replace(/Found.acquired /i,"") .replace(/[\n\r]/g,"").replace(/,\s*$/,""); return r; }

/* Main code */

// Find objectId (no easy way for iMacro to access the window.location) var objectId=bmget("DIV","ID:*researchObject*","HTM").replace(/^.*objectId=(\d{2,}).*$/i,"$1"); if(objectId.length>15){objectId=""};

// Get values var result="\n\n";

// Footer template var dispNo=''; if(bigNo.length>2){ dispNo=""+bigNo; if(regNo.length>4){dispNo=""+bigNo+" / "+"Registration:"+regNo}; }else{ dispNo=regNo; } result+="Footer\n\n\n\n"+ "Link\n\n\n\n"; // Display result alert("British Museum infobox\n\n"+result);