viewComic.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <!DOCTYPE html>
  2. <meta name="apple-mobile-web-app-capable" content="yes" />
  3. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  4. <html>
  5. <head>
  6. <meta charset="UTF-8">
  7. <script src="../script/jquery.min.js"></script>
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <script type='text/javascript' src="../script/semantic/semantic.min.js"></script>
  10. <script type='text/javascript' src="../script/ao_module.js"></script>
  11. <style>
  12. body, html {
  13. height: 100%;
  14. margin: 0;
  15. background-color:#2b2b2b;
  16. }
  17. #settingMenu .ui.toggle.checkbox input:checked ~ .box,#settingMenu .ui.toggle.checkbox input:checked ~ label{
  18. color: rgb(189, 189, 189) !important;
  19. }
  20. </style>
  21. <script>
  22. //Scrolling Controller
  23. var keys = {37: 1, 38: 1, 39: 1, 40: 1};
  24. function preventDefault(e) {
  25. e = e || window.event;
  26. if (e.preventDefault)
  27. e.preventDefault();
  28. e.returnValue = false;
  29. }
  30. function preventDefaultForScrollKeys(e) {
  31. if (keys[e.keyCode]) {
  32. preventDefault(e);
  33. return false;
  34. }
  35. }
  36. function disableScroll() {
  37. if (window.addEventListener) // older FF
  38. window.addEventListener('DOMMouseScroll', preventDefault, false);
  39. window.onwheel = preventDefault; // modern standard
  40. window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
  41. window.ontouchmove = preventDefault; // mobile
  42. document.onkeydown = preventDefaultForScrollKeys;
  43. }
  44. function enableScroll() {
  45. if (window.removeEventListener)
  46. window.removeEventListener('DOMMouseScroll', preventDefault, false);
  47. window.onmousewheel = document.onmousewheel = null;
  48. window.onwheel = null;
  49. window.ontouchmove = null;
  50. document.onkeydown = null;
  51. }
  52. disableScroll();
  53. </script>
  54. </head>
  55. <body>
  56. <div id="loading" style="position: fixed;top: 0;left: 0;background:rgba(0,0,0,0.5);color:white;width:100%;height:100%;z-index:100">
  57. <div class="ui active dimmer">
  58. <div class="ui text loader">Loading</div>
  59. </div>
  60. </div>
  61. <div class="ui attached inverted message" style="margin-top: 0em;" onClick="ToggleChapters();">
  62. <div class="header"><i class="bookmark icon"></i>You are already reached the top of this manga.</div>
  63. <p>Click here to select more chapters.</p>
  64. </div>
  65. <div id="MangaList" class="ui list">
  66. <div class="item" style="width: 100%;display: flex;align-items: flex-start;"><img src="" style="width: 100%;height: auto;"></img></div>
  67. </div>
  68. <!-- Click Detect DIV -->
  69. <div id="clickInterface" style="opacity:0;
  70. filter: alpha(opacity = 0);
  71. position:fixed;
  72. top:25%; bottom:25%; left:0; right:0;
  73. width:100%;
  74. height:50%;
  75. display:block;
  76. z-index:998;
  77. background:transparent;" onClick="">
  78. </div>
  79. <!-- Setting Config DIV -->
  80. <div id="SettingInterface" style="
  81. position:fixed;
  82. top:0; bottom:0; left:0; right:0;
  83. width:100%;
  84. height:100%;
  85. display:block;
  86. z-index:1501;
  87. display:none;" onClick="">
  88. <div id="settingMenu" class="ui very narrow container" style="top:15%;z-index:1502;">
  89. <div class="ui container" style="color:white;">
  90. <div class="ui inverted segment" style="background:rgba(61,61,61,0.8);">
  91. <p style="font-size:120%;"><i class='setting icon'></i>Settings</p>
  92. <div class="ui toggle checkbox">
  93. <input type="checkbox" id="lefthand">
  94. <label for="lefthand" style="color:white;"><i class="hand paper icon" style="transform: scaleX(-1);-moz-transform: scaleX(-1);-webkit-transform: scaleX(-1);-ms-transform: scaleX(-1);"></i>Left hand mode <br> Click the left section of the view for downward auto scrolling instead of right section.</label>
  95. </div><br><br>
  96. <div class="ui toggle checkbox">
  97. <input type="checkbox" id="progress">
  98. <label for="progress" style="color:white;"><i class="save icon"></i>Save progress <br> Save the current progress and return to that page automatically in the future.</label>
  99. </div><br><br>
  100. <div class="ui toggle checkbox">
  101. <input type="checkbox" id="pcm">
  102. <label for="pcm" style="color:white;"><i class="save icon"></i>PC Mode <br> Scale down the manga a bit to make you feel better on a big PC screen.</label>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <!-- Page Info DIV-->
  109. <div align="right" style="position: fixed;bottom: 0;right: 0;background:rgba(0,0,0,0.5);color:white;z-index:1000;">
  110. <div id="PageInfo" class="ui fluid text container">
  111. Loading Page Data...
  112. </div>
  113. </div>
  114. <!-- Next Chapter Message-->
  115. <div class="ui inverted message" onclick="NextChapter();" style="cursor: pointer;">
  116. <div class="header"><i class="bookmark icon"></i>You have finished this chapter.</div>
  117. <p id="reminder">Click this box to proceed to next chapter.</p>
  118. </div>
  119. <!-- Start of Chapter Selector-->
  120. <div id="ChapterSelector" class="ui inverted message" style="color:white;display:none;">
  121. <div class="ui stackable grid" id="chapterlist">
  122. </div>
  123. </div>
  124. <!-- END of Chapter Selector-->
  125. <div align="center" style="width:100%">
  126. <div class="ui buttons" >
  127. <button class="ui inverted basic button" onClick="window.location.href='index.html'" style="color:white !important;"><i class="chevron left icon"></i>Back</button>
  128. <button class="ui inverted basic button" onClick="ToggleChapters();" style="color:white !important;"><i class="book icon"></i>Chapters</button>
  129. </div>
  130. </div>
  131. <br>
  132. <br>
  133. <script type="text/javascript">
  134. var pages = [];
  135. var titles = "";
  136. var chapterPaths = [];
  137. var nextChapterID = 0;
  138. var maxChapterID = 0;
  139. var pagesNum = pages.length; //This page number is the number of files in the directory, not the actual page number
  140. var positions = [];
  141. var currentPage = 0;
  142. var chapterShown = false;
  143. var lastpage = 0;
  144. var floatWindow = !(!parent.isFunctionBar); //Updated support on floatWindow System
  145. //Auto save and left hand mode
  146. var autoSave = false;
  147. var leftHandMode = false;
  148. var isMobile = false; //initiate as false
  149. // device detection
  150. if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
  151. || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
  152. isMobile = true;
  153. }
  154. var preRenderComplete = false;
  155. var pcm = false; //PC Mode
  156. //Screen Width and height data
  157. var screenWidth = $(window).width();
  158. var screenHeight = $(window).height();
  159. //Debug Interface
  160. console.log("This Chapter ID: ",nextChapterID);
  161. console.log("Max Chapter ID: ",maxChapterID);
  162. console.log("Chapter Paths: ",chapterPaths);
  163. if(floatWindow){
  164. $("#PageInfo").parent().css("bottom","0px");
  165. $("body").css("padding-bottom","20px");
  166. }
  167. //Load the content of this manga chapter
  168. var mangaFolder = window.location.hash.substr(1);
  169. ao_module_agirun("Manga Cafe/backend/getMangaInfo.js", {folder: mangaFolder}, function(data){
  170. console.log(data);
  171. pages = data.pages;
  172. titles = data.title,
  173. chapterPaths = data.otherChapterDir;
  174. nextChapterID = 0;
  175. maxChapterID = chapterPaths.length;
  176. //Render manga to ui
  177. $("#MangaList").html("");
  178. data.pages.forEach(page => {
  179. $("#MangaList").append(`<div class="item" style="width: 100%;display: flex;align-items: flex-start;"><img src="../media?file=${page}" style="width: 100%;height: auto;"></img></div>`)
  180. });
  181. //Render next chapter button
  182. $("#chapterlist").html("");
  183. var counter = 0;
  184. var nextOneIsPreRender = false;
  185. var prerender = "";
  186. data.otherChapterDir.forEach(chapter => {
  187. var chapterName = chapter.split("/").pop();
  188. var chapterWide = "four";
  189. if (isMobile){
  190. chapterWide = "sixteen";
  191. }
  192. if (chapterName == data.title[1]){
  193. $("#chapterlist").append(`<div class="${chapterWide} wide column compact" style="color:white; padding: 0.3em !important;"><a class="ui fluid inverted basic disabled button" style="color:white;">${chapterName}</a></div>`);
  194. nextChapterID = counter;
  195. nextOneIsPreRender = true;
  196. }else{
  197. if (nextOneIsPreRender){
  198. nextOneIsPreRender = false;
  199. prerender = chapter;
  200. }
  201. $("#chapterlist").append(`<div class="${chapterWide} wide column compact" style="color:white; padding: 0.3em !important;"><a class="ui fluid inverted basic button" style="color:white;" onClick="ChapterRedirect('${chapter}');">${chapterName}</a></div>`);
  202. }
  203. counter++;
  204. });
  205. //Start waiting for all images to load
  206. var imagesLoaded = 0;
  207. var totalImages = $('img').length;
  208. $('img').on('load', function(event) {
  209. imagesLoaded++;
  210. if (imagesLoaded == totalImages) {
  211. init();
  212. if (nextOneIsPreRender == true){
  213. //There is no next chapter
  214. preRenderComplete = true;
  215. }else{
  216. //Start next chapter pre-render
  217. ao_module_agirun("Manga Cafe/backend/getMangaInfo.js",{folder: prerender}, function(data){
  218. //Pre-render complete
  219. console.log("Next chapter pre-render completed")
  220. preRenderComplete = true;
  221. });
  222. }
  223. }
  224. });
  225. });
  226. //Window onload replace document.ready due to the measurement of each div have to be done after the page loaded
  227. function init(){
  228. $('#loading').hide();
  229. enableScroll();
  230. positions = [];
  231. var count = 0;
  232. $('.item').each(function(i, obj) {
  233. var offsets = $(this).offset();
  234. var top = offsets.top;
  235. //console.log(top);
  236. positions.push(top);
  237. count += 1;
  238. });
  239. if (nextChapterID + 1 > maxChapterID - 1){
  240. $('#reminder').html('There is no more chapters.');
  241. }
  242. //alert(count);
  243. //Check if PCB Mode
  244. if (localStorage.pcm !== null){
  245. pcm = (localStorage.pcm == 'true');
  246. console.log('PC Mode: ' + pcm);
  247. $('#pcm').prop("checked",pcm);
  248. }
  249. if (pcm){
  250. //If PC mode is enabled, re-allign all image
  251. setTimeout(function(){ PCMode(0); }, 100);
  252. }
  253. //AutoSave Function
  254. if (localStorage.autoSave !== null){
  255. autoSave = (localStorage.autoSave == 'true');
  256. console.log('AutoSave: ' + autoSave);
  257. $('#progress').prop("checked",autoSave);
  258. if (localStorage.getItem(titles[0] + "-" + titles[1]) !== null && autoSave){
  259. var page = localStorage.getItem(titles[0] + "-" + titles[1]);
  260. console.log('Loading progress: ' + page);
  261. if (page != count){
  262. //Not yet finished
  263. console.log(count,page)
  264. setTimeout(function(){ GoToPage(page); },100);
  265. }
  266. }
  267. }
  268. if(localStorage.getItem(titles[0] + "-" + titles[1]) !== null && (localStorage.autoSave === null || localStorage.autoSave == 'false')){
  269. localStorage.removeItem(titles[0] + "-" + titles[1]);
  270. console.log("Old autosave record removed.");
  271. }
  272. //Left hand Mode function
  273. if (localStorage.leftHandMode !== null){
  274. leftHandMode = (localStorage.leftHandMode == 'true');
  275. console.log('Left Hand Mode: ' + leftHandMode);
  276. $('#lefthand').prop("checked",leftHandMode);
  277. }
  278. UpdatePageInfo();
  279. }
  280. //Check if settings changed
  281. $('#lefthand').change(function(){
  282. if($(this).is(':checked')){
  283. localStorage.leftHandMode = true;
  284. leftHandMode = true;
  285. console.log('Left Hand Mode Changed to ' + leftHandMode);
  286. } else {
  287. localStorage.leftHandMode = false;
  288. leftHandMode = false;
  289. console.log('Left Hand Mode Changed to ' + leftHandMode);
  290. }
  291. });
  292. $('#progress').change(function(){
  293. if($(this).is(':checked')){
  294. localStorage.autoSave = true;
  295. autoSave = true;
  296. console.log('Auto Save Changed to ' + autoSave);
  297. localStorage.setItem(titles[0] + "-" + titles[1], currentPage);
  298. } else {
  299. localStorage.autoSave = false;
  300. autoSave = false;
  301. console.log('Auto Save Changed to ' + autoSave);
  302. }
  303. });
  304. $('#pcm').change(function(){
  305. if($(this).is(':checked')){
  306. localStorage.pcm = true;
  307. pcm = true;
  308. console.log('PC Mode Changed to ' + pcm);
  309. PCMode();
  310. } else {
  311. localStorage.pcm = false;
  312. pcm = false;
  313. console.log('PC Mode Changed to ' + pcm);
  314. MobileMode();
  315. }
  316. });
  317. //End of setting change section
  318. //Recalculate page number accodring to new image position
  319. window.onresize = function() {
  320. positions = [];
  321. $('.item').each(function(i, obj) {
  322. var offsets = $(this).offset();
  323. var top = offsets.top;
  324. //console.log(top);
  325. positions.push(top);
  326. if (nextChapterID + 1 > maxChapterID - 1){
  327. $('#reminder').html('There is no more chapters.');
  328. }
  329. screenWidth = $(window).width();
  330. screenHeight = $(window).height();
  331. });
  332. }
  333. //Click Page Scroll functions
  334. var ControlPanel = document.getElementById('clickInterface');
  335. ControlPanel.addEventListener("click", AutoPageScroll, false);
  336. function AutoPageScroll(e){
  337. var clickX = e.clientX;
  338. var clickY = e.clientY;
  339. var split = screenWidth / 2;
  340. if (leftHandMode == true){
  341. //Left side is next page, right side is previous page
  342. if (clickX < split){
  343. //left
  344. scrollDown();
  345. }else{
  346. //right
  347. scrollUp();
  348. }
  349. }else{
  350. if (clickX > split){
  351. //right
  352. scrollDown();
  353. }else{
  354. //left
  355. scrollUp();
  356. }
  357. }
  358. }
  359. function scrollDown(){
  360. $("html, body").animate({ scrollTop: $(window).scrollTop() + screenHeight * 0.8 }, 1000);
  361. }
  362. function scrollUp(){
  363. $("html, body").animate({ scrollTop: $(window).scrollTop() - screenHeight * 0.8 }, 1000);
  364. }
  365. //End of auto scrolling
  366. //Resize all image to PC mode
  367. function PCMode(mode){
  368. var tmpPage = currentPage;
  369. $('.item').each(function(i, obj) {
  370. $(this).css("width","50%");
  371. });
  372. $('#MangaList').css("width","100%");
  373. $('#MangaList').prop("align","center");
  374. setTimeout(function(){ CalculatePageOffsets(); }, 1000);
  375. if (mode != 0){
  376. setTimeout(function(){ GoToPage(tmpPage); }, 100);
  377. }
  378. }
  379. function MobileMode(){
  380. var tmpPage = currentPage;
  381. $('.item').each(function(i, obj) {
  382. $(this).css("width","100%");
  383. });
  384. $('#MangaList').css("width","");
  385. $('#MangaList').prop("align","");
  386. setTimeout(function(){ CalculatePageOffsets(); }, 1000);
  387. setTimeout(function(){ GoToPage(tmpPage); }, 100);
  388. }
  389. function CalculatePageOffsets(){
  390. console.log('Calculating Page Offsets');
  391. positions = [];
  392. $('.item').each(function(i, obj) {
  393. var offsets = $(this).offset();
  394. var top = offsets.top;
  395. //console.log(top);
  396. positions.push(top);
  397. if (nextChapterID + 1 > maxChapterID - 1){
  398. $('#reminder').html('There is no more chapters.');
  399. }
  400. });
  401. UpdatePageInfo();
  402. }
  403. //Update page info on window scroll
  404. $( window ).scroll(function() {
  405. //console.log($(window).scrollTop());
  406. currentPage = getPageNum($(window).scrollTop(),positions);
  407. if (autoSave == true && currentPage != 0 && lastpage != currentPage){
  408. //Save Page number as: "title-chapter:page"
  409. localStorage.setItem(titles[0] + "-" + titles[1], currentPage);
  410. lastpage = currentPage;
  411. console.log(localStorage.getItem(titles[0] + "-" + titles[1]));
  412. }
  413. var shortentitle = titles[1];
  414. //console.log(currentPage);
  415. if (shortentitle.length > 12){
  416. shortentitle = shortentitle.substring(0, 12) + "...";
  417. }
  418. var prerenderFinishIcon = "<i class='loading spinner icon'></i>";
  419. if (preRenderComplete){
  420. prerenderFinishIcon = "<i class='checkmark icon' style='color: green;'></i>"
  421. }
  422. $('#PageInfo').html("  <i class='chevron left icon' onClick='back();'></i>  <i class='setting icon' onClick='ShowSetting();'></i>" + shortentitle + " " + prerenderFinishIcon + " " + currentPage.toString() + "/" + positions.length.toString() + "    " + titles[0] + "  ");
  423. //if the page reached the end, hide the auto scroll div
  424. if($(window).scrollTop() + $(window).height() == $(document).height()) {
  425. $('#clickInterface').hide();
  426. }else if ( $('#clickInterface').is(':visible') !== true && chapterShown !== true){
  427. $('#clickInterface').show();
  428. }
  429. });
  430. //Update Page Info (same as window.scroll function)
  431. function UpdatePageInfo(){
  432. currentPage = getPageNum($(window).scrollTop(),positions);
  433. if (autoSave == true && currentPage != 0){
  434. //Save Page number as: "title-chapter:page"
  435. localStorage.setItem(titles[0] + "-" + titles[1], currentPage);
  436. }
  437. //console.log(currentPage);
  438. var shortentitle = titles[1];
  439. //console.log(currentPage);
  440. if (shortentitle.length > 12){
  441. shortentitle = shortentitle.substring(0, 12) + "...";
  442. }
  443. var prerenderFinishIcon = "";
  444. if (preRenderComplete){
  445. prerenderFinishIcon = "<i class='checkmark icon'></i>"
  446. }
  447. $('#PageInfo').html("  <i class='chevron left icon' onClick='back();'></i>  <i class='setting icon' onClick='ShowSetting();'></i>" + shortentitle + " " + prerenderFinishIcon + " " + currentPage.toString() + "/" + positions.length.toString() + "    " + titles[0] + "  ");
  448. }
  449. function back(){
  450. window.location.href='index.html';
  451. }
  452. //Setting Interface controlling
  453. function ShowSetting(){
  454. $('#SettingInterface').fadeIn('slow');
  455. }
  456. var ExitPanel = document.getElementById('SettingInterface');
  457. ExitPanel.addEventListener("click", HideSetting, false);
  458. function HideSetting(e){
  459. //console.log(e.clientX);
  460. //console.log(e.clientY);
  461. pleft = $('#settingMenu').offset().left;
  462. pright = pleft + $('#settingMenu').width();
  463. ptop = $('#settingMenu').offset().top;
  464. pbottom = ptop + $('#settingMenu').height();
  465. //console.log(e.clientX,e.clientY,pleft,pright,ptop,pbottom);
  466. if (e.clientX < pleft || e.clientX > pright || e.clientY + $(window).scrollTop() < ptop || e.clientY + $(window).scrollTop()> pbottom){
  467. $('#SettingInterface').fadeOut('slow');
  468. }
  469. }
  470. //Next chapter controlling algorithm
  471. function NextChapter(){
  472. var id = nextChapterID + 1;
  473. if (id > maxChapterID - 1){
  474. }else{
  475. ChapterRedirect(chapterPaths[id]);
  476. }
  477. }
  478. function ChapterRedirect(path){
  479. window.location.href= "viewComic.html#" + path;
  480. window.location.reload();
  481. }
  482. //Show all chapters of this manga
  483. function ToggleChapters(){
  484. if (chapterShown == true){
  485. $('#ChapterSelector').fadeOut('slow');
  486. //$("html, body").animate({ scrollTop: $("#ChapterSelector").offset().top }, 1000);
  487. $("html, body").animate({ scrollTop: $(document).height() }, 1000);
  488. chapterShown = false;
  489. $('#clickInterface').show();
  490. }else{
  491. $('#ChapterSelector').fadeIn('slow');
  492. $("html, body").animate({ scrollTop: $("#ChapterSelector").offset().top }, 1000);
  493. //$("html, body").animate({ scrollTop: $(document).height() }, 1000);
  494. chapterShown = true;
  495. $('#clickInterface').hide();
  496. }
  497. }
  498. //Convert current view top to page number
  499. function getPageNum (num, arr) {
  500. for (var i = 0;i<arr.length;i++){
  501. if (arr[i] > num){
  502. return i;
  503. }
  504. }
  505. return arr.length;
  506. }
  507. function GoToPage(num){
  508. //console.log('Going to page: ' + num);
  509. CalculatePageOffsets();
  510. console.log("Going to page number:" + num);
  511. var targetTop = positions[num - 1];
  512. $('html, body').animate({scrollTop: targetTop + 5}, 1000);
  513. }
  514. </script>
  515. </body>
  516. </html>