Jump to content

User:Horcrux/RedFileLinkClicker.js

From Meta, a Wikimedia project coordination wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
 * It opens a red link of a file both on the local site and on Wikimedia Commons.
 * It may be useful for checking the motivation for a file deletion,
 * since you don't know a priori if it has been deleted locally or on Commons.
 */
$( function() {
	if (mw.config.get('wgSiteName') !== 'Wikimedia Commons' ) {
		var open_f = function (e, filename) {
		    e.preventDefault();
		    window.open('/wiki/File:' + filename);
		    window.open('/wiki/c:File:' + filename);
		};
		
		// red file links
		$("a.new").each((i,el) => {
			let href = $(el).attr("href");
			if (typeof href !== 'undefined' && href.indexOf("wpDestFile=") != -1) {
				let filename = href.match(/wpDestFile=(.*)/)[1]
				$(el).on("click", (e) => open_f(e, filename));
			}
		});
		
		// galleryboxes not containing an image
		$("li.gallerybox div.thumb:not(:has(img))").each((i,el) => {
			$(el).on("click", (e) => open_f(e, $(el).text()))
		});
	}
});