Skip to content

Instantly share code, notes, and snippets.

@tingjhenjiang
Last active December 7, 2021 09:12
Show Gist options
  • Save tingjhenjiang/bd0032eeb0ae3282a404beae1e1968f4 to your computer and use it in GitHub Desktop.
Save tingjhenjiang/bd0032eeb0ae3282a404beae1e1968f4 to your computer and use it in GitHub Desktop.
A bookmarklet to convert a webpage into a RIS file(standardized tag format developed by Research Information Systems)
javascript: (() => {
function download(filename, text) {
element = document.createElement('a');
element.setAttribute('href', 'data:text/plain.charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function outputWebpageRisDoc(info) {
template = '';
for (var key in info) {
template = template+key+' - '+info[key]+'\n';
}
template = template+'ER'+' - ';
return template;
}
function getWebpageAttributes() {
title = document.getElementsByTagName("title")[0].textContent;
webpageUrl = window.location.href;
today = new Date();
year = today.getFullYear();
options = {year:'numeric',month:'short',day:'numeric'};
accessDate = today.toLocaleDateString('en-US', options);
htmlMetaDataObj = {};
htmlMetaData = document.getElementsByTagName("meta");
for (var singleMetaDataObj of htmlMetaData) {
attrName = singleMetaDataObj.getAttributeNames();
attrName = attrName.filter(an => an!='content')[0];
attrKey = singleMetaDataObj.getAttribute(attrName);
htmlMetaDataObj[attrKey] = singleMetaDataObj.getAttribute('content');
}
return {
'TY': 'WEB',
'PY': year,
'TI': title,
'AB': (htmlMetaDataObj['description']) ? htmlMetaDataObj['description'] : '',
'AU': (htmlMetaDataObj['author']) ? htmlMetaDataObj['author'] : '',
'Y2': accessDate,
'LK': webpageUrl,
'UR': webpageUrl,
'KW': (htmlMetaDataObj['keywords']) ? htmlMetaDataObj['keywords'] : ''
};
}
function downloadHtmlAttrsInRIS() {
attrs = getWebpageAttributes();
ris = outputWebpageRisDoc(attrs);
download('webpage.ris',ris);
}
downloadHtmlAttrsInRIS();
})();
@tingjhenjiang
Copy link
Author

How to use:
Refer to this page. Replace line breaks to empty string in this script and make it a bookmark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment