Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Auto next
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @license MIT
- // @description auto clicking for next chapter
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
- // @author Shuraken007
- // @include https://*/*
- // @include http://*/*
- // ==/UserScript==
- /* jshint esversion: 9 */
- 'use strict';
- {
- this.$ = this.jQuery = jQuery.noConflict(true);
- const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
- const config = {
- // "ranobe.me": {
- // "url": "https://ranobe.me/ranobe*/*",
- // "delay": 100,
- // "next": async function () {
- // $('.read_nav_button.read_nav_button_bottom:contains("Следующая")').get(0).click()
- // },
- // "delete": [],
- // "hide": ["#site-content-left", "#site-content-right", ".footer", "#header", ".MessageAloneHead"],
- // "manual": async function () {
- // document.getElementById("site-content-center").style.margin = "0px auto";
- // document.getElementById("site-content-center").style.padding = "0px 50px";
- // document.getElementById("site-content-center").style.maxWidth = "1200px";
- // document.getElementById("site-content").style.maxWidth = "1200px";
- // document.getElementById("site-content").style.paddingBottom = "700px";
- // if ($('#darklight').html() === '1') {
- // $('.edit-darklight').click()
- // }
- // // document.body.style.fontFamily = "Georgia"
- // $('#fontSize').html(21);
- // $('.edit-font').click();
- // }
- // },
- "ranobelib": {
- "url": "https://ranobelib.me/ru/*/read/v*/*",
- "delay": 1000,
- "next": async function () {
- $('.btn:contains("Вперёд")').get(0).click()
- },
- "manual": async function () {
- setInterval(() => {
- try {
- document
- .getElementsByClassName("comments")[0]
- .parentNode
- .parentNode
- .style
- .marginBottom = "1000px";
- }
- catch (err) { }
- },
- 1000);
- }
- },
- };
- // prepareRegex by JoeSimmons
- // used to take a string and ready it for use in new RegExp()
- function prepareRegex(string, is_star_special = false) {
- // escape: []^&$.()?/\+{}|
- string = string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
- if (!is_star_special) {
- string = string.replaceAll('*', '\\*')
- } else {
- // '*' -> '[^ ]*', but '\*' -> '*'
- string = string.replace(/\\?\*/g, function (fullMatch) {
- return fullMatch === '\\*' ? '*' : '[^ ]*';
- });
- }
- return string;
- }
- function getRegFromString(string, is_global_required) {
- var a = string.split("/");
- let modifiers = a.pop();
- a.shift();
- let pattern = a.join("/");
- if (is_global_required && !modifiers.includes('g')) {
- modifiers += 'g';
- }
- return new RegExp(pattern, modifiers);
- }
- const rIsRegexp = /^\/(.+)\/(\w+)?$/;
- function tokenToRegex(string, is_prepared = false) {
- if (string.match(rIsRegexp)) {
- return getRegFromString(string, true);
- }
- if (is_prepared) {
- string = prepareRegex(string, true);
- return new RegExp(string);
- }
- return string;
- }
- class ScriptRunner {
- constructor() {
- this.on = false
- this.settings = null;
- this.cur_url = window.location.href;
- }
- preLoad() {
- for (const [_, url_config] of Object.entries(config)) {
- let url_token = tokenToRegex(url_config.url, true);
- if (!url_token.test(this.cur_url)) continue;
- this.settings = url_config;
- this.on = true
- break;
- }
- }
- async prepareNewPage() {
- if (!this.on) return;
- if (this.settings.delay) {
- await delay(this.settings.delay);
- }
- if (this.settings.delete)
- this.settings.delete.forEach(e => $(e).remove());
- if (this.settings.hide)
- this.settings.hide.forEach(e => $(e).hide());
- if (this.settings.manual)
- await this.settings.manual();
- }
- async onLoad() {
- if (!this.on) return;
- this.prepareNewPage();
- this.add_scroll_event(this.settings);
- }
- add_scroll_event(settings) {
- let cls = this;
- $(window).on('scroll', async function () {
- if ($(window).scrollTop() + 2 > $(document).height() - $(window).height()) {
- await settings.next();
- }
- }).scroll();
- }
- }
- let script_runner = new ScriptRunner();
- script_runner.preLoad();
- document.readyState !== 'loading'
- ? script_runner.onLoad()
- : addEventListener("DOMContentLoaded", () => { script_runner.onLoad(); });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement