User:MarMi wiki/global.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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
console.log("global start");

//Tests

mw.hook('wikipage.diff.wikitextBodyUpdate').add(function (nac, helpers) {
	mw.notify('wikipage.diff.wikitextBodyUpdate');
});
mw.hook('mediawiki.action.view.postEdit').add(function (nac, helpers) {
	mw.notify('mediawiki.action.view.postEdit');
});
mw.hook('ve.deactivate').add(function (nac, helpers) {
	console.log('ve.deactivate');
});
mw.hook('ve.deactivationComplete').add(function (nac, helpers) {
	console.log('ve.deactivationComplete');
});
mw.hook('util.addPortlet').add(function (nac, helpers) {
	mw.notify('util.addPortlet');
});

mw.hook('wikipage.editform').add(function (nac, helpers) {
	console.log('wikipage.editform');
});

mw.hook('wikipage.tableOfContents').add(function (nac, helpers) {
	console.log('wikipage.tableOfContents');
});

mw.hook('skin.logout').add(function (nac, helpers) {
	mw.notify('skin.logout');
});

mw.hook('wikipage.diff').add(function (nac, helpers) {
	console.log('wikipage.diff');
});

mw.hook('userjs.wp_sk.loaded').add(function (nac, helpers) {
	console.log('userjs.wp_sk.loaded');
});

mw.hook('userjs.wp_sk.redir.done').add(function (nac, helpers) {
	console.log('userjs.wp_sk.redir.done');
});

mw.hook('userjs.gConfig.ready').add(function (nac, helpers) {
	console.log('userjs.gConfig.ready');
});

mw.hook('util.addPortletLink').add(function (nac, helpers) {
	console.log('util.addPortletLink');
});

mw.hook('wikipage.indicators').add(function (nac, helpers) {
	console.log('wikipage.indicators');
});

mw.hook('wikipage.content').add(function (nac, helpers) {
	console.log('wikipage.content');
});

mw.hook('wikipage.categories').add(function (nac, helpers) {
	console.log('wikipage.categories');
});

mw.hook('mw.uls.compactlinks.initialized').add(function (nac, helpers) {
	console.log('mw.uls.compactlinks.initialized');
});

mw.hook('wikipage.collapsibleContent').add(function (nac, helpers) {
	console.log('wikipage.collapsibleContent');
});

mw.hook('userjs.popups.completed').add(function (nac, helpers) {
	console.log('userjs.popups.completed');
});

mw.hook('preferencesGadgetOptions.fetch').add(function (nac, helpers) {
	console.log('preferencesGadgetOptions.fetch');
});

mw.hook('lintHint.ready').add(function (nac, helpers) {
	console.log('lintHint.ready');
});

mw.hook('lintHint.config').add(function (nac, helpers) {
	mw.notify('lintHint.config');
});

mw.hook('lintHint.table-range').add(function (nac, helpers) {
	//after button press
	console.log('lintHint.table-range');
});

mw.hook('lintHint.config').add(function (nac, helpers) {
	mw.notify('lintHint.config');
});

mw.hook('preferencesGadgetOptions.ready').add(function (nac, helpers) {
	console.log('preferencesGadgetOptions.ready');
});

mw.hook('preferencesGadgetOptions.$button').add(function (nac, helpers) {
	//after button press
	console.log('preferencesGadgetOptions.$button');
});

mw.hook('preferencesGadgetOptions.forward').add(function (nac, helpers) {
	mw.notify('preferencesGadgetOptions.forward');
});

mw.hook('preferencesGadgetOptions.form').add(function (nac, helpers) {
	mw.notify('preferencesGadgetOptions.form');
});

mw.hook('wikipage.diff.diffTypeSwitch').add(function (nac, helpers) {
	console.log('wikipage.diff.diffTypeSwitch');
});

mw.hook('ve.activationStart').add(function (nac, helpers) {
	console.log('ve.activationStart');
});

mw.hook('ve.loadModules').add(function (nac, helpers) {
	console.log('ve.loadModules');
});

mw.hook('ve.wikitextInteractive').add(function (nac, helpers) {
	console.log('ve.wikitextInteractive');
});

mw.hook('userjs.script-ready.veAutocorrect').add(function (nac, helpers) {
	console.log('userjs.script-ready.veAutocorrect');
});

mw.hook('userjs.przyciskiOpis.gotowe').add(function (nac, helpers) {
	console.log('userjs.przyciskiOpis.gotowe');
});

mw.hook('userjs.wp_sk.ready').add(function (nac, helpers) {
	console.log('userjs.wp_sk.ready');
});

mw.hook('userjs.wp_sk.command_created').add(function (nac, helpers) {
	console.log('userjs.wp_sk.command_created');
});

mw.hook('ve.skinTabSetupComplete').add(function (nac, helpers) {
	console.log('ve.skinTabSetupComplete');
});

mw.hook('ve.activate').add(function (nac, helpers) {
	console.log('ve.activate');
});

mw.hook('ve.activationComplete').add(function (nac, helpers) {
	console.log('ve.activationComplete');
});

mw.hook('userjs.veNuxAutocorrect').add(function (nac, helpers) {
	console.log('userjs.veNuxAutocorrect');
});

mw.hook('userjs.veNuxAutocorrect.ready').add(function (nac, helpers) {
	console.log('userjs.veNuxAutocorrect.ready');
});


//location.search.indexOf( 'printable=yes' ) === -1 && mw.config.get( 'wgPageContentModel' ) !== 'wikibase-item' &&
const printable=location.search.indexOf( 'printable=yes' );
if (printable>-1)
	alert('printable=yes: '+location);
const wgPageContentModel=mw.config.get( 'wgPageContentModel' );
if (! /^(javascript|wikitext|css|wikibase-item|Scribunto|wikibase-property)$/.test(wgPageContentModel))
	alert('wgPageContentModel: '+wgPageContentModel);

//namespace !== 2 && namespace !== -1 &&
const namespace=mw.config.get( 'wgNamespaceNumber' );
if (![-1,0,1,2,3,4,5,6,7,8,10,11,12,14,15,102,103,120,828,829,1198].includes(namespace))
	alert('wgNamespaceNumber: '+namespace+" / "+mw.config.get( 'wgFormattedNamespaces' )[ namespace ]);

//console.log('wgAction',mw.config.get( 'wgAction' ));
const wgAction=mw.config.get( 'wgAction' );
if (! /^(view|edit|history|submit|info|rollback|purge|dtunsubscribe)$/.test(wgAction))
	alert('wgAction: '+wgAction);

const wgSiteName=mw.config.get("wgSiteName");

// Main

if ( namespace==0 && wgAction == "view" && location.search.indexOf('veaction=')<0 && wgSiteName!="Wikidata" ) {
	//$.when($.ready).then( function() {
		//console.log("g ready");
		
	//mw.hook('mw.uls.compactlinks.initialized').add(function () {
		// not in edit
		/*if (!ve.init)
		{*/
			mw.notify("WikidataInfo");	
			console.log("WikidataInfo");
			// [[:pl:User:MarMi wiki/WikidataInfo.js]]
			// 404 lines
			mw.loader.load( '//pl.wikipedia.org/w/index.php?title=User:MarMi_wiki/WikidataInfo.js&action=raw&ctype=text/javascript' );
		
			
			const lang=mw.config.get("wgPageContentLanguage");
			//do nothing if known language
			if (!/^(pl|en)$/.test(lang))
			{
				console.log("wgPageContentLanguage",lang);
				
				mw.hook("wikipage.content").add(function() {
					mw.notify("Google translate");
					console.log("Google translate");
					// Google translate	based on [[:en:User:Equazcion/SidebarTranslate]]
					
					 // h1 - article title
					 //h2, h3, ...
					 const headings = $('h1,h2');
					// console.log(headings);
					
					 // do nothing if no headings
					 /*if (headings.length<1)
					  return;*/
					
					//mw.hook("gTrans.run").add(function() {
					 // for all headings in collection do the same thing
					headings.each(function() {
						// add translation link
					 	$('<span/>', {
					 		class: 'mw-editsection',
					 		html: $('<a/>', {
								text: 'G',
								class: 'external gTrans',
								href: 'https://translate.google.pl/translate?sl=auto&tl=en&u=' +
									$('link[rel="canonical"]').attr('href'),
								title: 'Google translate: ' + lang + ' to English'
							})
					 	}).appendTo( this );
					
					});
				});
				 //importStylesheet('User:Equazcion/SidebarTranslate.css');
				 //siblings('.gTrans')
			}
		//}
	//});

}

//[[:c:User:Jack_who_built_the_house/convenientDiscussions.js]]
//~20 332 lines
//https://tools-static.wmflabs.org/convenient-discussions/docs/module-defaultConfig.html#.archivePaths
//https://commons.wikimedia.org/wiki/User:Jack_who_built_the_house/Convenient_Discussions#Configuring_for_a_wiki
const wgCanonicalNamespace=mw.config.get("wgCanonicalNamespace");
//console.log("wgCN:",wgCanonicalNamespace);
if (!/^(User|Talk|Project|Special|MediaWiki|Template|User_talk|File|File_talk|Help|Project_talk|Category|Template_talk|Wikiprojekt|Dyskusja_wikiprojektu|Module|Module_talk|Property|Extension|Translations|Category_talk|)$/.test(wgCanonicalNamespace))
	alert("wgCanonicalNamespace: "+wgCanonicalNamespace);
if (wgAction == "view" && location.search.indexOf('diff=')<0 && !mw.config.get("wgIsMainPage"))
{
	if (/^(Project|User_talk|Template_talk|Talk|Module_talk|Category_talk)$/.test(mw.config.get("wgCanonicalNamespace")))	//|Dyskusja_wikiprojektu
	{
		mw.notify("CD");
		console.log("CD");
		mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions.js&action=raw&ctype=text/javascript');
	}
}


//Search Antifocus
//mw.hook('advancedSearch.configureFields').add(function () {
//	console.log('advancedSearch.configureFields');

//if (mw.config.get( 'wgCanonicalSpecialPageName') == 'Search')
//{
//	console.log($('#ooui-php-1'));
	//console.log($('#ooui-php-1').attr('disabled'));

//to to	
//	$('#ooui-php-1').attr('disabled',true);

	//console.log($('#ooui-php-1').attr('disabled'));
	
	/*$.when(mw.loader.using("ext.advancedSearch.searchtoken")).then( function(){
  $('#ooui-php-1').attr('disabled',true)
  console.log('disable')
  //debugger
  //console.log(mw.loader.getModuleNames().filter( function ( module ) {return mw.loader.getState( module ) === 'ready';} ).join('\n'))
 } )

	$('#ooui-php-1').one("focus", function( event ) {
		//event.preventDefault()
//		debugger
		//event.stopPropagation()
		//event.stopImmediatePropagation()
		console.log('0 '+$('#ooui-php-1').is(':focus'))
		$('#ooui-php-1').one("focus", function( event ) {
			//event.preventDefault()
			//event.stopImmediatePropagation()
			console.log('1 '+$('#ooui-php-1').is(':focus'))
		})
	})

 $.when($.ready).then(function(){
	console.log('ready')
  //	debugger
  //	$('#ooui-php-1').attr('disabled',false)
 })*/
//}
//} );

console.log("global end");