Advertisement
Shuraken007

auto_next.js

Feb 18th, 2025 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Auto next
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @license MIT
  6. // @description  auto clicking for next chapter
  7. // @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  8. // @author       Shuraken007
  9. // @include https://*/*
  10. // @include http://*/*
  11. // ==/UserScript==
  12.  
  13. /* jshint esversion: 9 */
  14. 'use strict';
  15.  
  16. {
  17.    this.$ = this.jQuery = jQuery.noConflict(true);
  18.  
  19.    const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
  20.  
  21.    const config = {
  22.       // "ranobe.me": {
  23.       //    "url": "https://ranobe.me/ranobe*/*",
  24.       //    "delay": 100,
  25.       //    "next": async function () {
  26.       //       $('.read_nav_button.read_nav_button_bottom:contains("Следующая")').get(0).click()
  27.       //    },
  28.       //    "delete": [],
  29.       //    "hide": ["#site-content-left", "#site-content-right", ".footer", "#header", ".MessageAloneHead"],
  30.       //    "manual": async function () {
  31.       //       document.getElementById("site-content-center").style.margin = "0px auto";
  32.       //       document.getElementById("site-content-center").style.padding = "0px 50px";
  33.       //       document.getElementById("site-content-center").style.maxWidth = "1200px";
  34.       //       document.getElementById("site-content").style.maxWidth = "1200px";
  35.       //       document.getElementById("site-content").style.paddingBottom = "700px";
  36.       //       if ($('#darklight').html() === '1') {
  37.       //          $('.edit-darklight').click()
  38.       //       }
  39.       //       // document.body.style.fontFamily = "Georgia"
  40.       //       $('#fontSize').html(21);
  41.       //       $('.edit-font').click();
  42.       //    }
  43.       // },
  44.       "ranobelib": {
  45.          "url": "https://ranobelib.me/ru/*/read/v*/*",
  46.          "delay": 1000,
  47.          "next": async function () {
  48.             $('.btn:contains("Вперёд")').get(0).click()
  49.          },
  50.          "manual": async function () {
  51.             setInterval(() => {
  52.                try {
  53.                   document
  54.                      .getElementsByClassName("comments")[0]
  55.                      .parentNode
  56.                      .parentNode
  57.                      .style
  58.                      .marginBottom = "1000px";
  59.                }
  60.                catch (err) { }
  61.             },
  62.                1000);
  63.          }
  64.       },
  65.    };
  66.    // prepareRegex by JoeSimmons
  67.    // used to take a string and ready it for use in new RegExp()
  68.    function prepareRegex(string, is_star_special = false) {
  69.       // escape: []^&$.()?/\+{}|
  70.       string = string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
  71.       if (!is_star_special) {
  72.          string = string.replaceAll('*', '\\*')
  73.       } else {
  74.          // '*' -> '[^ ]*', but '\*' -> '*'
  75.          string = string.replace(/\\?\*/g, function (fullMatch) {
  76.             return fullMatch === '\\*' ? '*' : '[^ ]*';
  77.          });
  78.       }
  79.       return string;
  80.    }
  81.  
  82.    function getRegFromString(string, is_global_required) {
  83.       var a = string.split("/");
  84.       let modifiers = a.pop();
  85.       a.shift();
  86.       let pattern = a.join("/");
  87.       if (is_global_required && !modifiers.includes('g')) {
  88.          modifiers += 'g';
  89.       }
  90.       return new RegExp(pattern, modifiers);
  91.    }
  92.  
  93.    const rIsRegexp = /^\/(.+)\/(\w+)?$/;
  94.    function tokenToRegex(string, is_prepared = false) {
  95.       if (string.match(rIsRegexp)) {
  96.          return getRegFromString(string, true);
  97.       }
  98.  
  99.       if (is_prepared) {
  100.          string = prepareRegex(string, true);
  101.          return new RegExp(string);
  102.       }
  103.       return string;
  104.    }
  105.  
  106.    class ScriptRunner {
  107.       constructor() {
  108.          this.on = false
  109.          this.settings = null;
  110.          this.cur_url = window.location.href;
  111.       }
  112.  
  113.       preLoad() {
  114.          for (const [_, url_config] of Object.entries(config)) {
  115.             let url_token = tokenToRegex(url_config.url, true);
  116.             if (!url_token.test(this.cur_url)) continue;
  117.             this.settings = url_config;
  118.             this.on = true
  119.             break;
  120.          }
  121.       }
  122.  
  123.       async prepareNewPage() {
  124.          if (!this.on) return;
  125.  
  126.          if (this.settings.delay) {
  127.             await delay(this.settings.delay);
  128.          }
  129.          if (this.settings.delete)
  130.             this.settings.delete.forEach(e => $(e).remove());
  131.          if (this.settings.hide)
  132.             this.settings.hide.forEach(e => $(e).hide());
  133.  
  134.          if (this.settings.manual)
  135.             await this.settings.manual();
  136.       }
  137.  
  138.       async onLoad() {
  139.          if (!this.on) return;
  140.  
  141.          this.prepareNewPage();
  142.          this.add_scroll_event(this.settings);
  143.       }
  144.  
  145.       add_scroll_event(settings) {
  146.          let cls = this;
  147.          $(window).on('scroll', async function () {
  148.             if ($(window).scrollTop() + 2 > $(document).height() - $(window).height()) {
  149.                await settings.next();
  150.             }
  151.          }).scroll();
  152.       }
  153.  
  154.    }
  155.  
  156.    let script_runner = new ScriptRunner();
  157.    script_runner.preLoad();
  158.  
  159.    document.readyState !== 'loading'
  160.       ? script_runner.onLoad()
  161.       : addEventListener("DOMContentLoaded", () => { script_runner.onLoad(); });
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement