User:Samwilson/common.js

//mw.loader.load( 'https://fr.wikipedia.org/w/index.php?title=MediaWiki:Gadget-WhereWikimediansLive.css&action=raw&ctype=text/css', 'text/css' );
//mw.loader.load( 'https://fr.wikipedia.org/w/index.php?title=MediaWiki:Gadget-WhereWikimediansLive.js&action=raw&ctype=text/javascript' );

mw.loader.load( 'https://commons.wikimedia.org/w/index.php?title=User:Samwilson/GoogleOCR.js&action=raw&ctype=text/javascript' );
//mw.loader.load( 'https://commons.wikimedia.org/w/index.php?title=User:Samwilson/GoogleOCR_sandbox.js&action=raw&ctype=text/javascript' );
mw.loader.load( 'https://commons.wikimedia.org/w/index.php?title=User:Samwilson/PreviewWhileEditing.js&action=raw&ctype=text/javascript' );

mw.loader.load( 'https://commons.wikimedia.org/w/index.php?title=User:Samwilson/Searchnotincat.js&action=raw&ctype=text/javascript' );

window.catALotPrefs = {
	"disambig_category":"Disambiguation","redir_category":"Category redirects","watchlist":"preferences","minor":false,
	"editpages":false,"docleanup":false,"subcatcount":50,"uncat":true,"button":false
};

if ( mw.config.get('wgCanonicalNamespace') === 'Category' ) {
	var title = mw.config.get( 'wgTitle' );
    mw.util.addPortletLink(
    	'p-cactions', 
		'/wiki/Special:UploadWizard?categories=' + encodeURIComponent( title ),
		'Upload to: ' + title,
		'ca-upload-here', 
		"Upload to the '" + title + "' category",
		null
	);
}

// var time = (new Date()).getTime();
// mw.loader.load( 'http://localhost/wikimedia/mediawiki/samwilson-userscripts/commons.js?' + time );
if ( [ 'edit', 'submit' ].includes( mw.config.get( 'wgAction' ) ) ) {
	mw.hook( 'wikiEditor.toolbarReady' ).add( ( $textarea ) => {
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'main',
			group: 'format',
			tools: {
				smile: {
					label: 'taken on',
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/GNOME_Calendar_icon_2023.svg/20px-GNOME_Calendar_icon_2023.svg.png',
					action: {
						type: 'callback',
						execute: ( context ) => {
							const wikitext = $textarea.val()
								.replace( /date(\s*)=(\s*)([-: +0-9]+)/i, 'date$1=$2{{taken on|$3|location=Australia}}' )
								.replace( /author(\s*)=(\s*)(\[\[User:Samwilson\|Sam *wilson\]\]|Sam Wilson)/i, 'author$1=$2{{User:Samwilson/photographer|camera=}}' )
							;
							$textarea.val( wikitext );
						}
					}
				}
			}
		} );
	} );
}
Category:Pages using Taken on template with incorrect parameter Category:Photos by Sam Wilson Category:Photos by Sam Wilson missing camera name