-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
97 lines (93 loc) · 3.8 KB
/
popup.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
document.addEventListener('DOMContentLoaded', function() {
var url = "https://www.youtube.com";
var watchUrl = url + "/watch?v=";
var repeatYoutube = document.getElementById('repeatYoutube');
var stopYoutube = document.getElementById('stopYoutube');
var youtubePage = document.getElementById('youtubePage');
var otherPages = document.getElementById('otherPages');
var youtubeText = document.getElementById('youtubeText');
var youtubeURL = document.getElementById('youtubeURL');
var visitYouTube = document.getElementById('visitYouTube');
/**
* Check/Validate current tab url
*/
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var activeTab = tabs[0];
if (activeTab.url.indexOf(url) > -1) {
youtubePage.style.display = "block";
otherPages.style.display = "none";
if (activeTab.url.indexOf(watchUrl) > -1) {
youtubeText.innerHTML = "Click the Repeat button to enjoy the video unlimit..";
youtubeURL.innerHTML = activeTab.url;
repeatYoutube.removeAttribute("disabled");
stopYoutube.style.display = "none";
} else {
youtubeText.innerHTML = "You are not watching any video to repeat!";
repeatYoutube.setAttribute("disabled", "disabled");
stopYoutube.style.display = "none";
}
} else {
youtubePage.style.display = "none";
otherPages.style.display = "block";
}
/**
* onLoad event handler
*/
chrome.tabs.sendMessage(activeTab.id, {
message: "popup_load",
data: {}
}, function (response) {
if (response && response.repeat && response.url === activeTab.url) {
youtubeText.innerHTML = "Repeater is running the video at _ time";
youtubeURL.innerHTML = activeTab.url;
repeatYoutube.style.display = "none";
stopYoutube.style.display = "block";
}
});
/**
* Repeat button click event handler
*/
repeatYoutube.addEventListener('click', function() {
// sent message with youTube data
chrome.tabs.sendMessage(activeTab.id, {
message: "repeat_youtube",
data: {
url: youtubeURL.innerHTML,
repeat: true
}
}, function (response) {
if (response && response.repeat) {
youtubeText.innerHTML = "This video will play unlimit.. enjoy!!";
youtubeURL.innerHTML = activeTab.url;
repeatYoutube.setAttribute("disabled", "disabled");
repeatYoutube.style.display = "none";
stopYoutube.style.display = "block";
}
});
});
/**
* Stop repeat button event handler
*/
stopYoutube.addEventListener("click", function() {
// sent message to stop repeat
chrome.tabs.sendMessage(activeTab.id, {
message: "stop_repeat",
data: {}
}, function (response) {
if (response && response.stopped) {
youtubeText.innerHTML = "Click the Repeat button to enjoy the video unlimit..";
youtubeURL.innerHTML = activeTab.url;
repeatYoutube.removeAttribute("disabled");
repeatYoutube.style.display = "block";
stopYoutube.style.display = "none";
}
});
});
});
/**
* Visit youtube button click
*/
visitYouTube.addEventListener("click", function(e) {
window.open(url, "_blank");
});
});