toggle

Toggles chapter's read state

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         toggle
// @namespace    https://github.com/iugastefan
// @homepage     https://github.com/iugastefan/readtoggle/raw/master/toggle.user.js
// @version      0.4
// @description  Toggles chapter's read state
// @author       Iuga Stefan
// @match        https://mangadex.org/title/*
// @grant        none
// @license      BSD 3-Clause "New" or "Revised" License
// ==/UserScript==

(function() {
    'use strict';
    var but = document.createElement("button");
    but.className="btn btn-primary";
    var sp = document.createElement("span");
    sp.className = "fas fa-eye fa-fw";
    but.appendChild(sp);
    var t = document.createTextNode(" Toggle read status for all chapters");
    if(document.getElementsByClassName("chapter_mark_read_button").length === 0 && document.getElementsByClassName("chapter_mark_unread_button").length === 0) {
        t.textContent=" You need to follow to read";
        but.disabled=true;
    }
    but.appendChild(t);
    but.style.cursor = "pointer";
    but.onclick = function() {
        var x = document.getElementsByClassName("chapter_mark_read_button");
        if (x.length !== 0) {
            Array.from(x).forEach(function(item) {
                item.click();
            });
            but.disabled=true;
            t.textContent = " Refresh to toggle again";
        } else {
            x = document.getElementsByClassName("chapter_mark_unread_button");
            if (x.length !== 0) {
                Array.from(x).forEach(function(item) {
                    item.click();
                    but.disabled=true;
                    t.textContent = " Refresh to toggle again";
                });
            } else {
                console.log("Nothing to click");
            }
        }
    };
    document.getElementsByClassName("col-lg-9 col-xl-10")[document.getElementsByClassName("col-lg-9 col-xl-10").length-1].appendChild(but);
})();