1 function myFunction(){

2        console.log('asd');

3

4       chrome.tabs.query(

5            { active: true, windowId: chrome.windows.WINDOW_ID_CURRENT, currentWindow: true},

6            function(tabs) {

7

8                var tab = tabs[0];

9                var tab_title = tab.title;

10                const { id: tabId } = tabs[0].url;

11

12

13                let code = `document.getElementsByClassName('cue-group style-scope ytd-transcript-body-renderer')`;

14 

15

16                chrome.tabs.executeScript(tabId, { code }, send_mainPart);

17

18            }

19        );

20 }


21 function send_mainPart(result){
22
23        
24        var main = result[5].textContent;
25        
26        alert(main);
27
28        document.getElementById('main-part').innerHTML = "<p>" + main + "</p>";
29
30        
31 }


일단 코드를 이렇게 짜봤는데 막상 돌려보면 undefinded라고 에러가 뜨네...



13번 줄에 

 let code = `document.getElementsByClassName('cue-group style-scope ytd-transcript-body-renderer')[5].textContent`;

이렇게 안하는 이유는 저 배열 다 순회해야되가지고 배열 자체를 넘기고 싶음...


그리고

chrome.tabs.executeScript(tabId, { code }, send_mainPart);

이부분은 아무리 봐도 어떻게 동작하는지 모르겠다... 망할 함수형 


망할 js