User:Alien333/cuts.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/* global $, mw */
"use strict";
mw.loader.using(['mediawiki.util'], () => {
  $(() => { 
  	window.addEventListener("keydown", (e) => {
  			if (getstring(e.keyCode, getmods(e), mw.config.get("wgCanonicalNamespace")) in cuts) {
  				cuts[getstring(e.keyCode, getmods(e), mw.config.get("wgCanonicalNamespace"))].call();
  			} else if (getstring(e.keyCode, getmods(e), "_any_") in cuts) {
  				cuts[getstring(e.keyCode, getmods(e), "_any_")].call();
  			}
  	});
  });
});
var cuts = {};
function editonly (f) {
	return (() => {
		if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) != -1) {
			f.call();
		}
	});
}
function getstring(code, mods, ns) {
	return (code.toString() + "_" + mods + "_" + ns);
}
function add(code, mods, ns, f) {
	cuts[getstring(code, mods, ns)] = f;
}
function getmods(e) {
	return ((e.shiftKey?"1":"0")+(e.ctrlKey?"1":"0")+(e.metaKey?"1":"0")+(e.altKey?"1":"0"));
}
add(37, "0110", "Page", () => {window.open($("#ca-proofreadPagePrevLink")[0].childNodes[0].href)});
add(39, "0110", "Page", () => {window.open($("#ca-proofreadPageNextLink")[0].childNodes[0].href)});
add(37, "0100", "Page", () => {window.location.href = $("#ca-proofreadPagePrevLink")[0].childNodes[0].href});
add(39, "0100", "Page", () => {window.location.href = $("#ca-proofreadPageNextLink")[0].childNodes[0].href});
add(37, "0110", "", () => {window.open($(".wst-header-back-link")[0].childNodes[0].href)});
add(39, "0110", "", () => {window.open($(".wst-header-forward-link")[0].childNodes[0].href)});
add(37, "0100", "", () => {window.location.href = $(".wst-header-back-link")[0].childNodes[0].href});
add(39, "0100", "", () => {window.location.href = $(".wst-header-forward-link")[0].childNodes[0].href});
add(73, "0110", "Page", editonly(() => {$("#t-running-header").trigger("click")}));
add(79, "0110", "Page", editonly(() => {poemise()}));
add(85, "0110", "Page", editonly(() => {nobr()}));
add(80, "0110", "Page", editonly(() => {
	const pageQualityWidget = OO.ui.infuse($('.prp-pageQualityInputWidget'));
	pageQualityWidget.radioSelectWidget.selectItemByData("3");
	$("#wpSave").trigger("click");
	})
);
add(38, "0100", "Page", () => {window.location.href = $("#ca-proofreadPageIndexLink")[0].childNodes[0].href});
add(38, "0110", "Page", () => {window.open($("#ca-proofreadPageIndexLink")[0].childNodes[0].href)});
add(38, "0100", "" , () => {window.location.href = "https://en.wikisource.org/wiki/" + mw.config.get("wgPageName").split("/")[0]});
add(38, "0110", "", () => {window.open("https://en.wikisource.org/wiki/" + mw.config.get("wgPageName").split("/")[0], "_blank")});
add(27, "0100", "_any_", editonly(() => {window.location.href = "https://en.wikisource.org/wiki/" + mw.config.get("wgPageName")}));
add(89, "0110", "", () => similar());