newtoki(manatoki) viewer & downloader

newtoki(manatoki) viewer & downloader & adblock & more!

  1. // ==UserScript==
  2. // @name newtoki(manatoki) viewer & downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description newtoki(manatoki) viewer & downloader & adblock & more!
  6. // @author You
  7. // @include http*://manatoki*
  8. // @include http*://newtoki*
  9. // @grant GM_download
  10. // ==/UserScript==
  11. // adblock
  12. $('.hd_pops').remove()
  13. $('.board-tail-banner').remove()
  14. $('.basic-banner.row.row-10').remove()
  15. let linklist = localStorage.getItem('clickedlist'); // get clicked element
  16. // append download button
  17. var sendBtn = document.createElement("button");
  18. sendBtn.className = "btn btn-warning";
  19. sendBtn.style.zIndex = "3";
  20. sendBtn.style.position = "fixed";
  21. sendBtn.style.bottom = "0";
  22. sendBtn.style.right = "0";
  23. sendBtn.innerText = "download";
  24. let clicked, clickedlist = JSON.parse(localStorage.getItem("clickedlist"));
  25. if (clickedlist == null) {
  26. clickedlist = []
  27. console.log("welcome")
  28. }
  29. // check whether user is at viewpage
  30. if (!$("[class ='view-content1']")[0]) {
  31. document.getElementById("main-banner-view").appendChild(sendBtn);
  32. let m = clickedlist.some(function (item) {
  33. return item[0] === document.URL
  34. });
  35. if (m == false) {
  36. var today = new Date();
  37. var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
  38. var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  39. var dateTime = date + ' ' + time;
  40. clickedlist.push([document.URL, dateTime])
  41. localStorage.setItem("clickedlist", JSON.stringify(clickedlist))
  42. console.log(clickedlist)
  43. }
  44. else {
  45. console.log("you've visited")
  46. }
  47. }
  48.  
  49. if ($("[class ='view-content1']")[0]){
  50. for (let i=0; i < clickedlist.length; i ++) {
  51. // console.log(typeof clickedlist[i])
  52. if ($('a[href*="' + clickedlist[i][0] + '"]')[0]){
  53. $('a[href*="' + clickedlist[i][0] + '"]')[0].style.color = "blue"
  54. $('a[href*="' + clickedlist[i][0] + '"]')[0].text += "("+clickedlist[i][1]+")";
  55. }
  56. }
  57. console.log(clickedlist)
  58. // let linkBtn = $("[class='item-subject']")
  59. // // $(document).on('click', 'a', false);
  60. // linkBtn.click(function (e) {
  61. // console.log(e.target.getAttribute("href"))
  62. // clicked = e.target.getAttribute("href")
  63. // if (clickedlist.includes(clicked) == false){
  64. // clickedlist.push(clicked)
  65. // }
  66. // // clicked.style.color = "blue";
  67. // console.log(clickedlist)
  68. // window.localStorage.setItem("clickedlist", JSON.stringify(clickedlist))
  69. // });
  70. }
  71. var regex = /\d+/g, mnum = (parent.window.location.pathname != "/") ? parent.window.location.pathname.match(regex)[0] : 0;
  72. console.log(mnum)
  73. // get page title and manga number
  74. sendBtn.onclick = function() {
  75. // let canvas = $("img[src*='/data/file/comic'][src*="+mnum+"]").not("img[src*='thumb']")
  76. var title = document.getElementsByClassName('page-desc')[0].innerHTML
  77. let canvas = $("img[src*='/data/']").not("img[src*='thumb']"), loadimg = $('img[src$="/img/loading-image.gif"]'), countedword = {}
  78. // check if loading is completed
  79. if (loadimg.length <= 1) {
  80. // get every image which contains '/data/' and classify with parentNode inside the object
  81. for (let i = 0; i < canvas.length; i++) {
  82. var word = canvas[i].parentNode
  83. if (countedword[word.className] == undefined) {
  84. countedword[word.className] = 1;
  85. } else {
  86. countedword[word.className] += 1;
  87. }
  88. }
  89. //get the manga image from the object
  90. let a = 0, viewdiv = Object.keys(countedword)[1]
  91. console.log(viewdiv);
  92. console.log(countedword)
  93. // download every manga images every 0.3 sec
  94. for (let i = 0; i < canvas.length; i++) {
  95. (function(x) {
  96. setTimeout(function() {
  97. let word = canvas[i].parentNode
  98. if (word.className == viewdiv) {
  99. a += 1
  100. var blob = canvas[i].currentSrc
  101. let arg = {
  102. url: blob,
  103. name: title + a
  104. };
  105. GM_download(arg)
  106. }
  107. }, 300 * x);
  108. })(i);
  109. }
  110. } else {
  111. alert("wait for loading...")
  112. }
  113. };