YouTube Take Notes Popup

Opens Take Notes in a popup window when clicked

Size

3.4 KB

Version

1.0.1

Created

Jan 1, 2026

Updated

21 days ago

1// ==UserScript==
2// @name		YouTube Take Notes Popup
3// @description		Opens Take Notes in a popup window when clicked
4// @version		1.0.1
5// @match		https://*.youtube.com/*
6// @icon		https://www.youtube.com/s/desktop/a3c20ab4/img/favicon_32x32.png
7// ==/UserScript==
8(function() {
9    'use strict';
10    
11    console.log('YouTube Take Notes Popup extension loaded');
12    
13    function debounce(func, wait) {
14        let timeout;
15        return function executedFunction(...args) {
16            const later = () => {
17                clearTimeout(timeout);
18                func(...args);
19            };
20            clearTimeout(timeout);
21            timeout = setTimeout(later, wait);
22        };
23    }
24    
25    function interceptTakeNotesButton() {
26        const takeNoteBtn = document.querySelector('#edit-btn.ytp-button.ytp-screenshot');
27        
28        if (takeNoteBtn && !takeNoteBtn.dataset.popupIntercepted) {
29            console.log('Take Notes button found, adding popup interceptor');
30            
31            // 기존 클릭 이벤트를 가로채기
32            takeNoteBtn.addEventListener('click', function(e) {
33                e.preventDefault();
34                e.stopPropagation();
35                e.stopImmediatePropagation();
36                
37                console.log('Take Notes button clicked - opening popup');
38                
39                // 현재 비디오 URL 가져오기
40                const videoUrl = window.location.href;
41                const videoId = new URLSearchParams(window.location.search).get('v');
42                
43                // 팝업 창 열기 (800x600 크기)
44                const popupWidth = 800;
45                const popupHeight = 600;
46                const left = (screen.width - popupWidth) / 2;
47                const top = (screen.height - popupHeight) / 2;
48                
49                const popupWindow = window.open(
50                    videoUrl,
51                    'TakeNotesPopup',
52                    `width=${popupWidth},height=${popupHeight},left=${left},top=${top},resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,status=no`
53                );
54                
55                if (popupWindow) {
56                    popupWindow.focus();
57                    console.log('Popup window opened successfully');
58                } else {
59                    console.error('Failed to open popup - popup blocker may be active');
60                    alert('팝업이 차단되었습니다. 팝업 차단을 해제해주세요.');
61                }
62                
63                return false;
64            }, true); // useCapture = true로 설정하여 다른 리스너보다 먼저 실행
65            
66            takeNoteBtn.dataset.popupIntercepted = 'true';
67        }
68    }
69    
70    // DOM 변경 감지
71    const observer = new MutationObserver(debounce(() => {
72        interceptTakeNotesButton();
73    }, 300));
74    
75    function init() {
76        console.log('Initializing YouTube Take Notes Popup');
77        
78        // 초기 실행
79        interceptTakeNotesButton();
80        
81        // DOM 변경 감지 시작
82        observer.observe(document.body, {
83            childList: true,
84            subtree: true
85        });
86        
87        console.log('Observer started');
88    }
89    
90    // 페이지 로드 완료 후 실행
91    if (document.readyState === 'loading') {
92        document.addEventListener('DOMContentLoaded', init);
93    } else {
94        init();
95    }
96    
97})();