User:R160K/Uzanto Universala/script.js

//###STILL TO BE DONE: //–Read cefserva from page //-Read uzanto and pagspeco from page //-Read requestingWiki from url //-Scrape styles from original userpage // //###

//USERPAGE FUNCTIONS function displayUserpage {	//Ĉefserva Paĝo, Uzanto and Paĝspeco (###Eventually these data should be read from something, perhaps a template, on the userpage itself###) //This link points to the service the user's main account is on	cefserva = "en.wiktionary.org"; //###perhaps change the name of this variable to make it clearer that it is just ĉefservo### uzanto = "R160K"; pagspeco = "User"; packetNo = 1; //This project: requestingWiki = "en.wikipedia.org"; if (cefserva == requestingWiki) {return false}; //build string and make IFRAME cefservaPago = "https://" + cefserva + "/wiki/User:R160K/Uzanto_Universala/Ĉefserva_Paĝo#uzanto=" + escape(uzanto) + "&pagspeco=" + escape(pagspeco) + "&requestingwiki=" + escape(requestingWiki) + "&packetno=" + packetNo; document.getElementById("bodyContent").innerHTML = ' Loading... \	'; //make string-building variables static and shared //###eventually there should be a shared string-building, returning function for building the ĉefserva paĝo### displayUserpage.cefserva = cefserva; displayUserpage.uzanto = uzanto; displayUserpage.pagspeco = pagspeco; displayUserpage.requestingWiki = requestingWiki; } //function to receive data packets from relay frame function receivePacket(packetNo, numPackets, packet) {	//add the received packet to the function's shared data variable receivePacket.data += unescape(packet); //update the status on the userpage document.getElementById('loadStatus').innerText = "Packets loaded: " + packetNo + " of " + numPackets; //check if this is the last packet if (packetNo == numPackets) {		//this is the last packet //display data on the page document.getElementById("bodyContent").innerHTML = receivePacket.data; }	else {		//this is not the last //increment the packet number packetNo = 1 + packetNo * 1; //change the hash of the ĉefserva paĝo //build string cefservaPago = "https://" + displayUserpage.cefserva + "/wiki/User:R160K/Uzanto_Universala/Ĉefserva_Paĝo#uzanto=" + escape(displayUserpage.uzanto) + "&pagspeco=" + escape(displayUserpage.pagspeco) + "&requestingwiki=" + escape(displayUserpage.requestingWiki) + "&packetno=" + packetNo; //fire string var theFrame = document.getElementById("cefservaFramo"); //		theFrame.src = cefservaPago; } } //ĈEFSERVA PAĜO FUNCTIONS //function to be run on the Ĉefserva Paĝo function runCefservaPago {	//this wiki ###eventually this needs to be read from the page, perhaps### currentService = "en.wikipedia.org"; //extract variables from url //###come back later and do this using # instead of ? – should allow pages to load from the cache and result in quicker loading.### partToScan = location.hash; uzanto = partToScan.split("uzanto=")[1].split("&")[0]; uzanto = unescape(uzanto); pagspeco = partToScan.split("pagspeco=")[1].split("&")[0]; pagspeco = unescape(pagspeco); requestingWiki = partToScan.split("requestingwiki=")[1].split("&")[0]; requestingWiki = unescape(requestingWiki); packetNo = partToScan.split("packetno=")[1].split("&")[0]; packetNo = packetNo * 1; //Scraper URL to load scraperUrlToLoad = "https://" + currentService + "/wiki/" + pagspeco + ":" + uzanto; //load the userpage content of the cefservaPago //document.getElementById("bodyContent").innerHTML = "Test"; var quots = '"';	document.getElementById("bodyContent").innerHTML = " \  "; } //function to scrape the user or user_talk page data from the frame function relayInfo(requestingWiki, packetNo) {	//extract and escape body content	sourceWin = document.getElementById("scraperFrame").contentWindow;	sourceDoc = sourceWin.document.getElementById("bodyContent").innerHTML;	sourceDoc = escape(sourceDoc);	//maximum packet size is 1975 bytes	maxPacketSize = 1975;	//calculate number of packets required	numPackets = Math.ceil(sourceDoc.length / maxPacketSize);	//calculate start position for current packet	packetStart = maxPacketSize * (packetNo - 1);	//get packet	packet = sourceDoc.substr(packetStart, maxPacketSize);	//Build URL:	//relay URL to load	relayUrlToLoad = "https://" + requestingWiki + "/wiki/User:R160K/Uzanto_Universala/Loca_Framo#packetNo="	+ packetNo +"&numPackets=" + numPackets + "&data=" + packet;	//load url (or change hash) document.getElementById("relayFrame").contentWindow.location = relayUrlToLoad; } //function to request a new packet when the hash is changed function nextPacket(evt) {	partToScan = location.hash; requestingWiki = partToScan.split("requestingwiki=")[1].split("&")[0]; requestingWiki = unescape(requestingWiki); packetNo = partToScan.split("packetno=")[1].split("&")[0]; packetNo = packetNo * 1; relayInfo(requestingWiki, packetNo) } //LOCA FRAMO FUNCTIONS function runLocaFramo(evt) {	topFrame = window.parent.parent; //extract values from URL partToScan = location.hash; packetNo = partToScan.split("packetNo=")[1].split("&")[0]; numPackets = partToScan.split("numPackets=")[1].split("&")[0]; data = partToScan.split("data=")[1].split("&")[0]; //	packetNo = packetNo * 1; numPackets = numPackets * 1; //send packets to grandparent window grandParent = window.parent.parent; grandParent.receivePacket(packetNo,numPackets,data); } //BASE SCRIPT //This is the basic script that is run when any page loads //Create a string from URI-typed location var pageURL = window.location + ""; //Check if page loaded is a userpage if (pageURL.lastIndexOf("User:R160K") == pageURL.length - "User:R160K".length) {	//It is a userpage //initialise shared packet receiver variable receivePacket.data = ""; //begin the process of displaying the other-wiki userpage displayUserpage; } else {	//Check if page loaded is a Ĉefserva Paĝo if (pageURL.lastIndexOf("User:R160K/Uzanto_Universala/Ĉefserva_Paĝo") >= 0 || pageURL.lastIndexOf("Uzanto_Universala/%C4%88efserva_Pa%C4%9Do") >= 0) {		//add handler for hashchange event window.onhashchange = nextPacket; //initialise the Ĉefserva Paĝo. runCefservaPago; }	else {			//Check if page loaded is a Ĉefserva Paĝo if (pageURL.lastIndexOf("User:R160K/Uzanto_Universala/Loca_Framo") >= 0) {				window.onhashchange = runLocaFramo; runLocaFramo(null); }			else {			}	} }