Change a card size in darkino

Supprimer les styles en ligne des images et ajuster la taille et la marge des cartes sur une page web

目前為 2023-04-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Change a card size in darkino
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Supprimer les styles en ligne des images et ajuster la taille et la marge des cartes sur une page web
// @author       Mtx1
// @match        https://www2.darkino.net/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    const images = document.querySelectorAll('img[loading="lazy"]');
    const cards = document.querySelectorAll('.home-page-categories .videos .video-list.short, .video-latest-list.video-wrapper.short');

    function removeImageInlineStyles() {
        for (let img of images) {
            img.removeAttribute('style');
        }
    }

    function resizeCards(size) {
        for (let card of cards) {
            card.style.width = size + 'px';
        }
    }

    function adjustCardMargin(margin) {
        for (let card of cards) {
            card.style.margin = margin + 'px';
        }
    }

    const slider = document.createElement('input');
    slider.type = 'range';
    slider.min = '100';
    slider.max = '300';
    slider.value = localStorage.getItem('cardSize') || '300';
    slider.style.marginLeft = '10px';

    const valueDisplay = document.createElement('span');
    const percentage = Math.round((((slider.value - 100) / 200) * 100));
    valueDisplay.textContent = `${percentage}%`;
    valueDisplay.style.marginLeft = '5px';

    slider.addEventListener('input', (event) => {
        const size = parseInt(event.target.value);
        const percentage = Math.round(((size - 100) / 200) * 100);
        valueDisplay.textContent = `${percentage}%`;
        resizeCards(size);
        adjustCardMargin(size / 10);
        localStorage.setItem('cardSize', size);
    });

    const container = document.querySelector('.flex.justify-center.p-6');
    container.appendChild(slider);
    container.appendChild(valueDisplay);

    removeImageInlineStyles();

    const savedCardSize = localStorage.getItem('cardSize');
    if (savedCardSize) {
        resizeCards(savedCardSize);
        adjustCardMargin(savedCardSize / 10);
    }
})();