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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
|
(function() { 'use strict';
const TARGET_POPUP_XPATH = '//div[contains(@class, "qr-code") and @title]';
const BACKUP_POPUP_XPATH = '//*[@id="app"]/div/div[2]/div[1]/div[4]/div/div[2]/div/div[2]/div[1]//div[contains(@class, "qr-code")]';
const PLAY_BUTTON_SELECTOR = '.pv-playpause.pv-iconfont.pv-icon-btn-play';
const CONTINUE_BUTTON_SELECTOR = '.el-button.el-button--primary'; const CONTINUE_BUTTON_TEXT = '继续观看';
const CURRENT_TIME_SELECTOR = '.pv-time-current';
let popupDetected = false; let lastDetectedTitle = ''; let playButtonClicked = false; let continueButtonClicked = false; let lastPlayTime = ''; let timeCheckCounter = 0; const MAX_TIME_CHECKS = 5;
function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }
function findQrCodeWithTitle() { const qrCodeElements = document.querySelectorAll('.qr-code[title]'); for (let el of qrCodeElements) { const style = window.getComputedStyle(el); const visible = ( style.display !== 'none' && style.visibility !== 'hidden' && parseFloat(style.opacity) > 0 && el.offsetParent !== null ); if (visible) { return el; } } return null; }
function findPlayButton() { const playButton = document.querySelector(PLAY_BUTTON_SELECTOR); if (playButton) { console.log('找到播放按钮:', playButton); return playButton; } return null; }
function findContinueButton() { const buttons = document.querySelectorAll(CONTINUE_BUTTON_SELECTOR); for (let button of buttons) { const span = button.querySelector('span'); if (span && span.textContent.trim() === CONTINUE_BUTTON_TEXT) { console.log('找到继续观看按钮:', button); return button; } } return null; }
function getCurrentPlayTime() { const timeElement = document.querySelector(CURRENT_TIME_SELECTOR); if (timeElement) { return timeElement.textContent.trim(); } return null; }
function checkPlayTimeChanged() { const currentTime = getCurrentPlayTime(); console.log('当前播放时间:', currentTime, '上次播放时间:', lastPlayTime);
if (currentTime) { if (lastPlayTime === '') { lastPlayTime = currentTime; timeCheckCounter = 1; console.log('初始化播放时间:', currentTime); return false; } else if (currentTime !== lastPlayTime) { console.log('播放时间发生变化:', lastPlayTime, '->', currentTime); lastPlayTime = currentTime; timeCheckCounter = 0; return true; } else { timeCheckCounter++; console.log(`播放时间未变化 (${timeCheckCounter}/${MAX_TIME_CHECKS}):`, currentTime);
if (timeCheckCounter >= MAX_TIME_CHECKS) { console.log('播放可能卡住,尝试重新点击播放按钮'); return false; } return true; } } return false; }
function clickPlayButton() { if (playButtonClicked && timeCheckCounter < MAX_TIME_CHECKS) { return false; }
const playButton = findPlayButton(); if (playButton) { try { playButton.click(); console.log('成功点击播放按钮'); playButtonClicked = true; lastPlayTime = ''; timeCheckCounter = 0; showNotification('已自动点击播放按钮'); return true; } catch (error) { console.error('点击播放按钮时出错:', error); return simulateClick(playButton); } } return false; }
function clickContinueButton() { if (continueButtonClicked) { return false; }
const continueButton = findContinueButton(); if (continueButton) { try { continueButton.click(); console.log('成功点击继续观看按钮'); continueButtonClicked = true; showNotification('已自动点击继续观看按钮'); return true; } catch (error) { console.error('点击继续观看按钮时出错:', error); return simulateClick(continueButton); } } return false; }
function simulateClick(element) { try { console.log('尝试模拟点击事件'); const mouseEvent = new MouseEvent('click', { view: window, bubbles: true, cancelable: true }); element.dispatchEvent(mouseEvent); console.log('模拟点击成功'); return true; } catch (error) { console.error('模拟点击失败:', error); return false; } }
function openUrlInNewTab(url) { if (url && url.startsWith('http')) { console.log('在新标签页打开URL:', url); window.open(url, '_blank'); return true; } return false; }
function showNotification(message) { const notification = document.createElement('div'); notification.style.cssText = ` position: fixed; top: 20px; right: 20px; background: #4CAF50; color: white; padding: 10px 20px; border-radius: 5px; z-index: 10000; font-family: Arial, sans-serif; font-size: 14px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); `; notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => { if (notification.parentNode) { notification.parentNode.removeChild(notification); } }, 3000); }
function checkPlayStatus() { if (!popupDetected && playButtonClicked) { const timeChanged = checkPlayTimeChanged(); if (!timeChanged && timeCheckCounter >= MAX_TIME_CHECKS) { console.log('播放可能卡住,重新点击播放按钮'); playButtonClicked = false; setTimeout(() => { clickPlayButton(); }, 1000); } } }
function checkPopup() { const qrCodeElement = findQrCodeWithTitle();
const visible = qrCodeElement && window.getComputedStyle(qrCodeElement).display !== 'none';
if (visible) { const currentTitle = qrCodeElement.getAttribute('title'); console.log('当前检测到的title:', currentTitle);
if (currentTitle && currentTitle !== lastDetectedTitle) { popupDetected = true; lastDetectedTitle = currentTitle; playButtonClicked = false; continueButtonClicked = false; lastPlayTime = ''; timeCheckCounter = 0;
console.log('检测到新的二维码弹窗,title:', currentTitle);
if (openUrlInNewTab(currentTitle)) { console.log('成功在新标签页打开URL'); } else { console.log('URL格式不正确,无法打开:', currentTitle); } } } else { if (popupDetected) { console.log('弹窗已关闭'); popupDetected = false; lastDetectedTitle = '';
setTimeout(() => { if (!playButtonClicked) { clickPlayButton(); } if (!continueButtonClicked) { setTimeout(() => { clickContinueButton(); }, 1000); } }, 1000); } }
if (!popupDetected) { checkPlayStatus();
if (!playButtonClicked) { setTimeout(() => { clickPlayButton(); }, 2000); } if (!continueButtonClicked) { setTimeout(() => { clickContinueButton(); }, 3000); } } }
function startMonitoring() { console.log('开始监控二维码弹窗、播放按钮和继续观看按钮...');
checkPopup();
const observer = new MutationObserver(function(mutations) { let shouldCheckPopup = false; let shouldCheckPlayButton = false; let shouldCheckContinueButton = false;
mutations.forEach(function(mutation) { if (mutation.type === 'childList') { mutation.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.matches && node.matches('.qr-code')) { shouldCheckPopup = true; } else if (node.querySelector && node.querySelector('.qr-code')) { shouldCheckPopup = true; }
if (node.matches && node.matches(PLAY_BUTTON_SELECTOR)) { shouldCheckPlayButton = true; } else if (node.querySelector && node.querySelector(PLAY_BUTTON_SELECTOR)) { shouldCheckPlayButton = true; }
if (node.matches && node.matches(CONTINUE_BUTTON_SELECTOR)) { shouldCheckContinueButton = true; } else if (node.querySelector && node.querySelector(CONTINUE_BUTTON_SELECTOR)) { shouldCheckContinueButton = true; } } });
mutation.removedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.matches && node.matches('.qr-code')) { shouldCheckPopup = true; } else if (node.querySelector && node.querySelector('.qr-code')) { shouldCheckPopup = true; } } }); } });
if (shouldCheckPopup) { setTimeout(checkPopup, 500); }
if (shouldCheckPlayButton && !playButtonClicked) { setTimeout(() => { clickPlayButton(); }, 500); }
if (shouldCheckContinueButton && !continueButtonClicked) { setTimeout(() => { clickContinueButton(); }, 500); } });
observer.observe(document.body, { childList: true, subtree: true });
setInterval(checkPopup, 3000);
setInterval(checkPlayStatus, 5000); }
function init() { console.log('弹窗检测脚本初始化完成,开始监控'); startMonitoring(); }
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }
window.debugQrCode = function() { console.log('=== 二维码元素调试信息 ===');
const methods = [ { name: '主XPath', element: getElementByXpath(TARGET_POPUP_XPATH) }, { name: '备用XPath', element: getElementByXpath(BACKUP_POPUP_XPATH) }, { name: 'CSS选择器', element: document.querySelector('.qr-code[title]') }, { name: '所有qr-code', elements: document.querySelectorAll('.qr-code') } ];
methods.forEach(method => { console.log(`\n${method.name}:`); if (method.elements) { console.log(`找到 ${method.elements.length} 个.qr-code元素`); method.elements.forEach((el, index) => { const title = el.getAttribute('title'); console.log(` ${index + 1}. ${el.outerHTML.substring(0, 200)}`); console.log(` title: ${title}`); console.log(` 有title属性: ${el.hasAttribute('title')}`); }); } else if (method.element) { const title = method.element.getAttribute('title'); console.log(`找到元素:`, method.element); console.log(`outerHTML:`, method.element.outerHTML); console.log(`title属性:`, title); console.log(`有title属性:`, method.element.hasAttribute('title')); } else { console.log('未找到元素'); } }); };
window.openDetectedUrl = function() { const qrCodeElement = findQrCodeWithTitle(); if (qrCodeElement) { const url = qrCodeElement.getAttribute('title'); if (url) { console.log('手动打开URL:', url); return openUrlInNewTab(url); } else { console.log('找到元素但没有title属性'); return false; } } else { console.log('未找到二维码元素'); return false; } };
window.clickPlayButtonManually = function() { console.log('手动触发播放按钮点击'); playButtonClicked = false; lastPlayTime = ''; timeCheckCounter = 0; return clickPlayButton(); };
window.clickContinueButtonManually = function() { console.log('手动触发继续观看按钮点击'); continueButtonClicked = false; return clickContinueButton(); };
window.showPopupStatus = function() { console.log('=== 弹窗检测状态 ==='); console.log('弹窗检测状态:', popupDetected ? '已检测到弹窗' : '未检测到弹窗'); console.log('最后检测到的URL:', lastDetectedTitle || '无'); console.log('播放按钮状态:', playButtonClicked ? '已点击' : '未点击'); console.log('继续观看按钮状态:', continueButtonClicked ? '已点击' : '未点击'); console.log('当前播放时间:', getCurrentPlayTime() || '无'); console.log('上次播放时间:', lastPlayTime || '无'); console.log('时间检查计数:', timeCheckCounter);
const qrCodeElement = findQrCodeWithTitle(); if (qrCodeElement) { const url = qrCodeElement.getAttribute('title'); console.log('当前可用的URL:', url || '无'); } else { console.log('当前没有可用的二维码元素'); }
const playButton = findPlayButton(); if (playButton) { console.log('播放按钮存在:', playButton); } else { console.log('播放按钮不存在'); }
const continueButton = findContinueButton(); if (continueButton) { console.log('继续观看按钮存在:', continueButton); } else { console.log('继续观看按钮不存在'); }
const timeElement = document.querySelector(CURRENT_TIME_SELECTOR); if (timeElement) { console.log('播放时间元素存在:', timeElement); console.log('播放时间文本:', timeElement.textContent.trim()); } else { console.log('播放时间元素不存在'); } }; })();
|