mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
Add debug information inside the HTML page, with a button to switch it
on/off
This commit is contained in:
parent
4425806fe0
commit
1383f74640
@ -38,10 +38,9 @@ License:
|
||||
<body>
|
||||
<h1>Evopedia</h1>
|
||||
<div id="openLocalFiles" style="display: none;">
|
||||
<br />
|
||||
Please select the file titles.idx :<br /> <input type="file"
|
||||
id="titleFile" /><br /> Please select the files wikipedia_*.dat from
|
||||
the same dump :<br /> <input type="file" id="dataFiles" multiple />
|
||||
<br /> Please select the file titles.idx :<br /> <input type="file"
|
||||
id="titleFile" /><br /> Please select the files wikipedia_*.dat
|
||||
from the same dump :<br /> <input type="file" id="dataFiles" multiple />
|
||||
</div>
|
||||
<br /> Find titles from the prefix :
|
||||
<input type="text" id="prefix" value="" onkeyup="onKeyUpPrefix(event)" />
|
||||
@ -50,6 +49,11 @@ License:
|
||||
<br /> Choose a title from the filtered list :
|
||||
<select id="titleList" onchange="updateOffsetsFromTitle(this.value)"></select>
|
||||
<br />
|
||||
<input type="button" id="toggleDebug" value="Switch debug on/off"
|
||||
onclick="switchDebugOnOff()" />
|
||||
<input type="button" id="readData" value="Read article from dump"
|
||||
onclick="readArticleFromHtmlForm(dataFiles)" />
|
||||
<div id="debugZone" style="display: none;">
|
||||
<table>
|
||||
<tr>
|
||||
<th> </th>
|
||||
@ -77,13 +81,11 @@ License:
|
||||
<td><input type="text" id="redirectlength" value="" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="button" id="readData" value="Read article from dump"
|
||||
onclick="readArticleFromHtmlForm(dataFiles)" />
|
||||
<br />
|
||||
<textarea id="debugTextarea" cols="80" rows="10"> </textarea>
|
||||
</div>
|
||||
<!-- TODO : add CSS styles -->
|
||||
<div id="articleContent"> </div>
|
||||
<hr />
|
||||
<textarea id="debugZone" cols="80" rows="20"> </textarea>
|
||||
|
||||
<script type="text/javascript" src="evopedia.js"></script>
|
||||
</body>
|
||||
|
@ -49,6 +49,32 @@ else {
|
||||
};
|
||||
}
|
||||
|
||||
var debugOn = false;
|
||||
|
||||
/**
|
||||
* Print the given string inside the debug zone
|
||||
* @param string
|
||||
*/
|
||||
function debug(string) {
|
||||
if (debugOn) {
|
||||
document.getElementById("debugTextarea").value+=string+"\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch debug mode On/Off
|
||||
*/
|
||||
function switchDebugOnOff() {
|
||||
if (debugOn == true) {
|
||||
debugOn = false;
|
||||
document.getElementById("debugZone").style.display="none";
|
||||
}
|
||||
else {
|
||||
debugOn = true;
|
||||
document.getElementById("debugZone").style.display="block";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Offsets HTML fields from the selected title
|
||||
*/
|
||||
@ -126,7 +152,7 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
|
||||
newLineIndex++;
|
||||
}
|
||||
var title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
||||
//alert("title found : "+title);
|
||||
debug("title found : "+title);
|
||||
if (title.localeCompare(prefix)<0) {
|
||||
lo = mid;
|
||||
}
|
||||
@ -135,13 +161,13 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
|
||||
}
|
||||
recursivePrefixSearch(titleFile, reader, prefix, lo, hi);
|
||||
};
|
||||
//alert("Reading the file from "+mid+" to "+(mid+256)+" because lo="+lo+" and hi="+hi);
|
||||
debug("Reading the file from "+mid+" to "+(mid+256)+" because lo="+lo+" and hi="+hi);
|
||||
// Read the file as a binary string
|
||||
reader.readAsArrayBuffer(blob);
|
||||
}
|
||||
else {
|
||||
// We found the closest title
|
||||
//alert ("Found the closest title near index "+lo);
|
||||
debug ("Found the closest title near index "+lo);
|
||||
readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,lo);
|
||||
}
|
||||
}
|
||||
@ -246,6 +272,7 @@ function readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,startInde
|
||||
title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
||||
// Skip the first title
|
||||
if (titleNumber>=0 && title) {
|
||||
debug("Found title : escape1="+escape1+" escape2="+escape2+" filenumber="+filenumber+" blockstart="+blockstart+" blockoffset="+blockoffset+" length="+length+" title="+title);
|
||||
// TODO : check if the title starts with prefix, and return if it does not
|
||||
comboTitleList.options[titleNumber] = new Option (title, filenumber+"|"+blockstart+"|"+blockoffset+"|"+length);
|
||||
}
|
||||
@ -335,8 +362,6 @@ function readArticleFromOffset(dataFile, blockstart, blockoffset, length) {
|
||||
htmlArticle = decodeURIComponent(escape(htmlArticle));
|
||||
|
||||
document.getElementById('articleContent').innerHTML = htmlArticle;
|
||||
// For testing purpose
|
||||
//document.getElementById('debugZone').value = htmlArticle;
|
||||
};
|
||||
|
||||
// TODO : should be improved by reading the file chunks by chunks until the article is found,
|
||||
|
Loading…
x
Reference in New Issue
Block a user