wnacg jump

jump to indicate page

  1. // ==UserScript==
  2. // @name wnacg jump
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description jump to indicate page
  6. // @author charles
  7. // @match http://www.wnacg.com/photos-slide-aid-*.html
  8. // @icon https://www.google.com/s2/favicons?domain=wnacg.com
  9. // @run-at document-body
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const select = document.createElement("select");
  14. select.style.position = "fixed";
  15. select.style.top = "50%";
  16. select.style.left = "10px";
  17. select.style.height = "30px"
  18.  
  19. $("body").ready(() => {
  20. $("body").unbind("click");
  21. }
  22. )
  23. document.getElementsByTagName("body")[0].appendChild(select);
  24.  
  25. let count = 0;
  26. let max = 0;
  27. let index = 0;
  28. let list = []
  29. let optionList = []
  30. window.onscroll = () => {
  31. let scrollTop = document.querySelector('html').scrollTop;
  32. if (optionList.length > index) {
  33. if (scrollTop <= optionList[index].offsetTop && index > 0) {
  34. index = index - 1;
  35. select.value = list[index];
  36. // document.querySelector("select").value = list[index]
  37. } else if (optionList.length > index + 1) {
  38. if (scrollTop >= optionList[index + 1].offsetTop) {
  39. index = index + 1;
  40. select.value = list[index];
  41. // document.querySelector("select").value = list[index]
  42. }
  43. }
  44. }
  45. }
  46. const observer = new MutationObserver(function (mutations_list) {
  47. mutations_list.forEach(function (mutation) {
  48. mutation.addedNodes.forEach(function (added_node) {
  49. if (added_node.nodeName === "DIV") {
  50. if (count === 0) {
  51. const span = document.querySelector("#img_list").querySelector("div").querySelector("span").innerText;
  52. max = Number(span.split('/')[1]);
  53. }
  54. count = count + 1;
  55. const img = added_node.querySelector("img");
  56. const timer = setInterval(() => {
  57. if (img.complete) {
  58. clearInterval(timer)
  59. let option = document.createElement("option");
  60. option.innerText = count + "/" + max;
  61. list.push(count + "/" + max);
  62. select.appendChild(option);
  63. optionList.push(added_node)
  64. option.onclick = (e) => {
  65. e.preventDefault();
  66. document.querySelector("html").scrollTop = added_node.offsetTop;
  67. $("body").focus()
  68. // window.scrollTo(0, Number(rect.top))
  69. }
  70. option.onmousedown = (e) => {
  71. e.preventDefault();
  72. }
  73. }
  74. }, 50)
  75. if (count === max) {
  76. observer.disconnect();
  77. }
  78. }
  79. });
  80. });
  81. });
  82.  
  83. observer.observe(document.querySelector("#img_list"), {subtree: false, childList: true});