Skip to content
Permalink
Browse files

Wiley: Fix subdomains when 3rd-party cookies are blocked

Also fail properly and fall back if no BibTeX is retrieved

https://forums.zotero.org/discussion/74804/cant-save-from-ascpt-wiley
  • Loading branch information...
dstillman committed Nov 28, 2018
1 parent 2e55db9 commit e5ff91b8d00cfc1a6662e83bc3201ce3c34c135a
Showing with 15 additions and 3 deletions.
  1. +15 −3 Wiley Online Library.js
@@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2018-05-21 15:05:09"
"lastUpdated": "2018-11-28 08:40:37"
}

/*
@@ -223,7 +223,14 @@ function scrapeBibTeX(doc, url, pdfUrl) {
return;
}

var postUrl = 'https://onlinelibrary.wiley.com/action/downloadCitation';
// Use the current domain on Wiley subdomains (e.g., ascpt.) so that the
// download works even if third-party cookies are blocked. Otherwise, use
// the main domain.
var host = doc.location.host;
if (!host.endsWith('.onlinelibrary.wiley.com')) {
host = 'onlinelibrary.wiley.com';
}
var postUrl = `https://${host}/action/downloadCitation`;
var body = 'direct=direct' +
'&doi=' + encodeURIComponent(doi) +
'&downloadFileName=pericles_14619563AxA' +
@@ -233,9 +240,14 @@ function scrapeBibTeX(doc, url, pdfUrl) {

ZU.doPost(postUrl, body, function(text) {
// Replace uncommon dash (hex e2 80 90)
text = text.replace(//g, '-');
text = text.replace(//g, '-').trim();
//Z.debug(text);

var re = /^\s*@[a-zA-Z]+[\(\{]/;
if (text.startsWith('<') || !re.test(text)) {
throw new Error("Error retrieving BibTeX")
}

var translator = Zotero.loadTranslator('import');
//use BibTeX translator
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");

0 comments on commit e5ff91b

Please sign in to comment.
You can’t perform that action at this time.