User:Yeskarthik/MadamHut.js

(function {   // Only on mainspace articles    if(mw.config.get('wgNamespaceNumber') != 0) {        return;    }    var requires = [        'jquery.ui.button',        'mediawiki.api'    ];    var cssPath = '//en.wikipedia.org/w/index.php?title=User:Yuvipanda/MadamHut.css&action=raw&ctype=text/css';    var projectData = {        name: 'WikiProject India',        templates: ['WP India', 'WikiProject India'],        subProjects: [                'andaman',                'andhra',                'arunachal',                'assam',                'bihar',                'chandigarh',                'chhattisgarh',                'dadra',                'daman',                'delhi',                'goa',                'gujarat',                'haryana',                'himachal',                'jandk',                'jharkhand',                'karnataka',                'kerala',                'lakshya', 'madhya', 'maharashtra', 'manipur', 'meghalaya', 'mizoram', 'nagaland', 'odisha', 'puducherry', 'punjab', 'rajasthan', 'sikkim', 'tamilnadu', 'tripura', 'uttar', 'uttarakand', 'bengal', 'mumbai', 'mangalore', 'chennai', 'hyderabad', 'geography', 'states', 'districts', 'cities', 'maps', 'history', 'literature', 'politics', 'language', 'cinema', 'music', 'television', 'education', 'history', 'tamil' ],       actionNeeded: [ 'orphan', 'needs-infobox', 'map-needed', 'image-needed', 'attention' ]   };    var extractorRegex =  new RegExp(""); function Assessment(project, data) { this.project = project; this.data = data; this.subProjects = {} var that = this; $.each(this.data, function(key, value) {           if($.inArray(key, projectData.subProjects) != -1) {                that.subProjects[key] = "";                return;            }            if($.inArray(key.replace(/-importance$/, ), projectData.subProjects) != -1) {                that.subProjects[key.replace(/-importance$/, )] = value;                return            }        }); }   Assessment.fromWikiText = function(text) { var match = text.match(extractorRegex); var cleanTemplate = match[0].replace(/{|}|\n/g, ''); var parts = cleanTemplate.split('|'); var tags = {}; for(var i = 1; i < parts.length; i++) { console.log(parts[i]); var tag = parts[i].split('='); tags[$.trim(tag[0])] = $.trim(tag[1]); }       return new Assessment(parts[0], tags); }   mw.loader.load(cssPath, 'text/css'); mw.loader.using(requires, function {       $(function { $(" Overall:  unknown importance |  unknown classNext Article &raquo;  SubProjects:  Flags:    ").appendTo("body"); var api = new mw.Api; api.get({               action: "parse",                page: 'Talk:' +  mw.config.get('wgPageName'),                prop: 'wikitext'            }, {                ok: function(data) {                    var assessment = Assessment.fromWikiText(data.parse.wikitext['*']);                    a = assessment;                    $("#madamhut-importance").html(assessment.data.importance || "Unknown");                    $("#madamhut-class").html(assessment.data.class || "Unknown");                    var subProjectItems = $.map(assessment.subProjects, function(importance, subProject) { return "" + subProject + (importance ? " (" + importance + ")" : " (UA)") + ""; });                   $("#madamhut-subprojects-list").append(subProjectItems.join(' | '));                    $.each(projectData.actionNeeded, function(i, key) { var isChecked = (assessment.data[key] === 'yes'); var html = "" + key + " "; $(html).appendTo("#madamhut-action-needed"); });                   console.log(data);                }            }); });   }); });