User:Gryllida/js/archive-talk.js

$('.mw-headline').each(function( index ) { // console.log( index + ": " + $( this ).text );  var txt = $( this ).text;  if(mw.config.get( 'wgPageName' ) != 'User_talk:' + mw.config.get( 'wgUserName' )){  	return;  }  //if(txt.indexOf('Wikinews recent additions') == -1){  //	return true;  //}  var $self = $( this );  // dom  var $span = $(' ');  $span.text(' Archive');  $span.attr('style', 'color: blue');  $span_y = $(" Yes ");  $span_n = $(" No ");  var $span2 = $(" Are you sure? ");  $span2.append($span_y );  $span2.append($(' / ') );  $span2.append($span_n );

// event $span.click(function {   $span2.show;    $(this).hide;  }); $span_n.click(function {   $span2.hide;    $span.show;  }); // // delete the section with number 'index - 1' via api $span_y.click(function {   	var api = new mw.Api;  	// get section contents  	// https://en.wikipedia.org/w/api.php?action=parse&page=New_York&format=json&prop=wikitext&section=1&format=json  	api.get( { action: 'parse', page: mw.config.get( 'wgPageName' ), prop: 'wikitext', section: index+1 } ).done( function ( data ) { text = data.parse.wikitext['*']; text = '\r\n' + text; // add section contents to '/Archive' page mytitle = mw.config.get ('wgPageName') + '/Archive'; api.postWithToken("edit", {				action: 'edit',				title: mytitle,				summary: 'archiving section (assisted)',				appendtext: text			}); }); 	// blank the section  	api.postWithToken("edit", { action: 'edit', title: mw.config.get ('wgPageName'), section: index+1, summary: 'archiving section (assisted)', text: '' }); 	// update the view  	var $anchor = $self.parent;  	$anchor.nextUntil( "h2" ).remove;  	$anchor.remove;  	$('.archive-talk').remove;  	// importScript('User:Gryllida/js/archive-talk.js'); // does not work in global.js  	mw.loader.load( 'https://en.wikinews.org/w/index.php?title=User:Gryllida/js/archive-talk.js&action=raw&ctype=text/javascript' ); // n:User:Gryllida/js/archive-talk.js  }); // add to h $span.insertAfter($(this)); $span2.insertAfter($(this)); $span2.hide; });