Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
importScript("User:Jon_Harald_Søby/warnOnLargeFile.js");
importScript("User:Nikki/sandbox.js");
importScript("User:Sohom Datta/bookreader.js");


// Add ".json" to the concept URI link in the sidebar
if (document.getElementById("t-wb-concept"))
	document.querySelector("#t-wb-concept-uri a").href += ".json";


window.acdcFavoriteProperties = [
	"P180", // depicts
//	"P170", // creator
//	"P275", // copyright license
	"P407", // language of work or name
//	"P4082", // captured with
	"P1684", // inscription
	"P282", // writing system
	"P31", // instance of
];

function acdc_with_files() {
	if (!$("#t-acdc").length)
		return;

	$("<span> (<a>with files</a>)</span>").on("click", function() {
		setTimeout(function () {
			var files = Array.from(document.querySelectorAll(".cat_a_lot_selected a"), function (x) { return x.title });
			if (!files.length && mw.config.get("wgNamespaceNumber") === 6)
				files = [mw.config.get("wgPageName")];
			if (!files.length)
				files = Array.from(document.querySelectorAll("#mw-category-media ul li a.galleryfilename"), function (x) { return x.title });
			document.querySelector(".acdc-fileInputWidget-input").value = files.join("|");
			document.querySelector(".acdc-fileInputWidget-input").dispatchEvent(new Event("blur"));
		}, 500);
		$("#t-acdc").click();
	}).appendTo("#t-acdc");
}
mw.hook("wikipage.content").add(function () {
	mw.hook("gadget.acdc.loaded").add(acdc_with_files);
});

// [[:d:MediaWiki:Gadget-KeyShortcuts.js]]
$( function () {
	'use strict';
	
	var structuredData = function () {
		var $tab = $("#ooui-php-8");
		var mouseDownEvent = jQuery.Event("mousedown");
		mouseDownEvent.which = 1;
		mouseDownEvent.target = $tab;
		$tab.trigger(mouseDownEvent);
		var mouseUpEvent = new MouseEvent("mouseup", {"button": 0});
		//mouseUpEvent.which = 1;
		//mouseUpEvent.target = $tab;
		$tab[0].dispatchEvent(mouseUpEvent);
		$(".oo-ui-lookupElement input").first().focus();
	};
	$( this )
	.keydown( function ( event ) {
		 if (
		 	!event.ctrlKey &&
		 	!event.altKey &&
		 	!event.shiftKey &&
		 	!event.metaKey &&
		 	$( ':focus' ).length === 0
		 ) {
		 	switch ( event.keyCode ) {
				case 83: structuredData();return false; // S
			}
		 }
	} );
} );