InfiniteJandan

Waste your time faster by making images infinite on JANDAN.NET

目前为 2017-11-09 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name InfiniteJandan
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Waste your time faster by making images infinite on JANDAN.NET
  6. // @author w1ndy
  7. // @match http://jandan.net/pic
  8. // @match https://jandan.net/pic
  9. // @match http://jandan.net/ooxx
  10. // @match https://jandan.net/ooxx
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. let loading = false;
  18. let currentPage = $;
  19.  
  20. function getNextPage (jq) {
  21. return new Promise((resolve, reject) => {
  22. const URI = $(jq.find('.previous-comment-page:first')).attr('href');
  23. if (!URI) {
  24. reject('No next page!');
  25. } else {
  26. $.get(URI, data => {
  27. const page = '<div id="new-page">' + data.replace(/^[\s\S]*<body.*?>|<\/body>[\s\S]*$/ig, '') + '</div>';
  28. window.history.pushState(null, '', URI);
  29. resolve($(page));
  30. })
  31. .fail(() => {
  32. reject('Unable to load next page!');
  33. });
  34. }
  35. });
  36. }
  37.  
  38. function removeHook() {
  39. $('.comment-like, .comment-unlike').off('click', '**');
  40. $('.tucao-btn').off('click', '**');
  41. }
  42.  
  43. function addHook() {
  44. // ooxx btn
  45. $('.comment-like, .comment-unlike').on('click', function () {
  46. ooxx_action($(this), 'comment');
  47. });
  48.  
  49. // tucao btn
  50. $('.tucao-btn').on('click', function () {
  51. var $this = $(this);
  52. var comment_id = $this.data('id');
  53. var comment_item = $this.closest('li');
  54. var tucao_div = comment_item.find('div.jandan-tucao');
  55. if (tucao_div.length) {
  56. tucao_div.slideToggle('fast');
  57. } else {
  58. tucao_load_content(comment_item, comment_id);
  59. }
  60. });
  61. }
  62.  
  63. // Move up the comment box
  64. $('#commentform').insertBefore('#comments > div:nth-child(1)');
  65. $('#comments > div:nth-last-child(1)').insertBefore('#commentform');
  66.  
  67. // Insert infinite sensor
  68. $('<div id="infinite-status">Loading next page...</div>')
  69. .css('height', '50px')
  70. .css('line-height', '50px')
  71. .css('text-align', 'center')
  72. .insertAfter('.commentlist');
  73.  
  74. document.addEventListener('scroll', () => {
  75. if (loading) {
  76. return;
  77. }
  78. if ($(window).scrollTop() + $(window).height() > $('#infinite-status').offset().top) {
  79. console.log('loading...');
  80. loading = true;
  81. getNextPage(currentPage)
  82. .then(page => {
  83. $('.commentlist').append(page.find('.commentlist > *'));
  84. currentPage = page;
  85. loading = false;
  86. })
  87. .catch(err => {
  88. $('#infinite-status').html(err);
  89. });
  90. }
  91. });
  92. })();