User:Softly falling rain/common.js

// var llinks = document.querySelectorAll("a[href^='/wiki/']");

var $test = $(" This is a table of links  "); $( "#bodyContent" ).prepend($test);

for (var i=0; i < llinks.length; i++) { //console.log var s = String( llinks[i].getAttribute('href') ); if (! s.includes( ':' ) ) { var t =s.replace('/wiki/','/wiki/Talk:' ) //var $test = $(" " + s +  "  " + t + "  "); //$( "#aptable" ).append($test); } }

var accumulateWikiprojects = { };

function reqListener { try { console.log(this.readyState); console.log(this.status); var xmlDoc = this.responseXML; var pageName = "Rome";

if (null == xmlDoc ) { xmlDoc = new DOMParser.parseFromString (this.responseText, "text/xml"); }      var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);

if (null == nsResolver ) { alert( 'nsResolve = ' + nsResolver + "" ); }      var nameIterator = xmlDoc.evaluate("//*[@id='firstHeading']/text", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null ); pageName = nameIterator.iterateNext.nodeValue.replace(/Talk:/,''); var projectIterator = xmlDoc.evaluate("//*[contains(@href,'wiki/Wikipedia:WikiProject_')]", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null ); var thisNode = projectIterator.iterateNext; var wikiprojects = { } ; while (thisNode) { console.log(thisNode) var wikiproject = thisNode.getAttribute('href').replace(/^\/wiki\//,).replace(/\/.*$/, ).replace(/#.*$/, ''); console.log(wikiproject); wikiprojects[wikiproject] = 1; thisNode = projectIterator.iterateNext; }      accumulateWikiprojects[pageName] =  wikiprojects; var second = { } ; Object.keys(accumulateWikiprojects).forEach(function (k) {        console.log(k, accumulateWikiprojects[k]);         var wikiproject = accumulateWikiprojects[k];         //var sHTML = "  " + pageName + " " ;		var strl = "";

Object.keys(wikiproject).forEach(function (k) {       	console.log(k, wikiproject[k]);        	strl = strl + " " + k			var template = k.replace(/Wikipedia:WikiProject_(\w+)/, "Template:WikiProject_$1")            var sHTML = "  " + k + "    " ;            $( "#aptable" ).append(sHTML);    	 }); //var sHTML = " " + pageName + "  " + strl + "  " ; // $( "#aptable" ).append(sHTML); });      //var $test = $("  " + pageName +  "  " + "XXX" + "  ");       //$( "#aptable" ).append($test);

} catch (e) { alert( 'Error: ' + e ); console.log(e) } }

function reqError{ console.log("error" + this) } function getWikiProjects (pagename) { var req = new XMLHttpRequest; req.open("GET", "https://en.wikipedia.org/wiki/Talk:" + pagename); req.overrideMimeType('text/xml'); req.addEventListener("error", reqError); req.addEventListener("loadend", reqListener); req.send(null); }

//var pageName= $( "#mw-first-heading" ).textContent; //console.log(pageName)

//document.addEventListener("load", getWikiProjects("Rome")); //