User:Technical 13/SandBox/Gadget-listStyles.js

var type = "ul"; var path = $( 'ul' ); console.log( 'path = %o\ntype = %s', path, type ); function addPtLink( type, path ){ var listStyle = mw.util.addPortletLink(		'p-personal',		'#',		'(list style)',		'pt-liststyle',		'Switch list style between bullet and numbered [alt-shift-`]',		'`',		'#pt-userpage'	); if( type == "ul" ){ $( listStyle ).click( function ( e ) {			e.preventDefault;			path.css( 'list-style-image', 'none' );			path.css( 'list-style-type', function (i, val) { return val === "decimal" ? "disc" : "decimal"; });		});	} else if( type == "table" ){ var cellNumber = 0; console.log( 'cellNumber = %d', cellNumber ); path.each(function{			cellNumber++;			console.log( 'cellNumber = %d', cellNumber );			$( this ).html( ' ' + cellNumber + '. ' + $( this ).html);		}); $( listStyle ).click( function ( e ) {			e.preventDefault;			path.find( 'span.listStyle-item' ).css( 'style', function (i, val) { return val === "none" ? "inline" : "none"; });		});	} } var pageAction = mw.config.get( 'wgAction' ); console.log( 'pageAction = %s', pageAction ); if ( pageAction != 'history' ){ var nsNumber = mw.config.get( 'wgNamespaceNumber' ); console.log( 'nsNumber = %d', nsNumber ); if ( nsNumber === -1 ){ // Special: pages var specialPageName = mw.config.get( 'wgCanonicalSpecialPageName' ); console.log( 'specialPageName = %s', specialPageName ); if ( specialPageName == 'Whatlinkshere' ){ // Special:WhatLinksHere path = $( 'ul#mw-whatlinkshere-list' ); console.log( 'path = %o', path ); addPtLink( type, path ); } else if ( specialPageName == 'Contributions' ){ // Special:Contributions path = $( 'a.mw-changeslist-date' ).parents( 'ul' ); console.log( 'path = %o', path ); addPtLink( type, path ); } else if ( specialPageName == 'Log' ){ // Special:Log path = $( 'ul.mw-search-results' ); console.log( 'path = %o', path ); addPtLink( type, path ); } else if ( specialPageName == 'AbuseLog' && document.URL.indexOf("&wpSearchFilter=") != "-1" ){ // Special:AbuseLog path = $( 'ul.plainlinks' ); console.log( 'path = %o', path ); addPtLink( type, path ); } else if ( specialPageName == 'Prefixindex' ){ // Special:PrefixIndex type = "table"; console.log( 'type = %s', type ); var piPage = mw.config.get( 'wgTitle' ); console.log( 'piPage = %s\nThe first "/" is at character number: %d', piPage, pipage.indexOf( '///' ) ); piPage = piPage.substring( pipage.indexOf( '///' ) ); console.log( 'pipage = %s', piPage ); path = $( 'table#mw-prefixindex-list-table' ); console.log( 'path = %o', path ); path.html( ' The total number subpages to ' + piPage + ' is: (click to count)  ' + path.html ); path = path.find( 'td' ); console.log( 'path = %o', path ); addPtLink( type, path ); }	} else if ( nsNumber != 14){ //		var pageName = mw.config.get( 'wgPageName' ); //		console.log( 'pageName = %s', pageName ); } else { // [[Category:]] path = $( 'div.mw-content-ltr' ).find( 'ul' ); console.log( 'path = %o', path ); addPtLink( type, path ); } } else { // &action=history path = $( 'ul#pagehistory' ); console.log( 'path = %o', path ); addPtLink( type, path ); }