-
Notifications
You must be signed in to change notification settings - Fork 34
/
iframeWebFull.user.js
124 lines (118 loc) · 2.99 KB
/
iframeWebFull.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
// ==UserScript==
// @name 框架网页全屏
// @namespace iframeWebFull.xinggsf
// @version 0.3.1
// @description iframe网页全屏
// @author xinggsf
// @match https://ikandy.fun/vodplay/*
// @noframes
// @run-at document-body
// @grant GM_addStyle
// ==/UserScript==
(function(doc, by) {
'use strict';
const q = (css, p = doc) => p.querySelector(css);
const goNextMV = () => {
const s = location.pathname;
const m = s.match(/(\d+)(\D*)$/);
const d = +m[1] + 1;
location.assign(s.slice(0, m.index) + d + m[2]);
};
const getMainDomain = host => {
const a = host.split('.');
let i = a.length - 2;
if (/^(com?|cc|tv|net|org|gov|edu)$/.test(a[i])) i--;
return a[i];
};
const u = getMainDomain(location.hostname);
const doClick = e => {
if (typeof e === 'string') e = q(e);
if (e) { e.click ? e.click() : e.dispatchEvent(new MouseEvent('click')) };
};
class FullPage {
constructor(frm, onSwitch = null) {
this._onSwitch = onSwitch;
this.frame = frm;
GM_addStyle(
`.gm-fp-body .gm-fp-zTop {
position: relative !important;
z-index: 2147483647 !important;
}
.gm-fp-wrapper, .gm-fp-body{ overflow:hidden !important; }
.gm-fp-wrapper {
display: block !important;
position: fixed !important;
width: 100% !important;
height: 100% !important;
top: 0 !important;
left: 0 !important;
background: #000 !important;
z-index: 2147483647 !important;
}`
);
}
static isFull() {
return by.classList.contains('gm-fp-body');
}
toggle() {
this._onSwitch?.(this);
by.classList.toggle('gm-fp-body');
this.frame.classList.toggle('gm-fp-wrapper');
let e = this.frame.parentNode;
while (e != by) {
e.classList.toggle('gm-fp-zTop');
e = e.parentNode;
}
}
}
const config = {
olevod: {
nextCSS: 'i.next-p'
},
ikandy: {
nextCSS: 'ul.more-btn li:last-child a'
}
};
// const origin = config[u]?.origin || '/';
let ffp, mvWin, topFrame;
window.addEventListener("message", ev => {
if (!ev.source || !ev.data?.id) return;
switch (ev.data.id) {
case 'gm-h5-init-MVframe':
mvWin = ev.source;
topFrame = [...doc.getElementsByTagName('iframe')]
.find(e => e.allowfullscreen || e.offsetWidth > 99);
ffp = new FullPage(topFrame);
break;
case 'gm-h5-toggle-iframeWebFull':
ffp.toggle();
break;
case 'gm-h5-is-iframeWebFull': //响应子框架的ESC按键
FullPage.isFull() && ffp.toggle();
break;
case 'gm-h5-play-next':
config[u]?.nextCSS ? doClick(config[u].nextCSS) : goNextMV();
}
}, false);
by.addEventListener('keydown', ev => {
if (!ffp) return;
switch (ev.keyCode) {
case 78: // N 下一集
config[u]?.nextCSS ? doClick(config[u].nextCSS) : goNextMV();
break;
case 13: //回车键。 全屏
if (ev.shiftKey) {
ffp.toggle();
} else {
mvWin.postMessage({id: 'gm-h5-toggle-fullScreen'}, '*');
}
break;
case 27: //esc
if (doc.fullscreen) {
mvWin.postMessage({id: 'gm-h5-toggle-fullScreen'}, '*');
} else if (FullPage.isFull()) {
ffp.toggle();
}
}
});
})(document, document.body);