-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
144 lines (129 loc) · 4.93 KB
/
content.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
$(document).ready(() => {
console.log("content ready?");
let youtubeBtnDivName = "ytp-right-controls";
let videoFrame = document.getElementsByClassName("html5-main-video")[0];
let videoPage = document.getElementsByClassName("watch-title")[0];
if (!videoPage) {
videoPage = document.getElementsByClassName(
"ytd-video-primary-info-renderer"
)[0];
}
let initDone = false;
let btnCreated = false;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log(
sender.tab
? "from a content script:" + sender.tab.url
: "from the extension"
);
if (request.greeting == "hello")
chrome.storage.sync.get(["key"], function(result) {
console.log("Value currently is " + result.key);
var obj = { url: result.key };
name = result.key.split("=")[1];
/// get youtube id
video_id = window.location.search.split("v=")[1];
var ampersandPosition = video_id.indexOf("&");
if (ampersandPosition != -1) {
video_id = video_id.substring(0, ampersandPosition);
}
// get playtime from youtube
console.log("current id is " + video_id);
video = document.getElementsByClassName("video-stream")[0];
playtime = Math.round(video.currentTime);
console.log("current play time is " + playtime);
var youtubelink =
"https://www.youtube.com/embed/" +
video_id +
"?start=" +
playtime +
"&autoplay=1" +
"&modestbranding=1";
// chrome.storage.sync.set({youtubelink: youtubelink}, function() {
// console.log('storage youtubelink sets to ' + youtubelink);
// });
chrome.storage.local.set({ cslyoutubelink: youtubelink }, function() {
console.log("Storage cslyoutubelink Succesful");
});
// window.location.replace(result.key);
document.body.appendChild(container);
linkkk = document.createElement("link");
linkkk.href = "https://fonts.googleapis.com/icon?family=Material+Icons";
linkkk.rel = "stylesheet";
document.head.appendChild(linkkk);
document.body.appendChild(container);
$(".popup-player-container").hide();
///drag event
var $draggable = $(".draggable").draggabilly({
// options...
});
$draggable.on("dragMove", function() {
$(".popup-player").hide();
$("#close-iconss").hide();
});
$draggable.on("dragEnd", function(event, pointer) {
$(".popup-player").show();
$("#close-iconss").show();
});
///
var overlay = document.createElement("iframe");
var oStyle = overlay.style;
overlay.setAttribute("id", "player");
overlay.setAttribute("class", "popup-player");
overlay.setAttribute("src", youtubelink);
oStyle.position = "relative";
oStyle.display = "block !important";
oStyle.width = "500px";
oStyle.height = "315px";
oStyle.top = "6px";
oStyle.right = "-8.5px";
oStyle.borderRadius = "11px";
oStyle.border = "1px solid rgb(39, 147, 230)";
$(".popup-player-container").append(overlay);
var closeicon = document.createElement("i");
clostyle = closeicon.style;
clostyle.position = "relative";
clostyle.top = "-3.28in";
clostyle.right = "-5.06in";
clostyle.color = "white";
clostyle.zIndex = "9999";
clostyle.cursor = "pointer";
closeicon.setAttribute("class", "material-icons");
closeicon.setAttribute("id", "close-iconss");
closeicon.innerHTML = "clear";
$(".popup-player-container").append(closeicon);
$("body").on("click", "i#close-iconss", function() {
$("iframe.popup-player")
.get(0)
.remove();
$(".popup-player-container")
.get(0)
.remove();
$(this).remove();
localStorage.removeItem("lsyoutubelink");
chrome.storage.sync.remove(["youtubelink"], function(result) {
console.log("storage youtubelink removed");
});
});
}); //end storage get
chrome.storage.sync.remove(["key"], function(result) {
console.log("storage key removed");
});
}); //end listener
}); ///end ready
function clickminimize() {
$(".ytp-miniplayer-button").trigger("click");
}
var container = document.createElement("div");
var conStyle = container.style;
container.setAttribute("class", "popup-player-container draggable");
conStyle.width = "520px";
conStyle.height = "329px";
conStyle.position = "fixed";
conStyle.zIndex = "1000";
conStyle.display = "none";
conStyle.top = "65%";
conStyle.right = "2.2px";
conStyle.background = "linear-gradient(135deg, rgba(85,239,203,1) 0%,rgba(30,87,153,1) 0%,rgba(85,239,203,1) 0%,rgba(91,202,255,1) 100%)";
conStyle.borderRadius = "12px";
conStyle.cursor = "-webkit-grab";