2021-10-31 15:44:04 +00:00
|
|
|
<head>
|
2021-11-17 07:53:59 +00:00
|
|
|
<base>
|
2021-11-06 11:30:23 +00:00
|
|
|
<script src="https://cdn.jsdelivr.net/npm/marked@3.0.7/marked.min.js"></script>
|
2021-10-31 15:44:04 +00:00
|
|
|
<script>
|
|
|
|
function absFile(url) {
|
|
|
|
this.name=url;
|
|
|
|
this.slice = async(offset, length) =>{
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.append('range', 'bytes=' + offset + '-' + ( offset + length -1).toString());
|
|
|
|
|
|
|
|
const opts = {
|
|
|
|
credentials: 'include',
|
|
|
|
headers : headers
|
|
|
|
};
|
|
|
|
|
|
|
|
const resp = await fetch( this.name, opts );
|
|
|
|
return await resp.arrayBuffer();
|
|
|
|
//alert(JSON.stringify(resp.headers));
|
|
|
|
//return await resp.text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var file;
|
2021-11-12 07:24:33 +00:00
|
|
|
var blocksize = 1024;
|
2021-10-31 15:44:04 +00:00
|
|
|
function loadSlice(){
|
2021-11-15 08:58:53 +00:00
|
|
|
function render(u8array){
|
|
|
|
document.body.innerHTML = marked(new TextDecoder().decode(u8array));
|
2021-11-17 07:53:59 +00:00
|
|
|
scroll(0,0);
|
2021-11-15 08:58:53 +00:00
|
|
|
}
|
|
|
|
function setPageUrl(pageurl){
|
|
|
|
let a = document.createElement('a');
|
|
|
|
a.href = "i:5c"+pageurl;
|
|
|
|
a.click();
|
|
|
|
}
|
|
|
|
|
2021-11-08 07:41:41 +00:00
|
|
|
var page = 1;
|
2021-11-12 07:24:33 +00:00
|
|
|
var extrasize = blocksize; //extrasize should <= blocksize
|
2021-10-31 15:44:04 +00:00
|
|
|
let lhash = location.hash;
|
2021-11-12 07:24:33 +00:00
|
|
|
if(lhash){
|
|
|
|
if("p"!==lhash.charAt(1)){//#offset=&[len]
|
|
|
|
let iAmpersand = lhash.indexOf('&',8);
|
|
|
|
let offset = parseInt(lhash.substring(8,iAmpersand));
|
|
|
|
let len = parseInt(lhash.substring(iAmpersand+1));
|
|
|
|
{//update urlInc() url
|
|
|
|
let href = location.href;
|
|
|
|
let iHash = href.indexOf('#');
|
2021-11-15 08:58:53 +00:00
|
|
|
href=href.substring(0,iHash)+"#page="+Math.floor((offset+len)/blocksize);
|
|
|
|
setPageUrl(href);
|
2021-11-12 07:24:33 +00:00
|
|
|
}
|
|
|
|
file.slice(offset,len).then((buffer)=>{
|
|
|
|
let u8 = new Uint8Array(buffer);
|
|
|
|
render(u8);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//#page=
|
|
|
|
page = parseInt(lhash.substring(6));
|
2021-11-15 08:58:53 +00:00
|
|
|
}else
|
|
|
|
setPageUrl(location.href+"#page=1");
|
2021-10-31 15:44:04 +00:00
|
|
|
file.slice(blocksize*(page-1),blocksize+extrasize).then((buffer)=>{
|
|
|
|
let u8 = new Uint8Array(buffer);
|
2021-11-12 07:24:33 +00:00
|
|
|
let u8len = u8.length;
|
2021-10-31 15:44:04 +00:00
|
|
|
let iStart = 0;
|
2021-11-12 07:24:33 +00:00
|
|
|
let limit = Math.min(u8len,extrasize);
|
2021-10-31 15:44:04 +00:00
|
|
|
if(1!=page){
|
2021-11-12 07:24:33 +00:00
|
|
|
for(let i=1;i<limit;i=i+2){
|
2021-11-06 11:30:23 +00:00
|
|
|
if(10==u8[i] && 10==u8[i-1]) {
|
|
|
|
iStart = i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-12 07:24:33 +00:00
|
|
|
let iEnd = Math.min(u8len,blocksize);
|
|
|
|
limit = Math.min(u8len,blocksize+extrasize);
|
|
|
|
for(let i=blocksize+1;i<limit;i=i+2){
|
2021-11-06 11:30:23 +00:00
|
|
|
if(10==u8[i] && 10==u8[i-1]) {
|
|
|
|
iEnd = i+1;
|
|
|
|
break;
|
|
|
|
}
|
2021-10-31 15:44:04 +00:00
|
|
|
}
|
2021-11-12 07:24:33 +00:00
|
|
|
render(u8.slice(iStart,iEnd));
|
2021-10-31 15:44:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2021-11-12 07:24:33 +00:00
|
|
|
//?url=#offset=&[len]&page=
|
2021-11-17 07:53:59 +00:00
|
|
|
{
|
|
|
|
let url = location.search.substring(5);
|
|
|
|
file = new absFile(url);
|
|
|
|
document.getElementsByTagName('base')[0].href=url;
|
|
|
|
}
|
2021-11-12 07:24:33 +00:00
|
|
|
window.addEventListener('hashchange',loadSlice);
|
2021-10-31 15:44:04 +00:00
|
|
|
</script>
|
2021-11-08 07:41:41 +00:00
|
|
|
</head>
|
2021-10-31 15:44:04 +00:00
|
|
|
<body>
|
2021-11-12 07:24:33 +00:00
|
|
|
<script>loadSlice();</script>
|
2021-11-08 07:41:41 +00:00
|
|
|
</body>
|