zotero / zotero-connectors

Chrome, Firefox, Edge, and Safari extensions for Zotero
https://www.zotero.org/download/connectors
Other
531 stars 124 forks source link

MV3: Support CSL import from all .csl gitee pages #507

Closed jiaojiaodubai closed 3 months ago

jiaojiaodubai commented 3 months ago
  1. Github is often inaccessible in Chinese Mainland due to unaudited political content.
  2. In China, Gitee, also based on Git, is widely used as an alternative to GitHub.

Most East Asian style rely on CSL-M to achieve, and these styles are not allowed to be merged into CSL Syle's repository, though some are popular. We have maintained a large number of such styles and synchronized them to Gitee. In order to facilitate their distribution (as well as other styles that may be hosted on Gitee), I made this request.

adomasven commented 3 months ago

I'm not sure you understand entirely what we're doing with this code.

For Firefox, Safari and Edge with the current Zotero Connector, all you need to do is go into the Zotero Connector Preferences -> Advanced -> Config Editor and change the allowedCSLExtensionHosts parameter to ["raw.githubusercontent.com", "gitee.com"].

MV3 stuff is only relevant with Chrome. We're going to add direct support for allowedCSLExtensionHosts in MV3 though https://github.com/zotero/zotero-connectors/issues/508

jiaojiaodubai commented 3 months ago

I'm not sure you understand entirely what we're doing with this code.

To my knowledge, MV3 is a new standard for Chrome extensions and has been specially treated in the Connector.

For Firefox, Safari and Edge with the current Zotero Connector, all you need to do is ...

I do know that above settings will work, but as a styles distributor, I cannot guarantee that my users will be able to configure them properly. That's why I am trying to modify upstream code.

adomasven commented 3 months ago

I've added gitee.com as an allowed csl extension host in https://github.com/zotero/zotero-connectors/commit/6afc86ba079eeb06347731d3ef64f24a8df0d57c

For MV3 (Chrome) support your changes are wrong and won't work. The DNR rule needs to redirect to a different URL (or the same url with a hash like #importConfirm added at the end which will trigger the import prompt. However it would be better covered by implementing #508. If you want to take that on - we'll be happy to accept a PR. Do note that you need to test on Chrome the build in manifestv3 folder.

jiaojiaodubai commented 3 months ago

I've added gitee.com as an allowed csl extension host in 6afc86b

Thank you for your prompt response. I manually add "gitee.com" to allowedCSLExtensionHosts in Config Editor, but it didn't work. There is a testing page here. Note that unlike GitHub, the blob page and its raw page have the same host.

The DNR rule needs to redirect to a different URL (or the same url with a hash like #importConfirm added at the end which will trigger the import prompt.

After practical operation, I understand your meaning. We need to modify the URL in Connector to trigger confirmation window. I mistakenly thought that Zotero or the webpage had made such changes.

However it would be better covered by implementing #508.

Does this mean that we will automatically add #importConfirm for sites with supported hosts?

If you want to take that on - we'll be happy to accept a PR.

I am not familiar enough with Connector's code, so I may not be able to handle it.

adomasven commented 3 months ago

If I install the default Zotero Connector into Firefox, add gitee.com to allowed hosts, and navigate to https://gitee.com/redleafnew00/Chinese-STD-GB-T-7714-related-csl/raw/main/src/gb-t-7714-2015-note-bilingual/gb-t-7714-2015-note-bilingual.csl I get an import prompt.

I have not tested with Edge. Note that if you are building Zotero Connector yourself and testing with Edge, you need to load the extension from the build/chrome folder, not build/manifestv3. We do not distribute the MV3 extension for Edge.

jiaojiaodubai commented 3 months ago

OK, I conducted some tests.

But as I mentioned earlier, Gitee's blob page and raw page have the same host, so import prompt is also shown on blob page, which is different from GitHub. Is this tolerable?

adomasven commented 3 months ago

But as I mentioned earlier, Gitee's blob page and raw page have the same host, so import prompt is also shown on blob page, which is different from GitHub. Is this tolerable?

It's not ideal but acceptable. If you want to modify this PR to make it work properly for MV3, we will accept it along with the regex changes for allowedCSLExtensionHosts.

jiaojiaodubai commented 3 months ago

If you want to modify this PR to make it work properly for MV3, we will accept it along with the regex changes for allowedCSLExtensionHosts.

Yes, of course I hope that users in MV3 environment can also easily access styles on Gitee.

I built the extension based on current PR and tested it on Edge (127.0.2651.105), Firefox (115.14.0esr), and Chrome (127.0.6533.120). It performed well on both Github and Gitee (Firefox refused to allow me to access Github through a proxy network, so it was not tested).

If regular expressions are used to detect websites, then allowedCLSElongationHosts and their context codes may need to be modified to allowedCLSElongationURL or something in order to more clearly express our intention. In addition, I tend to use [^/]+ instead of [^/]* to represent specific URL parts in my code. The details of these code styles are up to you to decide.

adomasven commented 3 months ago

Merged. Thanks!

We'll keep the allowedCSLExtensionHosts pref name as is. Renaming it requires a pref migration, which is not worth it this change.