Jump to content

User:Gryllida/js/ajaxSectionUpdateOnDoubleClick.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
Author : Svetlana Tkachenko svetlana@members.fsf.org
This file is a part of ajaxSectionUpdateOnDoubleClick.
Licence: GPLv3+
Version: 0.1
Release date: 2018-02-26
Description: updates a section when double-clicked (useful on talk pages sometimes)
*/ 

$('.mw-headline').each(function(i){
	var $self = $(this);
	//alert(i);
    //alert($self.text());
    var $anchor = $self.parent();
    $anchor.nextUntil( "h2" ).dblclick(function(){
    	console.log('hi');
    	var api = new mw.Api();
		api.get( { // Corresponds to "api.php?action=parse&page=test"
    		action: 'parse',
    		page: mw.config.get( 'wgPageName' ),
    		section: i+1
		} ).done(function(data){
			var html = data.parse.text['*'];
			//$(this).replacewith($('<p>j</p>'));
    		$anchor.nextUntil( "h2" ).remove();
    		$anchor.replaceWith($(html));
		})
    });
});