User:Diegodlh/Web2Cit/script

The Web2Cit user script integrates Web2Cit into Wikipedia's visual editor. Web2Cit is a tool to collaboratively define procedures to automatically extract citation metadata from web sources.

How to install it?
Open your common.js file (or meta:Special:MyPage/global.js, to install across Wikimedia projects), add this at the end and save your changes: You may need to bypass your browser's cache for the changes to take effect.

Alternatively, follow the instructions in User_scripts.

How to use it?
The user script will add a "Web2Cit" checkbox to the dialog that opens when you click on the Visual Editor's "Cite" button.

If the checkbox is enabled, automatic citation generation will be handled by the Web2Cit translation server, which will return two citation results:


 * 1) The citation returned by Citoid, at the top; and
 * 2) The citation returned by Web2Cit, at the bottom.

In this case, a "Powered by Zotero & Web2Cit" legend will appear on the bottom-right corner. Click on "Web2Cit" to see more details and edit the results.

Note that only queries that look like URLs (i.e., starting with,   or following the pattern  ) will be handled this way. Other queries will be handled directly by Citoid as usual.

How do I report an issue?
Please open a task in Phabricator, or post a message on this page's Talk page.

Alternative Web2Cit server instance
By default, Web2Cit user script uses the production instance of Web2Cit server at https://web2cit.toolforge.org/. If you want to use an alternative instance (e.g., the test instance at https://w2c-beta.toolforge.org/), add the following setting to your  file:

How does the user script work?
Briefly, the user script applies three monkey patches:

patch
It monitors all $.ajax requests and modifies those matching the following criteria (all other requests are left untouched):


 * The target path begins with ; i.e., a Citoid request
 * The  parameter of the Citoid request is a URL (starts with ,   or follows the pattern.

These requests are routed to the Web2Cit translation server instead:.

By using the  parameter, the Web2Cit translation server returns both a raw Citoid citation and a Web2Cit citation. This avoids having to make two separate Citoid requests: one for the Citoid citation, and another one for any Citoid selection steps in the Web2Cit translation procedures.

CitoidInspector's patch
This patch adds "Web2Cit" to the credits legend, including a link to the translation result details.

CitoidInspector's patch
This adds the "Web2Cit" checkbox to the "Cite" dialog, to enable and disable Web2Cit translation (i.e., to patch or unpatch  and CitoidInspector's.

This setting is persisted by being saved to the browser's local storage  item.