User:Nikki/ExpandReferences.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* This script adds a link to the "Statements" heading on item and property pages to expand and collapse all references.

   To use it, add the following line to your common.js:
   mw.loader.load("//www.wikidata.org/w/index.php?title=User:Nikki/ExpandReferences.js&action=raw&ctype=text/javascript");
*/

(function () {
	"use strict";

	mw.loader.using("jquery.i18n").then(async function() {

	let translations = new mw.Title("User:Nikki/translations.json").getUrl() +
			"?action=raw&ctype=application/json";
	await $.i18n().load(translations);

	$("#claims").append(" <small style='color:grey'>(<span></span>)</small>");
	$("<a data-text='" + $.i18n("collapse-all-references")
		+ "' style='color:grey;cursor:pointer'>" + $.i18n("expand-all-references") + "</a>").click(function () {
		var currenttext = $(this).text();
		var previoustext = $(this).data("text");
		var selector = "div.wikibase-statementview-references-container a.ui-toggler";

		if (!$(this).data("state")) {
			$(this).data("state", 1);
			selector += "-toggle-collapsed";
		}
		$(selector).click();
		$(this).text(previoustext);
		$(this).data("text", currenttext);
	}).appendTo("#claims small span");

	});
})();