WikiApiary:Bookmarklet

This bookmarklet can be used to easily add websites to WikiApiary.

 javascript:q=location.href;p=document.title.replace(/[\/\#\<\>\[\]\|\{\}]/g,"-");a=d='';if(document.querySelector){if(link=document.querySelector('link[rel="EditURI"]')){a=(link.href).split("?")[0];}elseif((link=document.querySelector('link[type="application/rss+xml"]'))||(link=document.querySelector('link[type="application/rdf+xml"]'))){a=(link.href).split("?")[0].replace('index.php','api.php');}}if(document.getSelection){d=document.getSelection;}void(open('http://wikiapiary.com/wiki/Special:FormEdit/Website/'+'?Website%5BURL%5D='+encodeURIComponent(q)+'&Website%5BAPI%20URL%5D='+encodeURIComponent(a)+'&Website%5BName%5D='+encodeURIComponent(p)+'&Website%5BDescription%5D='+encodeURIComponent(d),'Add%20to%20WikiApiary'));

When you find a wiki that you want to add to WikiApiary, you can highlight the text that describes the wiki, and then activate the bookmarklet. The name of the window, URL in the location bar and the text you have highlighted will be used to pre-populate the form to add a new wiki. If the wiki provides a  attribute the API URL will also be pre-populated.

Expanded Code
This is the same code as above, but with spaces and newlines in place to make it easier to read and edit.

javascript: q = location.href; p = document.title.replace(/[\/\#\<\>\[\]\|\{\}]/g,"-"); a = d = ''; if (document.querySelector) { if ( link = document.querySelector('link[rel="EditURI"]') ) { a = (link.href).split("?")[0]; }   else if ( ( link = document.querySelector('link[type="application/rss+xml"]') ) ||              ( link = document.querySelector('link[type="application/rdf+xml"]') ) ) { a = (link.href).split("?")[0].replace('index.php','api.php'); } }  if (document.getSelection) { d = document.getSelection; } void(open('http://wikiapiary.com/wiki/Special:FormEdit/Website/' + '?Website%5BURL%5D=' + encodeURIComponent(q) + '&Website%5BAPI%20URL%5D=' + encodeURIComponent(a) + '&Website%5BName%5D=' + encodeURIComponent(p) + '&Website%5BDescription%5D=' + encodeURIComponent(d), 'Add%20to%20WikiApiary'));

To Do

 * Automatically get API URL from EditURI link. Done. Thingles (talk) 20:31, 28 February 2013 (UTC)
 * Instead of going directly to the edit form, go to a query form that will search to see if any wikis exist on this domain name. Provide a link in that querypage that will then allow the form to be activated with the fields populated.
 * Only relatively modern MediaWiki installs report EditURI. Older versions have link references in the head element pointing to index.php, which could reliably predict api.php. If EditURI is not present the bookmarklet could attempt to find index.php and assume that path for api.php. Will now derive the expected api.php URL from the RSS or RDF links in the header. Thingles (talk) 20:31, 28 February 2013 (UTC)