Skip to content

Commit

Permalink
🎨 Spaces around keywords (zotero#1717)
Browse files Browse the repository at this point in the history
Search and replace some cases to add spaces around
keywords: if, else, for, while, switch.

(Excluding FW code and translators with an open pull request.)
  • Loading branch information
zuphilip authored and adam3smith committed Aug 20, 2018
1 parent 2fa6a0f commit 2d3e4bd
Show file tree
Hide file tree
Showing 215 changed files with 3,003 additions and 3,003 deletions.
2 changes: 1 addition & 1 deletion ACLWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function doWeb(doc, url) {
}
});
});
} else if(url.endsWith('.bib')) {
} else if (url.endsWith('.bib')) {
// e.g. http://www.aclweb.org/anthology/P10-4014.bib
let bibtex = ZU.xpath(doc, '//pre')[0].textContent;
scrapeBibtex(bibtex, url);
Expand Down
2 changes: 1 addition & 1 deletion ACM Digital Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function scrape(doc) {
delete item.archiveLocation;

// some bibtext contains odd </kwd> tags - remove them
for(var i=0; i<item.tags.length; i++) {
for (var i=0; i<item.tags.length; i++) {
item.tags[i] = item.tags[i].replace("</kwd>", "");
}

Expand Down
38 changes: 19 additions & 19 deletions ACS Publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
function getSearchResults(doc, checkOnly, itemOpts) {
var items = {}, found = false;
var titles = doc.getElementsByClassName('titleAndAuthor');
for(var i=0; i<titles.length; i++){
for (var i=0; i<titles.length; i++){
var a = ZU.xpath(titles[i], './/h2//a')[0];
if (!a) continue;

Expand All @@ -37,7 +37,7 @@ function getSearchResults(doc, checkOnly, itemOpts) {
continue;
}

if(ZU.xpath(articleBox, './/a[text()="Supporting Info"]').length) {
if (ZU.xpath(articleBox, './/a[text()="Supporting Info"]').length) {
itemOpts[doi].hasSupp = true;
}

Expand All @@ -52,9 +52,9 @@ function getSearchResults(doc, checkOnly, itemOpts) {
function getDoi(url) {
var m = url.match(/https?:\/\/[^\/]*\/doi\/(?:abs\/|full\/)?(10\.[^\?#]+)/);

if(m) {
if (m) {
var doi = m[1];
if(doi.indexOf("prevSearch") != -1) {
if (doi.indexOf("prevSearch") != -1) {
doi = doi.substring(0,doi.indexOf("?"));
}
return decodeURIComponent(doi);
Expand All @@ -68,7 +68,7 @@ function getDoi(url) {
function getSuppFiles(div) {
var fileNames = ZU.xpath(div, './/li//li');
var attach = [];
for(var i=0, n=fileNames.length; i<n; i++) {
for (var i=0, n=fileNames.length; i<n; i++) {
attach.push(fileNames[i].textContent.trim().replace(/\s[\s\S]+/, ''));
}
return attach;
Expand All @@ -88,16 +88,16 @@ function getSuppMimeType(fileName) {
}

function attachSupp(item, doi, opts) {
if(!opts.attach) return;
if(!item.attachments) item.attachments = [];
if (!opts.attach) return;
if (!item.attachments) item.attachments = [];
var attachment;
for(var i=0, n=opts.attach.length; i<n; i++) {
for (var i=0, n=opts.attach.length; i<n; i++) {
attachment = {
title: opts.attach[i]
};
attachment.url = '/doi/suppl/' + doi + '/suppl_file/' + attachment.title;
attachment.mimeType = getSuppMimeType(attachment.title);
if(opts.attachAsLink || !attachment.mimeType) { //don't download unknown file types
if (opts.attachAsLink || !attachment.mimeType) { //don't download unknown file types
attachment.snapshot = false;
}

Expand All @@ -116,7 +116,7 @@ function detectWeb(doc, url) {
return "multiple";
} else if (getDoi(url)) {
var type = doc.getElementsByClassName("manuscriptType");
if(type.length && type[0].textContent.indexOf("Chapter") !=-1) {
if (type.length && type[0].textContent.indexOf("Chapter") !=-1) {
return "bookSection";
} else {
return "journalArticle";
Expand All @@ -131,7 +131,7 @@ function doWeb(doc, url){
opts.attachSupp = Z.getHiddenPref("attachSupplementary");
opts.attachAsLink = Z.getHiddenPref("supplementaryAsLink");
var highResPDF = Z.getHiddenPref("ACS.highResPDF"); //attach high res PDF?
if(highResPDF) {
if (highResPDF) {
opts.highResPDF = true;
opts.removePdfPlus = highResPDF === 1; //it can also be 2, which would mean attach both versions
}
Expand All @@ -156,7 +156,7 @@ function doWeb(doc, url){
Zotero.debug("DOI= "+doi);
//we can determine file names from the tooltip, which saves us an HTTP request
var suppTip = doc.getElementById('suppTipDiv');
if(opts.attachSupp && suppTip) {
if (opts.attachSupp && suppTip) {
try {
opts.attach = getSuppFiles(suppTip, opts);
} catch(e) {
Expand All @@ -167,7 +167,7 @@ function doWeb(doc, url){

//if we couldn't find this on the individual item page,
//then it doesn't have supp info anyway. This way we know not to check later
if(!opts.attach) opts.attach = [];
if (!opts.attach) opts.attach = [];

// See if we have pdfplus
var div = doc.getElementsByClassName('fulltext-formats')[0];
Expand All @@ -180,7 +180,7 @@ function doWeb(doc, url){
}

function scrape(items, opts){
for(var i=0, n=items.length; i<n; i++) {
for (var i=0, n=items.length; i<n; i++) {
processCallback(items[i], opts);
}
}
Expand All @@ -195,7 +195,7 @@ function processCallback(fetchItem, opts, downloadFileName) {
// Fix the wrong mapping for journal abbreviations
text = text.replace("\nJO -", "\nJ2 -");
// Use publication date when available
if(text.indexOf("\nDA -") !== -1) {
if (text.indexOf("\nDA -") !== -1) {
text = text.replace(/\nY1 - [^\n]*/, "")
.replace("\nDA -", "\nY1 -");
}
Expand Down Expand Up @@ -234,14 +234,14 @@ function processCallback(fetchItem, opts, downloadFileName) {

//supplementary data
try {
if(opts.attachSupp && opts.attach) {
if (opts.attachSupp && opts.attach) {
//came from individual item page
attachSupp(item, doi, opts);
} else if(opts.attachSupp && fetchItem.opts.hasSupp) {
} else if (opts.attachSupp && fetchItem.opts.hasSupp) {
//was a search result and has supp info
var suppUrl = '/doi/suppl/' + doi;

if(opts.attachAsLink) {
if (opts.attachAsLink) {
//if we're only attaching links, it's not worth linking to each doc
item.attachments.push({
title: "Supporting Information",
Expand All @@ -253,7 +253,7 @@ function processCallback(fetchItem, opts, downloadFileName) {
ZU.processDocuments(suppUrl, function(suppDoc) {
try {
var div = suppDoc.getElementById('supInfoBox');
if(div) {
if (div) {
var files = getSuppFiles(div);
attachSupp(item, doi, {
attach: files,
Expand Down
26 changes: 13 additions & 13 deletions AIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ function getSearchResults(doc) {
}

function detectWeb(doc, url) {
if(url.indexOf('search') !== -1 && getSearchResults(doc).length) {
if (url.indexOf('search') !== -1 && getSearchResults(doc).length) {
return 'multiple';
}

if(ZU.xpathText(doc, '/html/head/meta[@name="citation_journal_title"]/@content')) {
if (ZU.xpathText(doc, '/html/head/meta[@name="citation_journal_title"]/@content')) {
return 'journalArticle';
}
else if(doc.body.id == 'conferencepaper') return "conferencePaper"
else if (doc.body.id == 'conferencepaper') return "conferencePaper"
}
function doWeb(doc, url) {
if(detectWeb(doc, url) == 'multiple') {
if (detectWeb(doc, url) == 'multiple') {
var results = getSearchResults(doc);
var items = {};
for(var i=0, n=results.length; i<n; i++) {
for (var i=0, n=results.length; i<n; i++) {
var title = ZU.xpath(results[i], './/div[@class="title"]/a')[0];
items[title.href] = ZU.trimInternal(title.textContent);
}

Z.selectItems(items, function(selectedItems) {
if(!selectedItems) return true;
if (!selectedItems) return true;

var urls = [];
for(var i in selectedItems) {
for (var i in selectedItems) {
urls.push(i);
}

Expand All @@ -58,22 +58,22 @@ function scrape(doc, url) {

translator.setHandler('itemDone', function(obj, item) {
//for conference papers, we're missing some metadata
if(!item.publicationTitle
if (!item.publicationTitle
&& ZU.xpath(doc, '//div[@id="breadcrumb"]/a[@title="Link to conference proceedings"]').length) {
item.publicationTitle = "AIP Conference Proceedings";
item.volume = ZU.xpathText(doc, '//div[@class="itemCitation"]//span[@class="citationvolume"]');
}

//check if we have the correct publication date
var year = doc.getElementsByClassName('itemCitation')[0];
if(year) year = year.textContent.match(/\((\d{4})\)/);
if(year && (!item.date || item.date.indexOf(year[1]) == -1) ) {
if (year) year = year.textContent.match(/\((\d{4})\)/);
if (year && (!item.date || item.date.indexOf(year[1]) == -1) ) {
item.date = year[1];
}


var pdf = ZU.xpath(doc, '//div[@class="pdfItem"]/a[@class="pdf" and @href]')[0];
if(pdf) {
if (pdf) {
item.attachments.push({
title: "Full Text PDF",
url: pdf.href,
Expand All @@ -83,10 +83,10 @@ function scrape(doc, url) {

var keywords = ZU.xpath(doc, '//div[@class="keywords-container"]//dt/a');
var tags = [];
for(var i=0, n=keywords.length; i<n; i++) {
for (var i=0, n=keywords.length; i<n; i++) {
tags.push(ZU.trimInternal(keywords[i].textContent));
}
if(tags.length) {
if (tags.length) {
item.tags = tags;
}

Expand Down
12 changes: 6 additions & 6 deletions AMS MathSciNet.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
function detectWeb(doc, url) {

var itemType;
if(getSearchResults(doc, true)) {
if (getSearchResults(doc, true)) {
return "multiple"
} else if(itemType = ZU.xpathText(doc, '//div[@class="headlineMenu"]/*[last()-1]')) {
switch(itemType.trim().toLowerCase()) {
} else if (itemType = ZU.xpathText(doc, '//div[@class="headlineMenu"]/*[last()-1]')) {
switch (itemType.trim().toLowerCase()) {
case 'article':
return "journalArticle";
case 'book':
Expand Down Expand Up @@ -77,7 +77,7 @@ function scrape(doc, url) {
var bibTeXString = "";

var m;
while(m = preRE.exec(text)) {
while (m = preRE.exec(text)) {
bibTeXString += m[1] + '\n';
}

Expand All @@ -88,15 +88,15 @@ function scrape(doc, url) {
translator.setHandler("itemDone", function(obj, item) {
// Fix/fetch MR number
var mrnumber;
if(item.extra) {
if (item.extra) {
item.extra = item.extra.replace(/^MR:\s*(?:MR)?(\d+).*/gm,
function(m, mr) {
mrnumber = mr;
return 'MR: ' + mr;
});
}

if(mrnumber) {
if (mrnumber) {
url = 'https://mathscinet.ams.org/mathscinet-getitem?mr=' + mrnumber;
}
item.attachments.push({title: "MathSciNet Snapshot", document: doc});
Expand Down
2 changes: 1 addition & 1 deletion APA PsycNET.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function getIds(doc, url) {
* we can fetch the id from the url
* alternatively, the id is in a javascript section (this is messy)
*/
if(url.includes('/buy/')) {
if (url.includes('/buy/')) {
let m = url.match(/\/buy\/([\d\-]*)/);
if (m) {
return m[1];
Expand Down
12 changes: 6 additions & 6 deletions APS.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

function detectWeb(doc, url) {
var title = doc.getElementById('title');
if(title && ZU.xpath(title, './/a[@id="export-article-link"]').length) {
if (title && ZU.xpath(title, './/a[@id="export-article-link"]').length) {
return "journalArticle";
} else if(getSearchResults(doc, true)){
} else if (getSearchResults(doc, true)){
return "multiple";
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ function scrape(doc, url) {
));

// attach PDF
if(ZU.xpath(doc, '//div[@class="article-nav-actions"]/a[contains(text(), "PDF")]').length) {
if (ZU.xpath(doc, '//div[@class="article-nav-actions"]/a[contains(text(), "PDF")]').length) {
item.attachments.push({
title: 'Full Text PDF',
url: url.replace('{REPLACE}', 'pdf'),
Expand All @@ -123,17 +123,17 @@ function scrape(doc, url) {
document: doc
});

if(Z.getHiddenPref && Z.getHiddenPref('attachSupplementary')) {
if (Z.getHiddenPref && Z.getHiddenPref('attachSupplementary')) {
ZU.processDocuments(url.replace('{REPLACE}', 'supplemental'), function(doc) {
try {
var asLink = Z.getHiddenPref('supplementaryAsLink');
var suppFiles = doc.getElementsByClassName('supplemental-file');
for(var i=0; i<suppFiles.length; i++) {
for (var i=0; i<suppFiles.length; i++) {
var link = suppFiles[i].getElementsByTagName('a')[0];
if (!link || !link.href) continue;
var title = link.getAttribute('data-id') || 'Supplementary Data';
var type = suppTypeMap[link.href.split('.').pop()];
if(asLink || dontDownload.indexOf(type) != -1) {
if (asLink || dontDownload.indexOf(type) != -1) {
item.attachments.push({
title: title,
url: link.href,
Expand Down
2 changes: 1 addition & 1 deletion ARTFL Encyclopedie.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function reconcileAuthor(author){
Le Roy
*/
}
if(authorMap[author]) {
if (authorMap[author]) {
author = authorMap[author];
}
// remove ARTFL's trailing 5 for odd contributors (e.g. Turgot5)
Expand Down
12 changes: 6 additions & 6 deletions ASCE.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getTitles(doc) {
function detectWeb(doc, url) {
/* if (url.match(/\/doi\/abs\/10\.|\/doi\/full\/10\./)) {
return "journalArticle";
} else if(url.match(/\/action\/doSearch\?|\/toc\//))
} else if (url.match(/\/action\/doSearch\?|\/toc\//))
{
return "multiple";
} */
Expand All @@ -60,15 +60,15 @@ function doWeb(doc, url) {
var items = new Object();
var titles = getTitles(doc);
var doi;
for(var i=0, n=titles.length; i<n; i++) {
for (var i=0, n=titles.length; i<n; i++) {
doi = titles[i].href.match(/\/doi\/(?:abs|full)\/(10\.[^?#]+)/);
if(doi) {
if (doi) {
items[doi[1]] = titles[i].textContent;
}
}

Zotero.selectItems(items, function(selectedItems){
if(!selectedItems) return true;
if (!selectedItems) return true;

var dois = new Array();
for (var i in selectedItems) {
Expand All @@ -92,7 +92,7 @@ function finalizeItem(item, doc, doi, baseUrl) {
url: pdfurl + doi,
mimeType: 'application/pdf'
}];
if(doc) {
if (doc) {
item.attachments.push({
title: 'Snapshot',
document: doc
Expand All @@ -118,7 +118,7 @@ function scrape(doc, url, dois) {
var risFormat = '&format=ris';
var bibtexFormat = '&format=bibtex';

for(var i=0, n=dois.length; i<n; i++) {
for (var i=0, n=dois.length; i<n; i++) {
(function(doi) {
ZU.doPost(postUrl, postBody + doi + bibtexFormat, function(text) {
var translator = Zotero.loadTranslator("import");
Expand Down
Loading

0 comments on commit 2d3e4bd

Please sign in to comment.