(type)
| 532 | |
| 533 | // 屏蔽指定用户 |
| 534 | function blockUsers(type) { |
| 535 | if (!menu_value('menu_blockUsers')) return |
| 536 | if (!menu_value('menu_customBlockUsers') || menu_value('menu_customBlockUsers').length < 1) return |
| 537 | switch(type) { |
| 538 | case 'index': |
| 539 | blockUsers_('.Card.TopstoryItem.TopstoryItem-isRecommend', 'Card TopstoryItem TopstoryItem-isRecommend'); |
| 540 | break; |
| 541 | case 'follow': |
| 542 | blockUsers_('.Card.TopstoryItem.TopstoryItem-isFollow', 'Card TopstoryItem TopstoryItem-isFollow'); |
| 543 | break; |
| 544 | case 'question': |
| 545 | blockUsers_question(); |
| 546 | break; |
| 547 | case 'search': |
| 548 | blockUsers_search(); |
| 549 | break; |
| 550 | case 'topic': |
| 551 | blockUsers_('.List-item.TopicFeedItem', 'List-item TopicFeedItem'); |
| 552 | break; |
| 553 | case 'people': |
| 554 | blockUsers_button_people(); // 添加屏蔽用户按钮(用户主页) |
| 555 | break; |
| 556 | } |
| 557 | blockUsers_comment(); // 评论区 |
| 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) { // 找到就删除该信息流 |
no test coverage detected