wnacg-helper

A manga helper for wnacg.com

Stan na 22-07-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         wnacg-helper
// @namespace    https://www.wnacg.com/
// @version      0.0.1
// @author       dzh
// @description  A manga helper for wnacg.com
// @license      MIT
// @icon         https://www.wnacg.com/favicon.ico
// @match        https://www.wnacg.com/*
// ==/UserScript==

(function () {
  'use strict';

  (function() {
    $(document).ready(() => {
      observerImgList();
    });
    $(window).on("load", () => {
      $(document).keydown(handleKeydownEvent);
    });
    function observerImgList() {
      const targetNode = document.getElementById("img_list");
      if (!targetNode) return;
      const observer = new MutationObserver(handleMutationCallback);
      observer.observe(targetNode, {
        childList: true,
        subtree: true
      });
    }
    function handleMutationCallback(mutationList, observer) {
      mutationList.forEach((mutation) => {
        if (mutation.type === "childList") {
          autoChangeWidth();
        }
      });
    }
    function autoChangeWidth() {
      const imgList = document.querySelectorAll("#img_list img");
      imgList.forEach((img) => {
        img.style.width = "60%";
      });
    }
    function handleKeydownEvent(e) {
      switch (e.key) {
        case "=":
          plusWidth();
          break;
        case "-":
          minusWidth();
          break;
        case "r":
          autoChangeWidth();
          break;
      }
    }
    function plusWidth() {
      const imgList = document.querySelectorAll("#img_list img");
      const plusStep = 2;
      imgList.forEach((img) => {
        const width = parseInt(img.style.width);
        img.style.width = `${width + plusStep}%`;
      });
    }
    function minusWidth() {
      const imgList = document.querySelectorAll("#img_list img");
      const minusStep = 2;
      imgList.forEach((img) => {
        const width = parseInt(img.style.width);
        if (width <= 10) return;
        img.style.width = `${width - minusStep}%`;
      });
    }
  })();

})();