-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoap.enhancer.chrome.user.js
263 lines (221 loc) · 9.74 KB
/
soap.enhancer.chrome.user.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// ==UserScript==
// @name Soap enhancer
// @author PsychodelEKS
// @contributor Daniel Apatin (https://github.com/ad/)
// @description Разные улучшалки soap4.me
// @ujs:category site: enhancements
// @ujs:published 2015-02-01 23:59:00
// @ujs:modified 2022-05-30 11:22:37
// @ujs:documentation n/a
// @ujs:https://github.com/PsychodelEKS/soap4me-userjs/
// @include http://*soap4.me/*
// @include https://*soap4.me/*
// @match https://*soap4.me/soap/*
// @match https://*soap4youand.me/soap/*
// @version 0.3.2
// @updateURL https://github.com/PsychodelEKS/soap4me-userjs/raw/master/soap.enhancer.chrome.user.js
// @run-at document-end
// @grant none
// ==/UserScript==
// version: 0.0.28 (2015-02-05 02:44:17)
// - отмечаем эпизод просмотренным после проигрывания 90%
// version: 0.0.29 (2015-02-05 02:54:23)
// - отмечаем эпизод просмотренным после проигрывания 95%
// version: 0.0.32 (2015-02-18 06:28:10)
// - фикс бага с пропаданием скролла
// version: 0.0.33 (2015-02-19 03:31:39)
// - оптимизация автозакрытия
// version: 0.0.36 (2015-03-02 18:46:00)
// - фикс работы вкладок в сериале (расписание/рецензии и т.д.)
// version: 0.1.0 (2015-05-16 00:35:19)
// - автопроигрывание следующей серии
// version: 0.1.1 (2015-05-18 01:49:58)
// - показываем галку автоплея только если есть чего играть
// version: 0.1.2 (2017-09-06 12:37:58)
// - переезд на гитхаб
// version: 0.2 (2017-09-06 18:46:28)
// - базовая версия под новый плеер
// version: 0.2.2 (2017-09-06 19:26:33)
// - фикс разрешений
// version: 0.3.1 (2019-04-22 12:58:11)
// - Снова всё работает
function exists(variable) {
return typeof(variable) != 'undefined';
}
var dbgConsole = window.console;
// var dbgConsole = false;
var cl = function (data) {
if (dbgConsole) {
dbgConsole.log(data);
}
};
var cd = function (data) {
if (dbgConsole) {
dbgConsole.dir(data);
}
};
var cj = function (data) {
cl("\n"+JSON.stringify(data, null, 4));
};
var cg = function (name) {
if (dbgConsole) {
dbgConsole.group(name);
}
};
var cgc = function (name, preventInstance) {
if (dbgConsole) {
dbgConsole.groupCollapsed(name);
}
};
var cge = function () {
if (dbgConsole) {
dbgConsole.groupEnd();
}
};
var gtf = function () {
var elem = document.getElementsByTagName("video")[0];
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
};
var al = function () {
setTimeout(function(){
if ($('#html5video').closest('.ep').next().find('.watched .yes').length > 0
&& !$('#html5video').next().is('#autoplayNextDiv')
) {
$('#html5video').after(
$("<div id='autoplayNextDiv' class='right link' style='display: flex;align-items: center;'><input type='checkbox' value='1' id='autoplayNext' style='margin-right: 5px;' /><label for='autoplayNext'>автопроигрывание</label></div>")
);
if (localStorage.autoplay) {
$('#autoplayNext').attr('checked', 'checked');
}
$("#autoplayNext").click(function () {
localStorage.autoplay = $('#autoplayNext').is(':checked');
});
}
}, 500);
};
var initScript = function (window, undefined) {
var firstRun = true;
var nextEpisodeTriggered = false;
if (firstRun) {
firstRun = false;
// дефолтное значение переменной
// cache['html5_player_go_fullscreen'] = false;
// cache['html5_player_autoplay'] = false;
}
// для автозакрытия плеера после окончания серии
window.playerClosed = 0;
// сохраним оригинал
var PlayerjsEventsOriginal = window.PlayerjsEvents;
// оверрайд для дополнительно обработки событий плеера
window.PlayerjsEvents = function (event, id, info) {
if (event != 'time') {
cl('got event: eid: '+cache['active_eid']+': '+event+(info ? ': '+info : ''));
}
if (event == "play") {
al();
}
if (event == "end") {
// cache['html5_player_autoplay']
localStorage.autoplay = $('#autoplayNext').is(':checked');
if (localStorage.autoplay && !nextEpisodeTriggered) {
cl('attempt play next');
if (localStorage.fullscreen) {
// отметим текущий эпизод просмотренным
if (cache["active_eid"]) {
$("div.watched div[data\\:eid="+cache["active_eid"]+"][data\\:watched=0]").click();
}
var playerEp = $('#player').closest('.ep');
// найдем следующий непросмотреный
var nextEpisodeLink = playerEp.is(":has(div.watched div[data\\:eid="+cache["active_eid"]+"])")
// если текущий эпизод был первым из плейлиста
? playerEp.next().find('div.play.pointer')
// если текущий эпизод был НЕ первым из плейлиста
: playerEp.nextAll(".ep:has(div.watched div[data\\:eid="+cache["active_eid"]+"]):first")
.nextAll('.ep:has(div.watched div[data\\:watched=0]):first')
.find('div.play.pointer');
if (nextEpisodeLink) {
nextEpisodeTriggered = true;
var eid = nextEpisodeLink.attr("data:eid"),
episode = nextEpisodeLink.attr("data:episode"),
sid = nextEpisodeLink.attr("data:sid"),
hash = nextEpisodeLink.attr("data:hash");
cl('next eid:'+eid);
if (eid) {
hash = $.md5($.token()+eid+sid+hash);
var previousEid = cache["active_eid"];
cache["active_eid"] = eid;
$.ajax({
url: "/api/v2/play/episode/"+eid,
type: "post",
headers: {
"x-api-token": $.token(),
"x-user-agent": "browser: public v0.1"
},
data: {
eid: eid,
hash: hash
},
async: false,
dataType: "json",
success: function (json) {
if (!json.ok) {
cl('can not get next episode stream url');
return;
}
cache["html5_player"+cache['active_eid']] = cache["html5_player"+previousEid];
cache["html5_player"+cache['active_eid']].api('play', json.stream);
cache["html5_player"+cache['active_eid']].api('title', json.title);
nextEpisodeTriggered = false;
}
});
}
} else {
cl('could not find next episode link');
cache["html5_player"+cache['active_eid']].api('exitfullscreen');
}
} else {
$('#html5video').closest('.ep').next().find('div.play.pointer').click();
}
}
}
if (event == "init") {
cl('play on init ('+exists(cache["html5_player"+cache['active_eid']])+')');
var initPlayInterval = false;
initPlayInterval = setInterval(function(){
if (exists(cache["html5_player"+cache['active_eid']])) {
clearInterval(initPlayInterval);
initPlayInterval = false;
cl(' playing');
cache["html5_player"+cache['active_eid']].api("play");
setTimeout(function(){
cache["html5_player"+cache['active_eid']].api("unmute");
}, 500);
if (localStorage.fullscreen) {
setTimeout(function(){
cache["html5_player"+cache['active_eid']].api("fullscreen");
gtf();
}, 1000);
}
}
}, 50);
}
if (event == "fullscreen") {
localStorage.fullscreen = true;
}
if (event == "exitfullscreen") {
localStorage.fullscreen = false;
}
PlayerjsEventsOriginal(event, id, info);
};
$("#episodes .player, #episodes .play, #new .play").click(function(){
al()
});
return true;
};
initScript(window);