Matemaks Paywall

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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();
    }

})();