Shikimori comments loader

Load 100 comments instead of the standard 20

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Shikimori comments loader
// @name:ru      Загрузчик комментариев Shikimori
// @namespace    https://shikimori.org/
// @version      0.9
// @description  Load 100 comments instead of the standard 20
// @description:ru Загружает 100 комментариев вместо 20 стандартных на Shikimori
// @author       BoberMod
// @match        https://*.shikimori.org/*
// @match        https://shikimori.one/*
// @match        https://shikimori.me/*
// @grant        none
// ==/UserScript==

// Settings
// СКОЛЬКО КОММЕНТАРИЕВ ЗАГРУЖАТЬ ЗА 1 РАЗ
const commentsPerClick = 100; //НЕ СТОИТ ДЕЛАТЬ ЗНАЧЕНИЕ БОЛЬШЕ 150-200!

function change() {
    "use strict";

    let loader = document.getElementsByClassName("comments-loader")[0];
    if (!loader) { return false; }
    
    let numberOfComments = loader.getAttribute("data-count");
    let skipLink = loader.getAttribute("data-clickloaded-url-template").replace(/SKIP\/\d{1,2}/g, `SKIP/${commentsPerClick}`);

    loader.setAttribute("data-limit", commentsPerClick);
    loader.setAttribute("data-clickloaded-url-template", skipLink);

    if (numberOfComments <= commentsPerClick) {
        loader.innerText = `Загрузить ${numberOfComments} из ${numberOfComments} комментариев`;
    }
    else {
        loader.innerText = `Загрузить ещё ${commentsPerClick} из ${numberOfComments} комментариев`;
    }
}

function onload(fn) {
    document.addEventListener('page:load', fn);
    document.addEventListener('turbolinks:load', fn);

    if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
        fn();
    } else {
        document.addEventListener('DOMContentLoaded', fn);
    }
}

onload(change);