(className1, className2)
| 558 | blockUsers_button(); // 加入黑名单按钮(用户信息悬浮框中) |
| 559 | |
| 560 | function blockUsers_(className1, className2) { |
| 561 | // 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断 |
| 562 | function blockKeywords_now() { |
| 563 | document.querySelectorAll(className1).forEach(function(item1){ |
| 564 | let item = item1.querySelector('.ContentItem.AnswerItem, .ContentItem.ArticleItem'); // 用户名所在元素 |
| 565 | if (item) { |
| 566 | for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单 |
| 567 | if (keyword != '' && item.dataset.zop.indexOf('authorName":"' + keyword + '",') > -1) { // 找到就删除该信息流 |
| 568 | console.log('已屏蔽:' + item.dataset.zop); |
| 569 | item1.hidden = true; |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | }) |
| 575 | } |
| 576 | |
| 577 | blockKeywords_now(); |
| 578 | window.addEventListener('urlchange', function(){ |
| 579 | setTimeout(blockKeywords_now, 1000); // 网页 URL 变化后再次执行 |
| 580 | }) |
| 581 | |
| 582 | // 这个是监听网页插入事件,用来判断后续网页动态插入的元素 |
| 583 | const callback = (mutationsList, observer) => { |
| 584 | for (const mutation of mutationsList) { |
| 585 | for (const target of mutation.addedNodes) { |
| 586 | if (target.nodeType != 1) return |
| 587 | if (target.className === className2) { |
| 588 | let item = target.querySelector('.ContentItem.AnswerItem, .ContentItem.ArticleItem'); // 用户名所在元素 |
| 589 | if (item) { |
| 590 | for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单 |
| 591 | if (keyword != '' && item.dataset.zop.indexOf('authorName":"' + keyword + '",') > -1) { // 找到就删除该信息流 |
| 592 | console.log('已屏蔽:' + item.dataset.zop); |
| 593 | target.hidden = true; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | }; |
| 602 | const observer = new MutationObserver(callback); |
| 603 | observer.observe(document, { childList: true, subtree: true }); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | function blockUsers_question() { |
no test coverage detected