Advertisement
Guest User

Japanese Book Reader

a guest
Nov 18th, 2018
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/encoding-japanese/1.0.29/encoding.min.js"></script>
  5. <style>
  6. body {
  7. background-color: #280000;
  8. color: #FFCC33;
  9. line-height: 2.0;
  10. white-space: pre-line;
  11. overflow: auto;
  12. padding: 0 10px;
  13. margin: 20px;
  14. overflow: auto;
  15. margin: 40px auto;
  16. max-width: 60%;
  17. padding: 0 10px;
  18. }
  19. img {
  20. display: block;
  21. margin: 0 auto;
  22. max-width: 100%;
  23. }
  24. .furigana {
  25. color: #BD7777;
  26. direction: rtl;
  27. display: inline-block;
  28. font-size: .5em;
  29. margin-top: -1em;
  30. user-select: none;
  31. vertical-align: top;
  32. white-space: nowrap;
  33. width: 0;
  34. }
  35. .textArea {
  36. position: fixed;
  37. top: 0;
  38. padding: 0 12px;
  39. border-style: solid;
  40. background-color: #250000;
  41. color: #c19920;
  42. border-color: #280000;
  43. border-width: 1px;
  44. line-height: 2.0;
  45. width: 19%;
  46. height: 100%;
  47. }
  48. .textAreaLeft {
  49. border-right-color: #705400;
  50. left: 0px;
  51. }
  52. .textAreaRight {
  53. border-left-color: #705400;
  54. right: 0px;
  55. resize: none;
  56. }
  57. </style>
  58. </head>
  59. <body onscroll="SetDivPosition()">
  60. <center>
  61. <input type="file" id="file" />
  62. <h1 id="fileName"></h1>
  63. </center>
  64. <textarea class="textArea textAreaLeft">
  65. &#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;
  66. &#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;
  67. </textarea>
  68. <div id="fileContents"></div>
  69. <textarea class="textArea textAreaRight">
  70. &#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;
  71. &#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;&#13;&#10;
  72. </textarea>
  73.  
  74. <script type="text/javascript">
  75. const htmlFileName = 'fileName_' + window.location.pathname.split("/").pop();
  76. const htmlFileContents = 'fileContents_' + window.location.pathname.split("/").pop();
  77. const render = (fileName, fileContents) => {
  78. fileContents = fileContents
  79. .replace(/[#\((.*?.jpg)\)入る]/g, "<img src='$1' title='$1'>") // Insert <img src="..." >
  80. .replace(/[#改ページ]/g, "<hr></hr>") // Draw a white line for page changes
  81. .replace(/《(.*?)》/g, "<span class='furigana'>$1</span>"); // Wrap furigana
  82. document.getElementById('fileName').innerHTML = fileName;
  83. nameoffile = fileName;
  84. document.getElementById('fileContents').innerHTML = fileContents;
  85. };
  86. document.getElementById('file').addEventListener('change', (event) => {
  87. const file = event.target.files[0];
  88. const reader = new FileReader();
  89. reader.onload = (e) => {
  90. let fileContents = new Uint8Array(e.target.result);
  91. fileContents = Encoding.convert(fileContents,
  92. {
  93. to: 'unicode',
  94. from: Encoding.detect(fileContents),
  95. type: 'string'
  96. });
  97. // Remember the opened file
  98. localStorage.setItem(htmlFileName, file.name);
  99. localStorage.setItem(htmlFileContents, fileContents);
  100. // Render the new file
  101. render(file.name, fileContents);
  102. };
  103. reader.readAsArrayBuffer(file);
  104. }, false);
  105.  
  106. if (localStorage.getItem(htmlFileName)) {
  107. // If opened a file before, render it
  108. render(localStorage.getItem(htmlFileName), localStorage.getItem(htmlFileContents));
  109. }
  110.  
  111. // Load scrollbar position
  112. window.onload = function(){
  113. var strCook = localStorage.getItem(htmlFileName + "yPos")
  114. if(strCook.indexOf("!~")!=0){
  115. var intS = strCook.indexOf("!~");
  116. var intE = strCook.indexOf("~!");
  117. var strPos = strCook.substring(intS+2,intE);
  118. document.getElementsByTagName("body")[0].scrollTop = strPos;
  119. }
  120. }
  121.  
  122. // Set where scrollbar is at
  123. function SetDivPosition(){
  124. var intY = document.getElementsByTagName("body")[0].scrollTop;
  125. document.title = document.getElementById('fileName').innerHTML + " " + intY;
  126. localStorage.setItem(htmlFileName + "yPos", "yPos=!~" + intY + "~!")
  127. }
  128. </script>
  129. </body>
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement