(className1, className2, menuUpvote, menuComment)
| 465 | |
| 466 | |
| 467 | function blockLowCount_(className1, className2, menuUpvote, menuComment) { |
| 468 | // 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断 |
| 469 | function blockLowCount_now() { |
| 470 | document.querySelectorAll(className1).forEach(function(item1){ |
| 471 | console.log(item1) |
| 472 | blockLowCount_1(item1,menuUpvote,'upvote_num'); |
| 473 | blockLowCount_1(item1,menuComment,'comment_num'); |
| 474 | }) |
| 475 | } |
| 476 | |
| 477 | blockLowCount_now(); |
| 478 | window.addEventListener('urlchange', function(){ |
| 479 | setTimeout(blockLowCount_now, 1000); // 网页 URL 变化后再次执行 |
| 480 | }) |
| 481 | |
| 482 | // 这个是监听网页插入事件,用来判断后续网页动态插入的元素 |
| 483 | const callback = (mutationsList, observer) => { |
| 484 | for (const mutation of mutationsList) { |
| 485 | for (const target of mutation.addedNodes) { |
| 486 | if (target.nodeType != 1) return |
| 487 | if (target.className === className2) { |
| 488 | blockLowCount_1(target,menuUpvote,'upvote_num'); |
| 489 | blockLowCount_1(target,menuComment,'comment_num'); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | }; |
| 494 | const observer = new MutationObserver(callback); |
| 495 | observer.observe(document, { childList: true, subtree: true }); |
| 496 | } |
| 497 | |
| 498 | |
| 499 | function blockLowCount_1(item, menu, type) { |
no test coverage detected