User:Kiteretsu/EasyResolve.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
+
 
Amos (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:


EasyResolve.config = {
EasyResolve.config = {
name: '[[User:Aviram7/EasyResolve|EasyResolve]]',
name: '[[User:Kiteretsu/EasyResolve|EasyResolve]]',
version: '1.4',
version: '1.4',
debug: false
debug: false
Line 17: Line 17:
// console.log( sectionNumber );
// console.log( sectionNumber );
this.after( ' | ' );
this.after( ' | ' );
$(this).after( $( '<span class="EasyResolveClose" section=' + sectionNumber + '>Close discussion (via script)</span>') );
$(this).after( $( '<span class="EasyResolveClose" section=' + sectionNumber + '>Close this threads</span>') );
} catch ( e ) {
} catch ( e ) {
Line 60: Line 60:
EasyResolve.extraPages = [
EasyResolve.extraPages = [
"Test Wiki:Community portal",
"Test Wiki:Community portal",
'Test Wiki:Request for permissions',
"Test Wiki:Request for permissions",
'User talk:',
"User talk:",
];
];
mw.loader.using( 'mediawiki.api', function() {
mw.loader.using( 'mediawiki.api', function() {

Latest revision as of 02:08, 30 August 2024

//<nowiki>
//Maintained by DannyS712
var EasyResolve = {};
window.EasyResolve = EasyResolve;

EasyResolve.config = {
	name: '[[User:Kiteretsu/EasyResolve|EasyResolve]]',
	version: '1.4',
	debug: false
};
EasyResolve.summary = 'Mark a discussion as resolved (' + EasyResolve.config.name + ' v' + EasyResolve.config.version + ')';
EasyResolve.setup = function () {
	$('span.mw-editsection-bracket:first-child').each( function() {
		// console.log( this );
		try {
			var sectionNumber = this.parentElement.childNodes[1].href.match( /action=edit&section=(\d+)/ )[1];
			// console.log( sectionNumber );
			this.after( ' | ' );
			$(this).after( $( '<span class="EasyResolveClose" section=' + sectionNumber + '>Close this threads</span>') );
		} catch ( e ) {
			
		}
	} );
	$('span.EasyResolveClose').click( function() {
		console.log( this );
		EasyResolve.close( this );
	} );
};
EasyResolve.close = function ( section ) {
	console.log( section );
	var sectionNumber = section.outerHTML.match( /section="(\d+)"/ )[1];
	var pageTitle = mw.config.get( 'wgPageName' );
	console.log( sectionNumber );
	new mw.Api().get( {
		action: 'parse',
		page: pageTitle,
		prop: 'wikitext',
		section: sectionNumber
	}).done( function( result ) {
		console.log( result );
		var wikitext = result.parse.wikitext['*'];
		wikitext = wikitext + '\n{{section resolved|1=~~~~}}';
		console.log( wikitext );
		new mw.Api().postWithEditToken( {
			action: 'edit',
			title: pageTitle,
			section: sectionNumber,
			text: wikitext,
			summary: EasyResolve.summary,
			notminor: true,
			nocreate: true
		}).done( function( result ) {
			console.log( result );
			if ( result && result.edit && result.edit.result && result.edit.result === 'Success' ){
				location.reload();
			}
		});
	});
};
EasyResolve.extraPages = [
	"Test Wiki:Community portal",
	"Test Wiki:Request for permissions",
	"User talk:",
];
mw.loader.using( 'mediawiki.api', function() {
	$(document).ready( function () {
		if ( mw.config.get( 'wgAction' ) !== 'view' ) {
			return;
		}
		// General criteria: you can add a section and its a talk page or in
		// the project namespace
		if ( $('#ca-addsection').length > 0 &&
			( mw.config.get('wgNamespaceNumber') % 2 === 1 ||
			mw.config.get('wgNamespaceNumber') === 4 ) 
		) {
			EasyResolve.setup();
			return;
		}
		// Custom criteria: specified in EasyResolve.extraPages or user has
		// an override
		const pageName = mw.config.get( 'wgPageName' );
		if ( EasyResolve.extraPages.includes( pageName )
			|| ( window.EasyResolveCustomPages &&
					window.EasyResolveCustomPages.includes( pageName ) )
		) {
			EasyResolve.setup();
		}
	});
} );
//</nowiki>