JabRef-Browser-Extension
JabRef-Browser-Extension copied to clipboard
Add references to non-zotero websites
Still getting started with this so forgive me if I've overlooked something obvious. The following applies when using this extension in Chrome:
The documentation in the plugin's readme says "When you find an interesting article through Google Scholar, the arXiv or journal websites, this browser extension allows you to add those references to JabRef."
When I go to one of those websites and I click the little JabRef button in my chrome toolbar, sure enough it opens JabRef and I can import the citation. Great!
But when I go to a random website I want to cite, for example https://ridiculousfish.com/blog/posts/colors.html, clicking on the same button brings up the extension's context menu (ie the menu you see when you right click the button). There's no explanation given as to why this behavior is occurring, ie no message saying "This is not a website that we have a zotero translator for" or anything like that. My inference is that's the issue, but I don't know for sure.
In my use case, I want to be able to cite sources that don't have translators available, simply adding them without all the extra metadata that the translator can provide. Zotero itself does allow adding of arbitrary links like the one I mentioned above. I can add any additional fields I need by hand.
If for some reason that's impossible, as a fallback I'd request that a warning be shown to the user in cases where the import cannot occur, rather than unexpectedly showing an unrelated menu.
In Firefox, the import button is inside the search bar instead of the toolbar, which is unintuitive. Additionally, rather than having strange behavior on unsupported sites, the button instead disappears completely, which is extremely confusing. The inappropriate showing of the context menu does not occur, but only because the button has inexplicably vanished.
Good suggestion to ask the user if she wants to fallback to a simple import if there is no zotero translator for this page.
For firefox, the buttons in the address bar are for actions for the current page. See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Page_actions. So I think we are adhering to the official recommendations.
I have never done browser extension development before, but it's something I'd probably be able to figure out eventually. If you'd like to point at where I could make such changes, that would be great. Otherwise if it's an easy fix for someone experienced, that's fine too :)
The code here is responsible for handling the "no translator found"-case: https://github.com/JabRef/JabRef-Browser-Extension/blob/9aee2a0a350f1ec7fc2a177e8a059c13c0fcd380/background.js#L107-L109 here is how zotero handles that case https://github.com/zotero/zotero-connectors/blob/172daa1e7c2c78f390049eef4c996b4adf874107/src/browserExt/background.js#L606-L615 https://github.com/zotero/zotero-connectors/blob/172daa1e7c2c78f390049eef4c996b4adf874107/src/browserExt/background.js#L801-L803 https://github.com/zotero/zotero-connectors/blob/172daa1e7c2c78f390049eef4c996b4adf874107/src/common/translate_item.js#L75-L85
Let me know if you get stuck somewhere!
Definitely got stuck :) It looks like getting the button to stay showing up is on line 154, so I copied the show and setTitle from the other case and changed the text to not reference the translator label. That was easy enough with your hint.
However, getting the actual save to occur is not quite as simple. On line 193 the process starts, and I immediately hit a snag in not knowing how to tell that no translators were found, since that context information from 154 isn't available here and I don't see how to pass it along. Additionally, trying various incarnations of Zotero.Connector_Browser.saveAsWebpage(tab, 0) have generated various messages in the debug console, but hasn't launched JabRef to import the citation. I'm not sure how that mechanism is triggered.
I will keep digging, but if you have ideas of how to proceed past those two issues, I'd appreciate them. :)
For the first point, instead of (or in addition to?) https://github.com/JabRef/JabRef-Browser-Extension/blob/9aee2a0a350f1ec7fc2a177e8a059c13c0fcd380/background.js#L87 you could set the tabInfo in lookForTranslators
and enrich it by information whether there is a translator for it or not.
For the second point, its probably easier to not call Zotero's saveAsWebpage
, but just construct the bibtex by hand (using tab title, current date etc) and send it to JabRef. This would be similar to savePdf
.
Since you make good progress already, may I suggest that you open a PR and we continue there? Is usually easier if you have all the context available.
PR created, #442 . Your suggestion to duplicate savePdf was crucial. I think this should work okay. Side note, sorry about the whitespace change in the PR, my editor keeps rewriting the white space and git add -i could dodge most of that but not that one particular comment.
It looks like some of our conversation has been lost. As we discussed, I've added a different icon to indicate that the source being cited does not have a translator from zotero. What else do we need to do to move this forward?
This has been implemented in #442.