Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrates Google Scholar's citation count functionality, a websocket client for JabRef and other extensions/fixes #131

Merged
merged 68 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6314bb1
IntelliJ configuration files added
systemoperator Feb 5, 2020
714daf7
package.json automatically updated
systemoperator Feb 5, 2020
236a2f1
zotero-scholar-citations added, web-ext-config.js: ignoreFiles extend…
systemoperator Feb 5, 2020
a53bdb4
unmodified "item.js" copied from zotero-connectors/src/zotero/chrome/…
systemoperator Feb 5, 2020
2544514
current (reduced) version of item.js
systemoperator Feb 5, 2020
0f90960
refactoring, zsc_misc_pre.js and zsc_misc_post.js introduced, README.…
systemoperator Feb 6, 2020
2e6564d
extension
systemoperator Feb 6, 2020
231b7df
bugfix; fetching and transferring citation count to JabRef works now;…
systemoperator Feb 6, 2020
3236b4e
progress panel extended
systemoperator Feb 7, 2020
e3175bb
refactoring progress panel, small improvements, options.html extended
systemoperator Feb 7, 2020
0cf5b5a
websocket client skeleton added
systemoperator Feb 17, 2020
d4f38b4
wsClient.js: extension, refactoring
systemoperator Feb 19, 2020
ae0b60a
wsClient websocket: extension
systemoperator Feb 20, 2020
7072f37
ZscItem.prototype.getField() improved (it allows processing the year …
systemoperator Feb 20, 2020
c98406e
wsClient status added to web extension preferences
systemoperator Feb 20, 2020
4843fd9
augment items with citation count or other informative text; small re…
systemoperator Feb 20, 2020
b83fe19
now loading settings first + refactoring; fixed restoring settings
systemoperator Feb 21, 2020
c2e81ae
globalSettings added; making exportMode setting functional (switching…
systemoperator Feb 21, 2020
ffa2149
extension, improvements
systemoperator Feb 21, 2020
75181f4
integrate explicit DOI fetcher; extension in general
systemoperator Feb 22, 2020
a0b832d
internal metadata added (_externalRequest, _status), extension in gen…
systemoperator Feb 22, 2020
26b9d5a
internal status information extended
systemoperator Feb 22, 2020
aba686f
gulpfile.js corrected and extended; small improvements; comments
systemoperator Feb 23, 2020
f8202ff
small improvements
systemoperator Feb 23, 2020
ccc1c98
cleanup
systemoperator Feb 25, 2020
e4ab6d5
logging improved
systemoperator Feb 26, 2020
79cba53
gitignore
systemoperator Feb 26, 2020
373401f
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Feb 26, 2020
dbe1256
refactoring
systemoperator Mar 7, 2020
c4c4d3f
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Mar 7, 2020
62c0721
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Mar 13, 2020
b6f274d
improvements
systemoperator Mar 13, 2020
94bca10
improvements
systemoperator Mar 13, 2020
701fd7f
untrack file jabref-browser-extension.iml
systemoperator Mar 13, 2020
d187d52
update gitignore
systemoperator Mar 13, 2020
e64ca48
golbalSettings removed
systemoperator Mar 14, 2020
4411c6e
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Mar 14, 2020
3334e73
revert tracking idea files
systemoperator Mar 14, 2020
89f2c1a
revert gitignore
systemoperator Mar 14, 2020
4a44fa1
adapt gitignore according to http://www.gitignore.io/api/intellij,sub…
systemoperator Mar 14, 2020
42cdf64
refactoring
systemoperator Mar 14, 2020
8f6d228
websocket connection status and websocket client status merged
systemoperator Mar 14, 2020
271b97a
refactoring gulpfile; merging Zotero and zsc files to common folder e…
systemoperator Mar 14, 2020
c0f0f14
rm zsc folder
systemoperator Mar 14, 2020
1b515e7
changes for git subtree for zotero-scholar-citations (zsc)
systemoperator Mar 15, 2020
05f8bdb
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Mar 15, 2020
0259bb2
takeSnapshots integrated
systemoperator Mar 15, 2020
8c13932
description for potentially incomplete item refined
systemoperator Mar 15, 2020
d8c0027
setting _preferDoiForLookupIfExisting to false
systemoperator Mar 18, 2020
58c3811
fetching citation count is more reliable now by picking appropriate s…
systemoperator Mar 21, 2020
42ea1ad
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator May 13, 2020
ad9b6c2
packages updated
systemoperator May 13, 2020
7c034df
don't start websocket client, until JabRef's counterpart is integrated
systemoperator May 13, 2020
11b6fd4
fix for fetching references when citation count is disabled
systemoperator May 17, 2020
71261c6
Merge remote-tracking branch 'upstream/master' into dev-zsc
systemoperator Jan 20, 2021
0bb3816
update package-lock
systemoperator Jan 20, 2021
74674d1
small cleanup
systemoperator Jan 20, 2021
83af655
small cleanup
systemoperator Jan 20, 2021
f69e460
refactoring connector
systemoperator Jan 20, 2021
e9c0ade
refactor options.js
systemoperator Jan 20, 2021
331164b
refactoring bibtex/biblatex export mode
systemoperator Jan 20, 2021
efe5e38
minor cleanup
systemoperator Jan 21, 2021
ca19144
readme updated
systemoperator Jan 21, 2021
306a875
readme: fix wording
systemoperator Jan 21, 2021
cc6a14b
vs code workspace added
systemoperator Jan 21, 2021
f842599
revert package-lock.json
systemoperator Jan 21, 2021
d1ba670
minor cleanup
systemoperator Jan 21, 2021
ef3ebdd
Merge branch 'main' into dev-zsc
tobiasdiez Jan 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
JabFox.sublime-workspace
node_modules
web-ext-artifacts

Expand Down Expand Up @@ -78,3 +77,128 @@ $RECYCLE.BIN/
*.lnk

# End of https://www.gitignore.io/api/linux,macos,windows

# Created by https://www.gitignore.io/api/intellij,sublimetext
# Edit at https://www.gitignore.io/?templates=intellij,sublimetext

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/**/sonarlint/

# SonarQube Plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/

### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# Workspace files are user-specific
*.sublime-workspace

# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project

# SFTP configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

# End of https://www.gitignore.io/api/intellij,sublimetext
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.name

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

16 changes: 16 additions & 0 deletions .idea/checkstyle-idea.xml

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

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

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

6 changes: 6 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ To update dependencies:
- `npm outdated` gives an overview of outdated packages ([doc](https://docs.npmjs.com/cli/outdated))
- `npm-upgrade` updates all packages
- `npm install` install updated packages
-
- running
```
git subtree pull --prefix zotero-connectors https://github.com/zotero/zotero-connectors.git master --squash
git subtree pull --prefix zotero-connectors/src/zotero https://github.com/zotero/zotero.git master --squash
git subtree pull --prefix zotero-scholar-citations https://github.com/MaxKuehn/zotero-scholar-citations.git master --squash
```
updates `zotero-connectors` submodule
updates the `zotero-connectors` submodule and the `zotero-scholar-citations` submodule

- `gulp update-zotero-scripts` copies and post-processes Zotero scripts from `zotero-connectors` to `Zotero` folder

Expand Down
8 changes: 8 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Zotero.Repo.init();
Zotero.Messaging.init();
Zotero.Connector_Types.init();
Zotero.Translators.init();
zsc.init();
wsClient.startClient();

/*
Show/hide import button for all tabs (when add-on is loaded).
Expand Down Expand Up @@ -121,6 +123,12 @@ browser.runtime.onMessage.addListener(function(message, sender, sendResponse) {
console.log("JabRef: Start translation for tab %o", JSON.parse(JSON.stringify(tab)));
Zotero.Connector_Browser.saveWithTranslator(tab, 0);
});
} else if (message.getWsClientState) {
console.debug("JabRef: wsClientState requested");
let wsClientState = {};
wsClientState.clientStarted = wsClient.isClientStarted();
wsClientState.connectionState = wsClient.getConnectionState();
sendResponse(wsClientState);
} else if (message.eval) {
console.debug("JabRef: eval in background.js: %o", JSON.parse(JSON.stringify(message.eval)));
return evalInTab(sender.tab.id, message.eval);
Expand Down
16 changes: 11 additions & 5 deletions bibtexConverter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
convertToBibTex = function(items) {
console.log("JabRef: Convert items to BibTeX: %o", items);
convertToBibTex = function(items, conversionMode) {
var deferred = Zotero.Promise.defer();

var translation = new Zotero.Translate.Export();

translation.setItems(items);
translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); // BibTeX
if (conversionMode === 1) {
systemoperator marked this conversation as resolved.
Show resolved Hide resolved
console.log("JabRef: Converting item(s) to BibLaTeX: %o", items);
translation.setTranslator("b6e39b57-8942-4d11-8259-342c46ce395f"); // BibLaTeX
}
else {
console.log("JabRef: Converting item(s) to BibTeX: %o", items);
translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); // BibTeX
}
translation.setHandler("done", function(obj, worked) {
if (worked) {
deferred.resolve(obj.string);
Expand Down Expand Up @@ -232,6 +238,6 @@ Zotero.Schema = new function() {
browser.runtime.onMessage.addListener(message => {
if (message.convertToBibTex) {
console.log("JabRef: Got task to convert %o to BibTeX", message.convertToBibTex);
return convertToBibTex(message.convertToBibTex);
return convertToBibTex(message.convertToBibTex, message.conversionMode);
}
});
62 changes: 45 additions & 17 deletions connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,56 @@ if (!Date.prototype.toISODate) {
Zotero.Connector = new function() {
this.callMethod = Zotero.Promise.method(function(options, data, cb, tab) {
throw new Error("JabRef: Tried to contact Zotero standalone: " + options);
})
});

this.callMethodWithCookies = function(options, data, tab) {
if (options == "saveItems") {
this.convertToBibTex(data.items)
.then((bibtex) => this.sendBibTexToJabRef(bibtex));
} else if (options == "saveSnapshot") {
if (options === "saveItems") {
browser.storage.sync.get(['exportMode', 'takeSnapshots', 'retrieveCitationCounts'])
.then(configuration => {
// fetch current settings
configuration.exportMode = configuration.exportMode || 2;
systemoperator marked this conversation as resolved.
Show resolved Hide resolved
configuration.takeSnapshots = configuration.takeSnapshots || false;
configuration.retrieveCitationCounts = configuration.retrieveCitationCounts || false;
console.debug("exportMode: " + configuration.exportMode);
console.debug("takeSnapshots: " + configuration.takeSnapshots);
console.debug("retrieveCitationCounts: " + configuration.retrieveCitationCounts);

let items = [];

if (configuration.retrieveCitationCounts) {
console.log("[scholar-citations] fetching citation counts...");

// create zsc compatible items
for (let i = 0; i < data.items.length; i++) {
let item = new ZscItem(data.items[i]);
// add internal metadata
item.setField('_externalRequest', false); // false: triggered from browser; true: triggered from JabRef
item.setStatus(false, true, false, false); // init: no success, item complete (initial assumption), no captcha, not too many requests
items.push(item);
}

// get citations counts for all items
zsc.processItems(items);
}

this.convertToBibTex(items, configuration.exportMode, configuration.takeSnapshots)
.then((bibtex) => this.sendBibTexToJabRef(bibtex));
});
} else if (options === "saveSnapshot") {
// Ignore this
} else {
throw new Error("JabRef: Tried to contact Zotero standalone: " + options);
}
}
};

this.checkIsOnline = Zotero.Promise.method(function() {
var deferred = Zotero.Promise.defer();
// Pretend that we are connected to Zotero standalone
deferred.resolve(true);
return deferred.promise;
})
});

this.prepareForExport = function(items) {
// TODO: Get value from preferences
var shouldTakeSnapshots;
this.prepareForExport = function(items, takeSnapshots) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
for (var j = 0; j < item.attachments.length; j++) {
Expand All @@ -40,7 +67,7 @@ Zotero.Connector = new function() {
var isLink = attachment.mimeType === 'text/html' || attachment.mimeType === 'application/xhtml+xml';
if (isLink && attachment.snapshot !== false) {
// Snapshot
if (shouldTakeSnapshots && attachment.url) {
if (takeSnapshots && attachment.url) {
attachment.localPath = attachment.url;
} else {
// Ignore
Expand All @@ -59,10 +86,10 @@ Zotero.Connector = new function() {
item.accessDate = new Date().toISODate();
}
}
}
};

this.convertToBibTex = function(items) {
this.prepareForExport(items);
this.convertToBibTex = function(items, conversionMode, takeSnapshots) {
this.prepareForExport(items, takeSnapshots);

browser.runtime.sendMessage({
"onConvertToBibtex": "convertStarted"
Expand All @@ -75,12 +102,13 @@ Zotero.Connector = new function() {
for (let tab of tabs) {
return browser.tabs.sendMessage(
tab.id, {
convertToBibTex: items
convertToBibTex: items,
conversionMode: conversionMode
}
);
}
})
}
};

this.sendBibTexToJabRef = function(bibtex) {
browser.runtime.sendMessage({
Expand All @@ -105,4 +133,4 @@ Zotero.Connector = new function() {
});
});
}
}
};
Loading