-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
47 lines (38 loc) · 1.34 KB
/
content.js
File metadata and controls
47 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
console.log("This is YM content!")
function getCurrentTrackInfo() {
const titleElement = document.querySelector('ytmusic-player-bar .title');
const artistElement = document.querySelector('ytmusic-player-bar .byline');
if (titleElement && artistElement) {
const title = titleElement.textContent;
const artistFull = artistElement.textContent;
const artist = artistFull.split('•')[0].trim();
chrome.runtime.sendMessage({
type: 'TRACK_INFO',
title: title,
artist: artist
});
return true;
} else {
console.log('[SyncManager]: 제목 또는 아티스트 요소를 찾을 수 없습니다.');
return false;
}
}
function getCurrentPlaybackTime() {
const timeElement = document.querySelector("#left-controls > span");
if (timeElement) {
const currentTime = timeElement.innerText.split(" / ")[0].trim();
// console.log(`Current time: ${currentTime}`);
chrome.runtime.sendMessage({
type: 'PLAYBACK_TIME',
currentTime: currentTime
});
} else {
console.log('[SyncManager]: 재생 시각 요소를 찾을 수 없습니다.');
}
}
setInterval(() => {
getCurrentTrackInfo();
}, 500);
setInterval(() => {
getCurrentPlaybackTime();
}, 100); // 1초 간격으로 업데이트