Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKuehn committed Apr 15, 2019
2 parents b45c003 + 9c3f920 commit 328c935
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,28 @@ The original maintainer [Anton Beloglazov](https://github.com/beloglazov) seems

[RoadMap](https://github.com/MaxKuehn/zotero-scholar-citations/RoadMap.md)

## "Extra"-Column Content Handling
## Extra Column Info

### New Format in 2.0.x
Version 2.0.0 introduced a new format for storing the citation count, i.e. `ZSCC: 0000001`. Unfortunately that means existing entries are incompatible in terms of sorting.

#### Migration Tips
If you just straight up update your entire collection you're bound to run into a captcha. Once you do run into one, all following update request will fail and you will be prompted for each and every one of them. Consider updating your collection in batches of 5-10 items.

This limitation is a major inconvenience and fixing or at least alleviating it is the first thing on the priorty list (see the RoadMap).

### Staleness
As of Version 2.0.1 items whose citation count could not be updated will be marked with a trailing `s`, e.g. `ZSCC: 0000042s` to signal the user that ZSCC was unable to update the number of citations.

### Existing "Extra"-Column Content
ZSC will
- update legacy ZSC "extra"-content, i.e. 5 digit citation counts and "No Citation Data" strings
- respect content that is in the "Extra"-field as long as it's in `key: value` format
- update legacy ZSC "extra"-content, i.e. 5 digit citation counts and "No Citation Data" entries
- respect content that is already in the "Extra"-field
- ZSC will simply prepend the citation count to any existing content, so you can sort by the extra
- this includes arXiv, DOI, OCLC, etc.
- problably not combination of those unless they are ` \n` separated

#### When Updates fail
Consider temporary cutting out/deleting the "Extra" content. ZSC will update the citation count. After that you can simply append the previously removed.

## Why is ZSC unable retrieve the citation count for item X?
The most likely culprit is that ZSC search is too precise :^). Some Items do not have as complete of an author list on google scholar as they have in Zotero.
Expand Down
48 changes: 38 additions & 10 deletions chrome/content/scripts/zoteroscholarcitations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ let zsc = {
_extraPrefix: 'ZSCC',
_extraEntrySep: ' \n',
_noData : 'NoCitationData',
_legacyDataRegex: /^\d{5}/,
_legacyDataRegex: /^(\d{5})(s?)/,
_legacyNoDataRegex: /^No Citation Data/,
_searchblackList: new RegExp('[-+~*"]', 'g'),
_extraPair: /^([^:]*):\s*([^\s]*)(.*)$/
_searchblackList: new RegExp('[-+~*"]', 'g')
};
// _extraPair: /^([^:]*):\s*([^\s]*)(.*)$/

zsc._extraPair = new RegExp(
'^(' + zsc._extraPrefix + '): (\\d{' + zsc._citeCountStrLength + '}|'
+ zsc._noData + ')(s?)(.*)$'
);

zsc._extraStaleRegex = new RegExp('(' + zsc._extraPrefix + ': '
+ '\\d{' + zsc._citeCountStrLength + '})(s?)');

let isDebug = function() {
return typeof Zotero != 'undefined'
Expand Down Expand Up @@ -43,7 +51,7 @@ zsc.init = function() {
zsc.notifierCallback = {
notify: function(event, type, ids, extraData) {
if (event == 'add') {
zsc.processItems(Zotero.Items.get(ids).filter(zsc.hasRequiredFields));
zsc.processItems(Zotero.Items.get(ids));
}
}
};
Expand Down Expand Up @@ -99,6 +107,12 @@ zsc.updateCollection = function(collection) {

zsc.processItems = function(items) {
while (item = items.shift()) {
if (!zsc.hasRequiredFields(item)) {
if (isDebug()) Zotero.debug('[scholar-citations] '
+ 'skipping item "' + item.getField('title') + '"'
+ ' it has either an empty title or is missing creator information');
continue;
}
this.retrieveCitationData(item, function(item, citeCount) {
if (isDebug()) Zotero.debug('[scholar-citations] '
+ 'Updating item "' + item.getField('title') + '"');
Expand Down Expand Up @@ -135,11 +149,25 @@ zsc.updateItem = function(item, citeCountStr) {
zsc.updateExtra(zsc._legacyNoDataRegex
, curExtra, item, citeCountStr
,'updating legacy no-data extra content to new format');
} else if (zsc._legacyDataRegex.test(curExtra)) {
if (isDebug()) Zotero.debug('[scholar-citations] '
+ 'reformatting legacy entry and marking it as stale');
let matches = curExtra.match(zsc._legacyDataRegex);
let newExtra = curExtra.replace(zsc._legacyDataRegex,
zsc._extraPrefix + ': 00' + matches[1] + 's');
item.setField('extra', newExtra);
} else if (zsc._extraStaleRegex.test(curExtra)) {
if (isDebug()) Zotero.debug('[scholar-citations] '
+ 'marking entry as stale');
let matches = curExtra.match(zsc._extraStaleRegex);
let newExtra = curExtra.replace(zsc._extraStaleRegex, matches[1] + 's');
item.setField('extra', newExtra);
} else {
if (isDebug()) Zotero.debug('[scholar-citations] '
+ ' not updating extra content of "'
+ item.getField('title')
+ '", because we didn\'t get a cite count and it\'s not a zsc field.');
+ '", because we didn\'t get a cite count from gs '
+ ' and it\'s not a field format zsc recognizes.');
}
}

Expand All @@ -161,7 +189,7 @@ zsc.updateExtraPairs = function(extra, item, citeCountStr) {
let matches = entry.match(zsc._extraPair);
if (matches) {
if (matches[1].trim() === zsc._extraPrefix) {
newExtra.push(citeCountStr + matches[3]);
newExtra.push(citeCountStr + matches[4]);
} else {
newExtra.push(matches.input);
}
Expand Down Expand Up @@ -263,17 +291,17 @@ zsc.buildCiteCountString = function(citeCount) {
};

zsc.getCiteCount = function(responseText) {
let citePrefix = '>Cited by';
let citePrefix = '>Cited by ';
let citePrefixLen = citePrefix.length;
let citeCountStart = responseText.indexOf(citePrefix);

if (citeCountStart === -1) {
return -1
} else {
let citeCountEnd = responseText.indexOf('<', citeCountStart + 1);
let citeCountEnd = responseText.indexOf('<', citeCountStart);
let citeStr = responseText.substring(citeCountStart, citeCountEnd);
let citeCount = citeStr.substring(citePrefixLen + 1);
return parseInt(citeCount);
let citeCount = citeStr.substring(citePrefixLen);
return parseInt(citeCount.trim());
}
};

Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RDF:about="urn:mozilla:install-manifest"
em:id="[email protected]"
em:name="Zotero Scholar Citations"
em:version="2.0.0"
em:version="2.0.1"
em:type="2"
em:creator="Anton Beloglazov"
em:description="Zotero plugin for auto-fetching numbers of citations from Google Scholar"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zotero-scholar-citatations",
"version": "2.0.0",
"version": "2.0.1",
"bugs": {
"url": "https://github.com/MaxKuehn/zotero-scholar-citations/issues"
},
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ suite('Unit Tests', function() {
let matches = 'ZSCC: 9001042 arXiv: 1337.123456'.match(zsc._extraPair);
assert.equal(matches[1], 'ZSCC');
assert.equal(matches[2], '9001042');
assert.equal(matches[3], ' arXiv: 1337.123456')
assert.equal(matches[4], ' arXiv: 1337.123456')
});
});

Expand Down

0 comments on commit 328c935

Please sign in to comment.