-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopup.js
More file actions
146 lines (107 loc) · 3.93 KB
/
popup.js
File metadata and controls
146 lines (107 loc) · 3.93 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
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
145
146
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var endUrl;
var nextEpisode = true;
var nextSeason = false;
var epNum;
var seNum;
var nextEp;
var nextSe;
function navigate(url1, url2)
{
// Creates an object which can read files from the server
var reader = new XMLHttpRequest();
var checkFor = url1;
// Opens the file and specifies the method (get)
// Asynchronous is true
reader.open('get', checkFor, true);
//check each time the ready state changes
//to see if the object is ready
reader.onreadystatechange = checkReadyState;
function checkReadyState() {
if (reader.readyState === 4) {
//check to see whether request for the file failed or succeeded
if ((reader.status == 200) || (reader.status == 0)) {
chrome.tabs.update({
url: url1
});
if (nextEpisode)
{
document.getElementById("check").innerHTML = "Next episode! S"+formatNum(seNum)+"E"+formatNum(nextEp)+" 👌<br/><a href='"+endUrl+"' target='_blank'>See all episodes</a>";
document.getElementById("check").style.color = "green";
}
else if (nextSeason)
{
document.getElementById("check").innerHTML = "Next season! S"+formatNum(nextSe)+"E01 👌<br/><a href='"+endUrl+"' target='_blank'>See all episodes</a>";
document.getElementById("check").style.color = "green";
}
else
{
document.getElementById("check").innerHTML = "<b>Series completed!</b>";
document.getElementById("check").style.color = "green";
}
}
else {
if (nextEpisode)
{
nextSeason = true;
nextEpisode = false;
}
else if (nextSeason)
nextSeason = false;
navigate(url2, endUrl);
return;
}
}//end of if (reader.readyState === 4)
}// end of checkReadyState()
// Sends the request for the file data to the server
// Use null for "get" mode
reader.send(null);
}
function formatNum(num)
{
var n = parseInt(num);
if (n < 10)
return "0"+n;
return n;
}
function gotoPutlocker(target)
{
chrome.tabs.update({
url: "http://www.putlockers.ch"
});
}
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.getSelected(null, function(tab) {
var url = tab.url;
if (url.substring(7,20) == "putlockers.ch")
{
if (url.indexOf("-season-") * url.indexOf("-episode-") >= 0)
{
// indices of episode and season numbers
var epNumIndex = url.indexOf("-episode-")+"-episode-".length;
var seNumIndex = url.indexOf("-season-")+"-season-".length;
// the actual episode and season numbers
epNum = url.substring(epNumIndex, url.indexOf("-",epNumIndex));
seNum = url.substring(seNumIndex, url.indexOf("-",seNumIndex));
nextEp = parseInt(epNum)+1;
nextSe = parseInt(seNum)+1;
// final URLs of next episode and next season
var nextEpURL = url.substring(0, epNumIndex) + nextEp + url.substring(url.indexOf("-",epNumIndex), url.length);
var nextSeURL = url.substring(0, seNumIndex) + nextSe + "-episode-1"+url.substring(url.indexOf("-",epNumIndex), url.length);
// if there is no next season
endUrl = url.substring(0, url.indexOf("-tvshow")+"-tvshow".length) + url.substring(url.indexOf("-online-"));
console.log("endURL: "+endUrl);
navigate(nextEpURL, nextSeURL);
document.getElementById("check").innerHTML = "All good 👌";
document.getElementById("check").style.color = "green";
}
}
else
{
document.getElementById("check").innerHTML = "Not putlockers.ch 👎<br/><a href='http://www.putlockers.ch' target='_blank'>Go there now</a>";
document.getElementById("check").style.color = "red";
}
});
}, false);