-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmyscript.js
111 lines (98 loc) · 2.96 KB
/
myscript.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
$(document).ready(function() {
var youtube = ".video-stream.html5-main-video";
var netflix = ".player-video-wrapper div video";
var originalStyle = undefined;
var isEnabled = -1;
var timer = undefined;
function getData() {
chrome.storage.local.get("extensionIsEnabled",function (status){
isEnabled = status.extensionIsEnabled;
initKeyboardEvent();
initOnchangeEvent();
if(youtubeCheck()) { //youtube check
forceYoutubeDefault(isEnabled);
}else{
setData();
}
});
}
function youtubeCheck() {
if(window.location.href.indexOf("www.youtube.com") > 0) { //youtube check
return true;
}else{
return false;
}
}
function setData() {
if(isEnabled === true) {
addClass();
}else{
removeClass();
}
}
function addClass() {
$(youtube).addClass("youtubeExtraClass");//youtube
$(netflix).addClass("extraClass");//netflix
}
function removeClass() {
$(youtube).removeClass("youtubeExtraClass");
$(netflix).removeClass("extraClass");
}
function initKeyboardEvent() {
$(document).on('keydown', null, 'alt+ctrl+c',function(event) {
console.log(event);
if(isEnabled === true) {
chrome.storage.local.set({"extensionIsEnabled":false},function (){
isEnabled = false;
});
}else if(isEnabled === false){
chrome.storage.local.set({"extensionIsEnabled":true},function (){
isEnabled = true;
});
}
});
}
function initOnchangeEvent() {
chrome.storage.onChanged.addListener(function(changes, areaName){
var isNowEnabled = changes.extensionIsEnabled.newValue;
if(isNowEnabled === true) {
if(youtubeCheck()) {
forceYoutubeDefault(isNowEnabled);
}else{
addClass();
}
}else{
if(youtubeCheck()) {
forceYoutubeDefault(isNowEnabled);
}else{
removeClass();
}
}
});
}
function fullScreenCheck() {
if (document.webkitCurrentFullScreenElement != null) {
addClass();
}else{
removeClass();
}
}
function forceStyle() {
// $(youtube).attr("style", originalStyle);
}
function intervalSet() {
return setInterval(function(){
fullScreenCheck();
forceStyle();
}, 100);
}
function forceYoutubeDefault(isYoutubeEnabled) {
if(isYoutubeEnabled) {
timer = intervalSet();
}else{
clearInterval(timer);
removeClass();
}
}
getData();
});