-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
142 lines (128 loc) · 4.85 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
//content.js
vidIDs = {cur: 0, ids: []};
// changing the logo to a turntable
turntable = "\"" + chrome.extension.getURL("icon.png") + "\"";
$(".mw-wiki-logo").css("background-image", "url(" +turntable + ")");
$('.mw-wiki-logo').height(115);
$('.mw-wiki-logo').css('background-size', '90px 90px');
$('.mw-wiki-logo').removeAttr('title');
$("<div style='padding: 15px 0px 0px 0px;text-align:center;font-size:22px;font-family: \"Crimson Text\"'><a style='display:block;width:160px;height:25px' href='https://www.wikipedia.org/'>Wiki Wiki</a></div>").insertBefore(".mw-wiki-logo");
$("<div style='padding: 0px 0px 0px 0px;text-align:center;font-size:32px;font-family: \"Crimson Text\"'><a style='display:block;width:160px;height:30px' href='https://www.wikipedia.org/'>Wikipedia</a></div>").insertBefore(".mw-wiki-logo");
// helper method that rotates the turntable icon
$.fn.animateRotate = function(angle, duration, easing, complete) {
return this.each(function() {
var $elem = $(this);
$({deg: 0}).animate({deg: angle}, {
duration: duration,
easing: easing,
step: function(now) {
$elem.css({
transform: 'rotate(' + now + 'deg)'
});
},
complete: complete || $.noop
});
});
};
// prevents page redirects on logo click
$('.mw-wiki-logo').click(function(e) {
e.preventDefault();
$('.mw-wiki-logo').animateRotate(720, 2000);
changeVideo();
});
// rotates the turntable 2160 degrees for a duration of 10000 milliseconds
$('.mw-wiki-logo').animateRotate(720, 2000);
// grabs the title of the Wikipedia article and trims out the '- Wikipedia part'
title = document.title
title = title.substring(0, title.length-12);
chrome.runtime.sendMessage({title: title, highway: "wikititle"}, function(response) {
// console.log(response.title);
});
//HERE IS THE JS FOR THE VIDEO
var tag = document.createElement('script');
tag.id = 'iframe-demo';
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('existing-iframe-example', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
document.getElementById('existing-iframe-example').style.borderColor = '#FF6D00';
}
function changeBorderColor(playerStatus) {
var color;
if (playerStatus == -1) {
color = "#37474F"; // unstarted = gray
} else if (playerStatus == 0) {
color = "#FFFF00"; // ended = yellow
} else if (playerStatus == 1) {
color = "#33691E"; // playing = green
} else if (playerStatus == 2) {
color = "#DD2C00"; // paused = red
} else if (playerStatus == 3) {
color = "#AA00FF"; // buffering = purple
} else if (playerStatus == 5) {
color = "#FF6DOO"; // video cued = orange
}
if (color) {
document.getElementById('existing-iframe-example').style.borderColor = color;
}
}
function onPlayerStateChange(event) {
changeBorderColor(event.data);
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request.highway == 'sendVidID') {
id = request.id;
setIframe(id);
}
if(request.highway == 'sendVidIDs') {
vidIDs['ids'] = request.ids;
vidIDs['cur'] = 0;
id = vidIDs['ids'][0];
setIframe(id);
}
if(request.highway == 'playclicked') {
if (request.playClickedTitle) {
$('#existing-iframe-example')[0].contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
} else {
$('#existing-iframe-example')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
}
}
}
);
function setIframe(id) {
$('#existing-iframe-example').remove();
baseURL = "https://www.youtube.com";
path = "/embed/";
queryParams = "?enablejsapi=1&autoplay=1";
youtubeIframe = $('<iframe id=\"existing-iframe-example\" \
width=\"640\" height="360" \
src=\"' + baseURL + path + id + queryParams + '\" \
frameborder="0" \
style="border: solid 4px #37474F" \
></iframe>/');
youtubeIframe.insertBefore("#footer");
$('#existing-iframe-example').hide();
}
function getNextVideoIdIndex() {
nextIndex = vidIDs['cur'] + 1;
nextIndex = vidIDs['cur'] + 1 < vidIDs['ids'].length ? nextIndex : 0;
// alert("Switching to index: " + nextIndex + " of " + vidIDs['ids'].length);
return nextIndex;
}
function changeVideo() {
nextIndex = getNextVideoIdIndex();
nextVidID = vidIDs['ids'][nextIndex]
setIframe(nextVidID);
vidIDs['cur'] = nextIndex;
// alert(nextIndex);
}