markdeep.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <head>
  2. <script>window.markdeepOptions = {mode: 'script'};</script>
  3. <script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js"></script>
  4. <script id="MathJax-script" async src="https://fastly.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
  5. <script>
  6. function absFile(url) {
  7. this.name=url;
  8. this.slice = async(offset, length) =>{
  9. const headers = new Headers();
  10. headers.append('range', 'bytes=' + offset + '-' + ( offset + length -1).toString());
  11. const opts = {
  12. credentials: 'include',
  13. headers : headers
  14. };
  15. const resp = await fetch( this.name, opts );
  16. return await resp.arrayBuffer();
  17. //alert(JSON.stringify(resp.headers));
  18. //return await resp.text();
  19. }
  20. }
  21. var file;
  22. var blocksize = 1024;
  23. function loadSlice(){
  24. function render(u8array){
  25. document.body.innerHTML = window.markdeep.format(new TextDecoder().decode(u8array),true);
  26. MathJax.typesetPromise();
  27. }
  28. function setPageUrl(pageurl){
  29. let a = document.createElement('a');
  30. a.href = "i:5c"+pageurl;
  31. a.click();
  32. }
  33. var url;
  34. var page = 1;
  35. var extrasize = blocksize; //extrasize should <= blocksize
  36. let lhash = location.hash;
  37. if(lhash){
  38. if("p"!==lhash.charAt(1)){//#offset=&[len]
  39. let iAmpersand = lhash.indexOf('&',8);
  40. let offset = parseInt(lhash.substring(8,iAmpersand));
  41. let len = parseInt(lhash.substring(iAmpersand+1));
  42. {//update urlInc() url
  43. let href = location.href;
  44. let iHash = href.indexOf('#');
  45. href=href.substring(0,iHash)+"#page="+Math.floor((offset+len)/blocksize);
  46. setPageUrl(href);
  47. }
  48. file.slice(offset,len).then((buffer)=>{
  49. let u8 = new Uint8Array(buffer);
  50. render(u8);
  51. });
  52. return;
  53. }
  54. //#page=
  55. page = parseInt(lhash.substring(6));
  56. }else
  57. setPageUrl(location.href+"#page=1");
  58. file.slice(blocksize*(page-1),blocksize+extrasize).then((buffer)=>{
  59. let u8 = new Uint8Array(buffer);
  60. let u8len = u8.length;
  61. let iStart = 0;
  62. let limit = Math.min(u8len,extrasize);
  63. if(1!=page){
  64. for(let i=1;i<limit;i=i+2){
  65. if(10==u8[i] && 10==u8[i-1]) {
  66. iStart = i+1;
  67. break;
  68. }
  69. }
  70. }
  71. let iEnd = Math.min(u8len,blocksize);
  72. limit = Math.min(u8len,blocksize+extrasize);
  73. for(let i=blocksize+1;i<limit;i=i+2){
  74. if(10==u8[i] && 10==u8[i-1]) {
  75. iEnd = i+1;
  76. break;
  77. }
  78. }
  79. render(u8.slice(iStart,iEnd));
  80. });
  81. }
  82. //?url=#offset=&[len]&page=
  83. file = new absFile(location.search.substring(5));
  84. window.addEventListener('hashchange',loadSlice);
  85. </script>
  86. </head>
  87. <body>
  88. <script>loadSlice();</script>
  89. </body>