Skip to content

Instantly share code, notes, and snippets.

@davemasse
Last active October 12, 2015 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davemasse/1199557 to your computer and use it in GitHub Desktop.
Save davemasse/1199557 to your computer and use it in GitHub Desktop.
jQuery bookmarklet using Ben Alman's generator
// Makes local newspaper archives accessible by altering archive links (PDFs are not password-protected!)
(function($) {
monthArray = {
January: '01',
February: '02',
March: '03',
April: '04',
May: '05',
June: '06',
July: '07',
August: '08',
September: '09',
October: '10',
November: '11',
December: '12'
};
$('a[href*="1communityindexbody.lasso"]:gt(0)').each(function() {
var href = $(this).attr('href').split('&');
var pub = href[1].replace('pub=', '');
var date = $(this).text().split(' ');
var year = date[2].replace(/[^\d]/g, '');
var month = date[0].replace(/[^a-z]/gi, '');
var day = date[1].replace(/[^\d]/g, '');
if (day.length == 1)
day = '0' + day;
$(this).attr('href', '/pdf/' + pub + '.' + year + '.' + monthArray[month] + '.' + day + '.pdf');
$(this).attr('target', '_blank');
});
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment