Skip to content

Commit

Permalink
Modification of OSF translator
Browse files Browse the repository at this point in the history
This is intended to address the [issue#3188](zotero#3188)

I have made two modifications.
1. Modify `detectWeb` function to ensure that OSF Projects are recognized as "Web Page" instead of "Journal Article."
2. Modify `scrape` function to customize the citation information for OSF Projects.
  • Loading branch information
UniqueClouds committed Jan 8, 2024
1 parent c73db0a commit 4e38d30
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions OSF Preprints.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2022-04-04 18:35:34"
"lastUpdated": "2024-01-08 03:07:26"
}

/*
Expand Down Expand Up @@ -41,7 +41,10 @@ const preprintType = ZU.fieldIsValidForType('title', 'preprint')
: 'report';

function detectWeb(doc, url) {
if (text(doc, 'h1#preprintTitle')) {
if (url.includes('osf.io') && !url.includes('/preprints/')) {
return "webpage"; // Change this to capture as a webpage
}
else if (text(doc, 'h1#preprintTitle')) {
return preprintType;
}
else if (url.includes("discover?") && getSearchResults(doc, true)) {
Expand Down Expand Up @@ -143,6 +146,7 @@ function scrape(doc, url) {
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');

translator.setHandler('itemDone', function (obj, item) {

if (preprintType != 'preprint') {
if (item.extra) {
item.extra += "\ntype: article";
Expand All @@ -158,6 +162,10 @@ function scrape(doc, url) {
}
}
item.libraryCatalog = "OSF Preprints";
if (url.includes('osf.io ') && !url.includes('/preprints/')) {
item.itemType = "webpage";
item.websiteType = "OSF Project";
}
item.complete();
});

Expand All @@ -168,6 +176,7 @@ function scrape(doc, url) {
}



/** BEGIN TEST CASES **/
var testCases = [
{
Expand Down Expand Up @@ -244,7 +253,7 @@ var testCases = [
"defer": true,
"items": [
{
"itemType": "preprint",
"itemType": "webpage",
"title": "‘All In’: A Pragmatic Framework for COVID-19 Testing and Action on a Global Scale",
"creators": [
{
Expand Down

0 comments on commit 4e38d30

Please sign in to comment.