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>
|
<body>
|
||||||
<h1>Evopedia</h1>
|
<h1>Evopedia</h1>
|
||||||
<div id="openLocalFiles" style="display: none;">
|
<div id="openLocalFiles" style="display: none;">
|
||||||
<br />
|
<br /> Please select the file titles.idx :<br /> <input type="file"
|
||||||
Please select the file titles.idx :<br /> <input type="file"
|
id="titleFile" /><br /> Please select the files wikipedia_*.dat
|
||||||
id="titleFile" /><br /> Please select the files wikipedia_*.dat from
|
from the same dump :<br /> <input type="file" id="dataFiles" multiple />
|
||||||
the same dump :<br /> <input type="file" id="dataFiles" multiple />
|
|
||||||
</div>
|
</div>
|
||||||
<br /> Find titles from the prefix :
|
<br /> Find titles from the prefix :
|
||||||
<input type="text" id="prefix" value="" onkeyup="onKeyUpPrefix(event)" />
|
<input type="text" id="prefix" value="" onkeyup="onKeyUpPrefix(event)" />
|
||||||
@ -50,40 +49,43 @@ License:
|
|||||||
<br /> Choose a title from the filtered list :
|
<br /> Choose a title from the filtered list :
|
||||||
<select id="titleList" onchange="updateOffsetsFromTitle(this.value)"></select>
|
<select id="titleList" onchange="updateOffsetsFromTitle(this.value)"></select>
|
||||||
<br />
|
<br />
|
||||||
<table>
|
<input type="button" id="toggleDebug" value="Switch debug on/off"
|
||||||
<tr>
|
onclick="switchDebugOnOff()" />
|
||||||
<th> </th>
|
|
||||||
<th>Original offsets</th>
|
|
||||||
<th>Redirect offsets</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>File number</td>
|
|
||||||
<td><input type="text" id="filenumber" value="" /></td>
|
|
||||||
<td><input type="text" id="redirectfilenumber" value="" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Blockstart</td>
|
|
||||||
<td><input type="text" id="blockstart" value="" /></td>
|
|
||||||
<td><input type="text" id="redirectblockstart" value="" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Blockoffset</td>
|
|
||||||
<td><input type="text" id="blockoffset" value="" /></td>
|
|
||||||
<td><input type="text" id="redirectblockoffset" value="" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Length</td>
|
|
||||||
<td><input type="text" id="length" value="" /></td>
|
|
||||||
<td><input type="text" id="redirectlength" value="" /></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<input type="button" id="readData" value="Read article from dump"
|
<input type="button" id="readData" value="Read article from dump"
|
||||||
onclick="readArticleFromHtmlForm(dataFiles)" />
|
onclick="readArticleFromHtmlForm(dataFiles)" />
|
||||||
<br />
|
<div id="debugZone" style="display: none;">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<th>Original offsets</th>
|
||||||
|
<th>Redirect offsets</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>File number</td>
|
||||||
|
<td><input type="text" id="filenumber" value="" /></td>
|
||||||
|
<td><input type="text" id="redirectfilenumber" value="" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Blockstart</td>
|
||||||
|
<td><input type="text" id="blockstart" value="" /></td>
|
||||||
|
<td><input type="text" id="redirectblockstart" value="" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Blockoffset</td>
|
||||||
|
<td><input type="text" id="blockoffset" value="" /></td>
|
||||||
|
<td><input type="text" id="redirectblockoffset" value="" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Length</td>
|
||||||
|
<td><input type="text" id="length" value="" /></td>
|
||||||
|
<td><input type="text" id="redirectlength" value="" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<textarea id="debugTextarea" cols="80" rows="10"> </textarea>
|
||||||
|
</div>
|
||||||
<!-- TODO : add CSS styles -->
|
<!-- TODO : add CSS styles -->
|
||||||
<div id="articleContent"> </div>
|
<div id="articleContent"> </div>
|
||||||
<hr />
|
<hr />
|
||||||
<textarea id="debugZone" cols="80" rows="20"> </textarea>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="evopedia.js"></script>
|
<script type="text/javascript" src="evopedia.js"></script>
|
||||||
</body>
|
</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
|
* Set the Offsets HTML fields from the selected title
|
||||||
*/
|
*/
|
||||||
@ -126,7 +152,7 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
|
|||||||
newLineIndex++;
|
newLineIndex++;
|
||||||
}
|
}
|
||||||
var title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
var title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
||||||
//alert("title found : "+title);
|
debug("title found : "+title);
|
||||||
if (title.localeCompare(prefix)<0) {
|
if (title.localeCompare(prefix)<0) {
|
||||||
lo = mid;
|
lo = mid;
|
||||||
}
|
}
|
||||||
@ -135,13 +161,13 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
|
|||||||
}
|
}
|
||||||
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
|
// Read the file as a binary string
|
||||||
reader.readAsArrayBuffer(blob);
|
reader.readAsArrayBuffer(blob);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We found the closest title
|
// 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);
|
readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,lo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,6 +272,7 @@ function readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,startInde
|
|||||||
title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
|
||||||
// Skip the first title
|
// Skip the first title
|
||||||
if (titleNumber>=0 && 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
|
// TODO : check if the title starts with prefix, and return if it does not
|
||||||
comboTitleList.options[titleNumber] = new Option (title, filenumber+"|"+blockstart+"|"+blockoffset+"|"+length);
|
comboTitleList.options[titleNumber] = new Option (title, filenumber+"|"+blockstart+"|"+blockoffset+"|"+length);
|
||||||
}
|
}
|
||||||
@ -335,8 +362,6 @@ function readArticleFromOffset(dataFile, blockstart, blockoffset, length) {
|
|||||||
htmlArticle = decodeURIComponent(escape(htmlArticle));
|
htmlArticle = decodeURIComponent(escape(htmlArticle));
|
||||||
|
|
||||||
document.getElementById('articleContent').innerHTML = 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,
|
// 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