-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-iwara-player.user.js
More file actions
103 lines (94 loc) · 3.66 KB
/
replace-iwara-player.user.js
File metadata and controls
103 lines (94 loc) · 3.66 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
// ==UserScript==
// @name 替换 iwara 播放器
// @namespace https://github.com/s0urcelab/userscripts
// @version 1.1
// @description 修复iwara播放器加载源错误问题
// @match https://www.iwara.tv/video/*
// @require https://fastly.jsdelivr.net/npm/[email protected]/browser/index.min.js
// @icon https://www.iwara.tv/logo.png
// @author s0urce
// @license MIT
// ==/UserScript==
; (function () {
'use strict';
// const css=`
// .videoPlayer {
// display: none !important;
// }
// `
// GM_addStyle(css)
// Save the original fetch function
const originalFetch = window.fetch;
// Create a new fetch function that wraps the original one
function newFetch(...args) {
const [url] = args
return originalFetch(...args).then(response => {
if (url.includes('files.iwara.tv/file')) {
response.clone().json().then(json => {
const { src: { view: videoSrc } } = json.find(v => v.name === 'Source')
console.warn(`当前播放资源url:${videoSrc}`)
window.videoSrc = videoSrc
})
}
return response;
});
}
// Replace the original fetch function with our new one
window.fetch = newFetch;
const targetNode = document.getElementById('app');
const observerOptions = {
childList: true,
subtree: true,
};
function callback(mutationList, observer) {
mutationList.forEach((mutation) => {
switch (mutation.type) {
case 'childList':
for (let node of mutation.addedNodes) {
if (node.className === 'videoPlayer') {
node.style.display = 'none'
document.querySelector(".page-video__player").style.maxHeight = 'none'
// append container for xgplayer
const playCon = document.createElement("div")
playCon.id = 'xgplayer'
node.parentNode.appendChild(playCon)
window.xg = new window.Player({
id: 'xgplayer',
url: window.videoSrc,
volume: 1,
fluid: true,
videoInit: true,
})
observer.disconnect()
}
}
break;
}
});
}
const observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
// function checkAndReplace() {
// const originContainer = document.querySelector(".videoPlayer");
// if (originContainer) {
// originContainer.style.display = 'none'
// document.querySelector(".page-video__player").style.maxHeight = 'none'
// // append container for xgplayer
// const playCon = document.createElement("div")
// playCon.id = 'xgplayer'
// originContainer.parentNode.appendChild(playCon)
// window.xg = new window.Player({
// id: 'xgplayer',
// url: window.videoSrc,
// volume: 1,
// fluid: true,
// videoInit: true,
// })
// } else {
// // If the element doesn't exist yet, try again in 500ms
// setTimeout(checkAndReplace, 500);
// }
// }
// Start checking for the element
// checkAndReplace();
})();