쿠팡플레이 URL 필터 버튼

Adds MOVIE and TVSHOW filter buttons to Coupang Play's titles page, and dynamically shows/hides them based on the URL.

当前为 2025-07-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         쿠팡플레이 URL 필터 버튼
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds MOVIE and TVSHOW filter buttons to Coupang Play's titles page, and dynamically shows/hides them based on the URL.
// @author       DongHaerang
// @match        *://*.coupangplay.com/titles*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // --- 스타일 정의 (한 번만 실행) ---
    const styles = `
        #filter-button-container {
            position: fixed;
            top: 0px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 9999;
            display: flex;
            gap: 10px;
        }
        .filter-btn {
            background-color: #0073e6;
            color: white;
            border: none;
            padding: 0px 5px;
            border-radius: 5px;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.2s;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .filter-btn:hover {
            background-color: #005bb5;
        }
        #copy-notification {
            position: fixed;
            /* ✨ 변경된 부분: 버튼 아래에 위치하도록 top 값을 조정 */
            top: 60px;
            left: 50%;
            /* ✨ 변경된 부분: 수평 중앙 정렬만 유지 */
            transform: translateX(-50%);
            background-color: rgba(0, 0, 0, 0.75);
            color: white;
            padding: 15px 30px;
            border-radius: 8px;
            z-index: 10000;
            font-size: 16px;
            opacity: 0;
            transition: opacity 0.3s ease-in-out;
            pointer-events: none;
            max-width: 90%;
            word-break: break-all;
            text-align: center;
        }
    `;

    const styleSheet = document.createElement("style");
    styleSheet.innerText = styles;
    document.head.appendChild(styleSheet);

    // --- 버튼 클릭 및 알림 기능 ---
    function showNotification(message) {
        const existingNotification = document.getElementById('copy-notification');
        if (existingNotification) return;

        const notification = document.createElement('div');
        notification.id = 'copy-notification';
        notification.textContent = message;
        document.body.appendChild(notification);

        setTimeout(() => { notification.style.opacity = '1'; }, 10);
        setTimeout(() => {
            notification.style.opacity = '0';
            setTimeout(() => { notification.remove(); }, 300);
        }, 2500);
    }

    function handleButtonClick(type) {
        const baseUrl = window.location.href.split('?')[0];
        const newUrl = `${baseUrl}?type=${type}`;

        navigator.clipboard.writeText(newUrl).then(() => {
            showNotification(`'${newUrl}'이(가) 저장되었습니다.`);
        }).catch(err => {
            console.error('클립보드 복사 실패:', err);
            showNotification('복사에 실패했습니다.');
        });
    }

    // --- 버튼을 생성하는 함수 ---
    function createButtons() {
        if (document.getElementById('filter-button-container')) return;

        const container = document.createElement('div');
        container.id = 'filter-button-container';

        const movieButton = document.createElement('button');
        movieButton.textContent = 'MOVIE';
        movieButton.className = 'filter-btn';
        movieButton.addEventListener('click', () => handleButtonClick('MOVIE'));

        const tvshowButton = document.createElement('button');
        tvshowButton.textContent = 'TVSHOW';
        tvshowButton.className = 'filter-btn';
        tvshowButton.addEventListener('click', () => handleButtonClick('TVSHOW'));

        container.appendChild(movieButton);
        container.appendChild(tvshowButton);
        document.body.appendChild(container);
    }

    // --- 주기적으로 URL을 확인하여 버튼을 표시/숨김 ---
    function checkUrlAndToggleButtons() {
        const shouldShow = window.location.href.includes('coupangplay.com/titles');
        const container = document.getElementById('filter-button-container');

        if (shouldShow) {
            if (!container) {
                createButtons();
            }
        } else {
            if (container) {
                container.remove();
            }
        }
    }

    // 0.5초마다 URL 검사 함수를 실행
    setInterval(checkUrlAndToggleButtons, 500);

})();