Matemaks Paywall

Ukrywa div.center.platny_dostep_info i dodaje przycisk YouTube oraz PDF przy każdym zadaniu z atrybutem yt

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Advertisement:

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

Advertisement:

// ==UserScript==
// @name         Matemaks Paywall
// @version      1.1
// @description  Ukrywa div.center.platny_dostep_info i dodaje przycisk YouTube oraz PDF przy każdym zadaniu z atrybutem yt
// @match        *://www.matemaks.pl/*
// @license      MIT
// @grant        none
// @namespace https://greasyfork.org/users/1618843
// ==/UserScript==

(function () {
    'use strict';

    // ─── Konfiguracja ─────────────────────────────────────────────────────────
    const PDF_BASE_URL = 'https://www.matemaks.pl/notatki'; // <-- zmień na właściwy URL

    // ─── 1. Ukryj blokady dostępu ─────────────────────────────────────────────
    function hidePaywalls() {
        document.querySelectorAll('.center.platny_dostep_info').forEach(el => {
            el.style.display = 'none';
        });
    }

    // ─── 2. Styl przycisku ────────────────────────────────────────────────────
    function applyBtnStyle(btn, bgColor = '#fcfbf1') {
        Object.assign(btn.style, {
            display:    'inline-flex',
            alignItems: 'center',
            gap:        '6px',
            padding:    '2px 9px',
            margin:     '0',
            cursor:     'pointer',
            border:     '1px solid #ccc',
            background: bgColor,
            boxSizing:  'border-box',
            font:       'inherit',
        });
        btn.addEventListener('mouseenter', () => btn.style.background = '#fcfcd3');
        btn.addEventListener('mouseleave', () => btn.style.background = bgColor);
    }

    // ─── 3. Dodaj przyciski YT + PDF ─────────────────────────────────────────
    function addButtons() {
        document.querySelectorAll('.zadanie[yt]').forEach(el => {
            const ytId = el.getAttribute('yt');
            if (!ytId) return;

            // Nie dodawaj przycisków drugi raz
            if (el.querySelector('.yt-btn-injected')) return;

            // Pomiń jeśli zadanie ma już .buttons
            if (el.querySelector('.buttons')) return;

            const sek    = el.getAttribute('sek');
            const dataId = el.getAttribute('data-id') || el.getAttribute('id') || '';

            // ── Przycisk YouTube ──────────────────────────────────────────────
            const ytBtn = document.createElement('button');
            ytBtn.className = 'yt-btn-injected';
            ytBtn.innerHTML = `
                <img src="/grafika/ikony/film.svg" style="width:16px;height:16px;display:block;" onerror="this.style.display='none'">
                <span>Film</span>
            `;
            applyBtnStyle(ytBtn);

            // ── Przycisk PDF ──────────────────────────────────────────────────
            const pdfBtn = document.createElement('button');
            pdfBtn.className = 'pdf-btn-injected';

            // Numer z wiodącymi zerami, np. data-id="3740" → z3740n.pdf
            const paddedId  = dataId.padStart(4, '0');
            const pdfUrl    = `${PDF_BASE_URL}/z${paddedId}n.pdf`;

            pdfBtn.innerHTML = `
                <img src="/grafika/ikony/pisemne.svg" style="width:16px;height:16px;display:block;" onerror="this.style.display='none'">
                <span>Pdf</span>
            `;
            applyBtnStyle(pdfBtn);

            pdfBtn.addEventListener('click', () => {
                window.open(pdfUrl, '_blank');
            });

            // ── Wrapper wyśrodkowujący oba przyciski ──────────────────────────
            const btnWrapper = document.createElement('div');
            Object.assign(btnWrapper.style, {
                display:        'flex',
                justifyContent: 'center',
                width:          '100%',
                margin:         '8px auto',
            });
            // Usuń prawy border pierwszego przycisku żeby nie było podwójnej linii
            ytBtn.style.borderRight = 'none';
            btnWrapper.appendChild(ytBtn);
            btnWrapper.appendChild(pdfBtn);

            // ── Embed wrapper (YT) ────────────────────────────────────────────
            const embedWrapper = document.createElement('div');
            embedWrapper.className = 'yt-embed-wrapper';
            Object.assign(embedWrapper.style, {
                display:     'none',
                marginTop:   '8px',
                width:       '100%',
                aspectRatio: '16 / 9',
            });

            ytBtn.addEventListener('click', () => {
                const visible = embedWrapper.style.display !== 'none';
                if (visible) {
                    embedWrapper.style.display = 'none';
                    embedWrapper.innerHTML = '';
                } else {
                    const startSek = sek && sek !== '0' ? `&start=${sek}` : '';
                    const iframe = document.createElement('iframe');
                    iframe.src             = `https://www.youtube.com/embed/${ytId}?autoplay=1${startSek}`;
                    iframe.allow           = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
                    iframe.allowFullscreen = true;
                    Object.assign(iframe.style, {
                        width:   '100%',
                        height:  '100%',
                        border:  'none',
                        display: 'block',
                    });
                    embedWrapper.innerHTML = '';
                    embedWrapper.appendChild(iframe);
                    embedWrapper.style.display = 'block';
                }
            });

            el.appendChild(btnWrapper);
            el.appendChild(embedWrapper);
        });
    }

    // ─── 4. Obserwuj dynamiczne zmiany DOM ────────────────────────────────────
    function run() {
        hidePaywalls();
        addButtons();
    }

    const observer = new MutationObserver(run);
    observer.observe(document.body, { childList: true, subtree: true });

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', run);
    } else {
        run();
    }

})();