User:Bazzargh/citemark

This script is a Bookmarklet that extracts useful metadata from most webpages. Unlike more sophisticated tools like Zotero, it doesn't try to make data fit the citation template; it blindly dumps out a useful set of metadata in citation format, leaving you to edit the results. I find that it's easier to remove data that I've extracted by mistake rather than have to type in data that other tools failed to extract.

I was surprised not to find something like this already in existence; if there's a better one already out there, let me know!

Firefox, Safari, Chrome, and Opera
Usage: Create a bookmark with the value below. Go to the web page you want to cite, and click the bookmark. An alert will appear, from which you can copy and paste the text of the citation (press Cmd-A Cmd-C on Mac, Ctrl-A Ctrl-C on windows. Firefox won't highlight the text you're copying on Mac). If you select text before using the bookmark, that will appear as the quote parameter in the citation.

The bookmark URL, with comments and whitespace stripped, as an URL-encoded string for convenience

 javascript:function%20h(t){var%20z=document.getElementsByTagName(t)[0];return%20z&&z.childNodes[0]?e(t,z.childNodes[0].nodeValue):;}function%20e(a,b){var%20d=Date.parse(b);return%20a&&b?('|'+a+'='+(d?f(d):b)+'\n'):}function%20z(x){return%20x<10?'0'+x:x}function%20f(x){var%20d=new%20Date(x);return%20d.getFullYear+'-'+z(d.getMonth+1)+'-'+z(d.getDate)}var%20s=e('url',window.location)+e('accessdate',Date)+e('title',document.title)+e('date',document.lastModified)+e('quote',window.getSelection+)+h('h1')+h('h2');var%20m=document.getElementsByTagName('meta');for(var%20i=0;i<m.length;i++){s+=e(m[i].getAttribute('name'),m[i].getAttribute('content'))}alert()

Source
Here's the source code, with additional whitespace and comments. I'd encourage you to use this version and edit it down into a bookmark, rather than the condensed version above; don't just trust JavaScript you find on the net!

Notes: this version hasn't been tested in Safari yet - I don't know if window.getSelection works there but everything else should be ok. There's better ways to grab the h1, h2 tags, but unfortunately they interfere with the NoScript extension.

Internet Explorer
Internet explorer won't support bookmarklets longer than 512 characters, so there's a limit to what can be achieved. The URL below will capture the selection, and create a citation with the url, title, date, accessdate, and quote parameters set. When you change a favourite to this value in IE, it will complain that "The protocol 'javascript' does not have a registered program". You need to click yes to use the bookmarklet, javascript URLs do work in IE. Tested in IE7/Win only, its all I have handy.

Usage: Create a favourite with the value below. Go to the web page you want to cite, and click the favourite. An alert will appear, from which you can copy and paste the text of the citation (Ctrl-A Ctrl-C). If you select text before using the favourite, that will appear as the quote parameter in the citation.

The favourite URL, with comments and whitespace stripped, as an URL-encoded string for convenience:

javascript:function%20e(a,b){var%20d=Date.parse(b);return%20a&&b?('|'+a+'='+(d?f(d):b)+'\n'):}function%20z(x){return%20x<10?'0'+x:x}function%20f(x){var%20d=new%20Date(x);return%20d.getFullYear+'-'+z(d.getMonth+1)+'-'+z(d.getDate)}var%20s=e('url',window.location)+e('accessdate',Date)+e('title',document.title)+e('date',document.lastModified)+e('quote',document.selection.createRange.text);alert()

Source
Mostly this is cut down from the firefox version, but the selection is captured differently.

Examples
An example of the output (in IE you will see much less):

Obviously you need to edit this down - the guessed 'date' is wrong but the correct one is in there with a different name; the same goes for the title. Also, most of the fields use names that are not valid for cite web and need to be removed. After editing, we have:

Which formats the reference like so:

Tips
If you select text on the page before using the bookmarklet, it will add this to the citation as a quote. However, this can be useful just to quickly copy and paste additional info with the citation. As an example, this article:

Does not, at the time of writing, serve up the metadata required for the document creation date. To create the citation, I highlighted the text on the page Jul 8, 1999 before using citemark. It was recognized as a date and automatically reformatted to the date format used by cite web, as  quote=1999-07-08 .

More usually, you can use this to copy and paste a larger chunk of text from the page at the same time as grabbing the URL, title, and access date.