(type)
| 450 | |
| 451 | // 屏蔽低赞/低评回答/文章 |
| 452 | function blockLowCount(type) { |
| 453 | switch(type) { |
| 454 | case 'index': |
| 455 | blockLowCount_('.Card.TopstoryItem.TopstoryItem-isRecommend', 'Card TopstoryItem TopstoryItem-isRecommend', 'menu_blockLowUpvoteCount', 'menu_blockLowCommentCount'); |
| 456 | break; |
| 457 | case 'follow': |
| 458 | blockLowCount_('.Card.TopstoryItem.TopstoryItem-isFollow', 'Card TopstoryItem TopstoryItem-isFollow', 'menu_blockLowUpvoteCountFollow', 'menu_blockLowCommentCountFollow'); |
| 459 | break; |
| 460 | case 'question': |
| 461 | blockLowCount_('.List-item', 'List-item', 'menu_blockLowUpvoteCountQuestion', 'menu_blockLowCommentCountQuestion'); |
| 462 | break; |
| 463 | } |
| 464 | console.log(type) |
| 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) { |
| 500 | if (GM_getValue(menu)) { |
| 501 | let item_ContentItem = item.querySelector('.ContentItem') |
| 502 | if (item_ContentItem && item_ContentItem.dataset.zaExtraModule) { |
| 503 | let item2 = JSON.parse(item_ContentItem.dataset.zaExtraModule); |
| 504 | //console.log(item2) |
| 505 | if (item2 && item2.card.content && Number(item2.card.content[type]) < Number(GM_getValue(menu))) { |
| 506 | console.log('已屏蔽' + (type === 'upvote_num' ? '低赞':'低评') + (item_ContentItem.classList.contains('AnswerItem') ? '回答':'文章') + ':', item2.card.content[type] + '<' + GM_getValue(menu), item); |
| 507 | item.hidden = true; |
| 508 | item.style.display = 'none'; |
| 509 | } |
no test coverage detected