User:Bharaththiruveedula/common.js

// importScript('User:Sivabalan.t/wikiCodeEditor/code-editor.js'); $(function{   var title = mw.config.get('wgTitle');    var content  = "";    $(' ', { id: 'categories', text: 'Categories' }).appendTo('#bodyContent');

$(' ',{       id : 'add',        text : '(+)'    }).css({'text-decoration':'none','cursor':'pointer'}).appendTo('#categories');

$(' ',{       type : 'text',        placeholder : 'Enter the categories',        id : 'catentry'    }).css('display','none').appendTo('#categories'); $('#add').click(function{       $('#catentry').css('display','inline');        $('#catsave').css('display','inline');        $('#add').css('display','none');    }); $(' ',{       text : 'save',        id : 'catsave'    }).css('display','none').appendTo('#categories');

$.get('http://en.wikipedia.org//w/api.php?action=parse&format=json&page='+title+'&prop=categories',function(data){   if(typeof data.parse.categories === 'undefined'){    }    else{        $.each(data.parse.categories,function(index,value){ addEntry(value['*']); content = content + " \n"; });   }    mw.loader.using('jquery.ui',function{ $('#catentry').autocomplete({           source : function( request, response){                $.ajax({ url : "http://en.wikipedia.org/w/api.php", dataType : "jsonp", data : { action : "query", list : "allcategories", format : "json", aclimit : 20, acfrom : request.term },                   success : function(data){ response($.map(data.query.allcategories, function(item){ return item['*']; }));                   }                                });            }        });    });    $('#catsave').click(function{ var text = $('#catentry').val.trim.split(","); $.each(text,function(index,value){           content  = content + " \n";            addEntry(value);            $.get('http://en.wikipedia.org/w/api.php?action=parse&format=json&page='+title+'&prop=wikitext',function(data){ var wikitext = data.parse.wikitext['*']; console.log(wikitext); console.log(wikitext.replace(/\[\[Category([\s\S])*\]\][\n]/,content+"\n\r")); });       });

});   $(' ',{        class:'img', html:'&times;' }).appendTo('.entry');

$('.img').css('cursor','pointer'); $('.img').click(function{       var categoryName = $(this).parent.text.replace(/[^\x00-\x80]/,'');;        console.log(categoryName);        $(this).parent.fadeOut;        $.get('http://en.wikipedia.org/w/api.php?action=parse&format=json&page='+title+'&prop=wikitext',function(data){ var wikitext = data.parse.wikitext['*']; //console.log(content); var regex = new RegExp("\[\[Category.*("+categoryName+".*\]\])$"); console.log(wikitext.replace(regex,"")); });   });    function addEntry(category){ $(' ',{                 text : category,            class : 'entry'        }).appendTo('#categories'); }; }); }); //