cursor初体验摸鱼视频播放器

[up主专用,视频内嵌代码贴在这]

  • 刚试用了下cursor,我不会代码,但是还是一步步提问给整出来了,欢迎使用~

功能:

  • // 在网页【左下角】添加视频播放器,自动播放【XJJ】视频,

  • 右上角开启【自动】,解放双手,

  • 右下角【白色块】可调整大小,

  • 拖动视频可以移动位置,

  • 【切换源】换源。

  • 如果有更加精彩的小姐姐API也可以留言叫我加入(目前只有3个视频源

  • 我不会代码,想改的也可以把代码直接贴进cursor让它给改- -!

  • cursor还是挺好玩的.

本教程用到 Win10 电脑 和 篡改猴 (Tampermonkey) 浏览器插件

0a7357cd467b4d30e87bd.png
0e0ae2e543368da6f8365.png
684d3a24a16c30fcfa75a.png
8390ea2388b400fe04c42.png
image.png
image.png

image.png

image.png

image.png

image.png

image.png

image.png

源码

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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// ==UserScript==
// @name 摸鱼视频播放器(cursor版)
// @namespace http://tampermonkey.net/
// @version 1.17
// @description 在网页【左下角】添加视频播放器,自动播放【XJJ】视频,右上角开启【自动】,解放双手,右下角【白色块】可调整大小,拖动视频可以移动位置
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==

(function() {
'use strict';

// 常量定义
const DEFAULT_WIDTH = '225px';
const DEFAULT_HEIGHT = '400px';
const LARGE_WIDTH = '450px';
const LARGE_HEIGHT = '800px';
const SMALL_WIDTH = '112.5px';
const SMALL_HEIGHT = '200px';
const HIDE_CONTROLS_DELAY = 3000;

const apiList = [
{ name: '颜值视频', url: 'https://sp.4n2.cn/?api=bianzhuang&type=json' },
{ name: '小姐姐视频', url: 'https://api.kuleu.com/api/xjj?type=json' },
{ name: '随机视频', url: 'https://sp.4n2.cn/?api=sw&type=json' }
];

let currentSourceIndex = 0;
let autoMode = false; // 确保初始状态为关闭
let videoHistory = [];
let historyIndex = -1;
let isDragging = false;
let isResizing = false;
let offsetX, offsetY, startWidth, startHeight;
let hideControlsTimeout;

// 样式定义
GM_addStyle(`
#fishPlayer {
position: fixed;
left: 10px;
bottom: 10px;
z-index: 9999;
display: none;
cursor: default;
border-radius: 10px; // 添加圆角
overflow: hidden; // 确保内容不超出圆角
}
#fishToggle {
position: fixed;
left: 10px;
bottom: 10px;
z-index: 10000;
background: transparent;
color: white;
border: 1px solid black;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
}
#fishVideo {
width: 100%;
height: 100%;
background: black;
position: relative;
border-radius: 10px; // 为视频添加圆角
}
#fishControls, #fishSizeControls, #fishSource {
display: none;
}
#fishControls {
position: absolute;
top: 0;
left: 0;
width: 100%;
display: flex;
justify-content: space-between;
padding: 5px;
box-sizing: border-box;
}
#fishLeftControls, #fishRightControls {
display: flex;
flex-direction: column;
}
#fishSizeControls {
display: none; // 隐藏大中小按钮
}
#fishSwitch, #fishRetry, #fishAuto, .sizeBtn {
background: transparent;
color: white;
border: 1px solid white;
padding: 5px;
border-radius: 5px;
cursor: pointer;
margin-bottom: 5px;
pointer-events: auto;
}
#fishSource {
font-size: 12px;
text-align: center;
color: white;
}
#resizeHandle {
position: absolute;
width: 15px;
height: 15px;
background: rgba(255, 255, 255, 0.5);
right: 0;
bottom: 0;
cursor: nwse-resize;
}
`);

// HTML模板
const playerHtml = `
<div id="fishPlayer" style="display: none;">
<video id="fishVideo" controls autoplay></video>
<div id="fishControls">
<div id="fishLeftControls">
<button id="fishSwitch">切换源</button>
<button id="fishRetry">重试源</button>
<div id="fishSource"></div>
</div>
<div id="fishRightControls">
<button id="fishAuto">自动:关</button>
<!-- 大中小按钮已被注释掉,但保留代码以便将来使用 -->
<!--
<button class="sizeBtn" id="sizeLarge">大</button>
<button class="sizeBtn" id="sizeDefault">中</button>
<button class="sizeBtn" id="sizeSmall">小</button>
-->
</div>
</div>
<div id="resizeHandle"></div>
</div>
<button id="fishToggle">XJJ</button>
`;

document.body.insertAdjacentHTML('beforeend', playerHtml);

// DOM元素
const toggle = document.getElementById('fishToggle');
const player = document.getElementById('fishPlayer');
const video = document.getElementById('fishVideo');
const resizeHandle = document.getElementById('resizeHandle');
const switchBtn = document.getElementById('fishSwitch');
const retryBtn = document.getElementById('fishRetry');
const autoBtn = document.getElementById('fishAuto');
const sourceDiv = document.getElementById('fishSource');
const controls = document.querySelectorAll('#fishControls, #fishSizeControls, #fishSource');

// 功能函数
function setPlayerSize(width, height) {
player.style.width = width;
player.style.height = height;
video.style.width = '100%';
video.style.height = '100%';
}

let videoCache = []; // 用于存储视频 URL 的缓存
let currentVideoIndex = -1; // 当前视频在缓存中的索引

function loadVideo(direction = 'next', switchSource = false) {
if (switchSource) {
currentSourceIndex = (currentSourceIndex + 1) % apiList.length;
videoCache = [];
currentVideoIndex = -1;
}

sourceDiv.textContent = `当前源: ${apiList[currentSourceIndex].name}`;

if (direction === 'previous' && currentVideoIndex > 0) {
currentVideoIndex--;
playVideo(videoCache[currentVideoIndex]);
return;
}

if (direction === 'next' && currentVideoIndex < videoCache.length - 1) {
currentVideoIndex++;
playVideo(videoCache[currentVideoIndex]);
return;
}

GM_xmlhttpRequest({
method: 'GET',
url: apiList[currentSourceIndex].url,
onload: function(response) {
let videoUrl;
try {
const data = JSON.parse(response.responseText);
videoUrl = data.url || data.video || (data.data && data.data.url);
} catch (e) {
videoUrl = response.responseText.trim();
}
if (videoUrl && videoUrl.startsWith('http')) {
if (direction === 'next') {
videoCache = videoCache.slice(0, currentVideoIndex + 1);
videoCache.push(videoUrl);
currentVideoIndex = videoCache.length - 1;
}
playVideo(videoUrl);
} else {
console.error('无效的视频URL:', videoUrl);
sourceDiv.textContent += ' (加载失败)';
loadVideo(direction, switchSource); // 加载失败时重试
}
},
onerror: function(error) {
console.error('请求失败:', error);
sourceDiv.textContent += ' (请求失败)';
loadVideo(direction, switchSource); // 请求失败时重试
}
});
}

function playVideo(videoUrl) {
video.src = videoUrl;
video.play().catch(e => console.error('视频播放失败:', e));
updateVideoHistory(videoUrl);
}

function updateVideoHistory(videoUrl) {
if (historyIndex === videoHistory.length - 1) {
videoHistory.push(videoUrl);
} else {
videoHistory = videoHistory.slice(0, historyIndex + 1);
videoHistory.push(videoUrl);
}
historyIndex = videoHistory.length - 1;
}

function loadNextVideo() {
loadVideo('next');
}

function loadPreviousVideo() {
loadVideo('previous');
}

function switchSource() {
loadVideo('next', true);
}

// 修改 toggle 按钮的事件监听器
toggle.addEventListener('click', () => {
if (player.style.display === 'none') {
player.style.display = 'block';
if (!video.src) {
loadVideo();
} else {
video.play().catch(e => console.error('视频播放失败:', e));
}
} else {
player.style.display = 'none';
video.pause();
}
});

switchBtn.addEventListener('click', switchSource);
retryBtn.addEventListener('click', loadVideo);

autoBtn.addEventListener('click', () => {
autoMode = !autoMode;
autoBtn.textContent = `自动:${autoMode ? '开' : '关'}`;
console.log('自动播放模式:', autoMode ? '开启' : '关闭'); // 添加日志
});

video.addEventListener('ended', () => {
console.log('视频播放结束'); // 添加日志
if (autoMode) {
console.log('自动播放模式开启,加载下一个视频'); // 添加日志
loadNextVideo();
}
});

video.addEventListener('wheel', (event) => {
event.preventDefault();
if (event.deltaY > 0) {
loadNextVideo();
} else {
loadPreviousVideo();
}
});

player.addEventListener('mouseenter', () => {
clearTimeout(hideControlsTimeout);
controls.forEach(control => control.style.display = 'flex');
});

player.addEventListener('mouseleave', () => {
hideControlsTimeout = setTimeout(() => {
controls.forEach(control => control.style.display = 'none');
}, HIDE_CONTROLS_DELAY);
});

player.addEventListener('mousedown', (event) => {
if (event.target === resizeHandle) {
isResizing = true;
startWidth = player.offsetWidth;
startHeight = player.offsetHeight;
offsetX = event.clientX;
offsetY = event.clientY;
event.preventDefault();
} else if (!event.target.closest('button')) {
isDragging = true;
offsetX = event.clientX - player.offsetLeft;
offsetY = event.clientY - player.offsetTop;
event.preventDefault();
}
});

document.addEventListener('mousemove', (event) => {
if (isDragging) {
player.style.left = `${event.clientX - offsetX}px`;
player.style.top = `${event.clientY - offsetY}px`;
} else if (isResizing) {
const newWidth = Math.max(100, startWidth + (event.clientX - offsetX));
const newHeight = Math.max(100, startHeight + (event.clientY - offsetY));
setPlayerSize(`${newWidth}px`, `${newHeight}px`);
}
});

document.addEventListener('mouseup', () => {
isDragging = false;
isResizing = false;
});

// 使用事件委托处理大小调整按钮
document.getElementById('fishRightControls').addEventListener('click', (event) => {
if (event.target.classList.contains('sizeBtn')) {
switch(event.target.id) {
case 'sizeLarge':
setPlayerSize(LARGE_WIDTH, LARGE_HEIGHT);
break;
case 'sizeDefault':
setPlayerSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
break;
case 'sizeSmall':
setPlayerSize(SMALL_WIDTH, SMALL_HEIGHT);
break;
}
}
});

// 初始化播放器大小
setPlayerSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

// 确保 XJJ 按钮默认显示
toggle.style.display = 'block';
})();