MediaWiki:Gadget-fileDownload.js

From Old School Near-Reality Wiki
Revision as of 18:15, 3 October 2022 by Jacmob (talk | contribs) (Created page with "→‎* * Adds a download link to file pages * * @author Gaz Lloyd: $(function(){ if (!(mw.config.get('wgNamespaceNumber') === 6 && $('.fullMedia, .filehistory').length > 0)) { return; } function addLinks() { // underneath image - also replace filename with page title $('.fullMedia a.internal').after( ' (', $('<a>') .text('download') .addClass('fileDownload') .attr({ href: $('.fullMedia a.internal').attr('href'), download: mw.conf...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.
 1 /**
 2  * Adds a download link to file pages
 3  * 
 4  * @author Gaz Lloyd
 5  */
 6 $(function(){
 7 	if (!(mw.config.get('wgNamespaceNumber') === 6  && $('.fullMedia, .filehistory').length > 0)) {
 8 		return;
 9 	}
10 	function addLinks() {
11 		// underneath image - also replace filename with page title
12 		$('.fullMedia a.internal').after(
13 			' (',
14 			$('<a>')
15 				.text('download')
16 				.addClass('fileDownload')
17 				.attr({
18 					href: $('.fullMedia a.internal').attr('href'),
19 					download: mw.config.get('wgTitle').replace('_', ' '),
20 					title: 'Download this file'
21 				}),
22 			')'
23 		);
24 		
25 		// file history - leave numbers in file name
26 		$('.filehistory tr td[style]').each(function() {
27 			var $this = $(this);
28 			$this.append(
29 				$('<br />'),
30 				$('<a>')
31 					.text('Download')
32 					.addClass('fileDownload')
33 					.attr({
34 						download: '',
35 						href: $this.find('a').attr('href'),
36 						title: 'Download this version of this file'
37 					})
38 			);
39 		});
40 	}
41 	addLinks()
42 })