(className1, className2)
| 946 | |
| 947 | |
| 948 | function blockKeywords_(className1, className2) { |
| 949 | // 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断 |
| 950 | function blockKeywords_now() { |
| 951 | if (location.pathname === '/hot') { |
| 952 | document.querySelectorAll('.HotItem').forEach(function(item1){blockKeywords_1(item1, 'h2.HotItem-title');}) |
| 953 | } else { |
| 954 | document.querySelectorAll(className1).forEach(function(item1){blockKeywords_1(item1, 'h2.ContentItem-title meta[itemprop="name"], meta[itemprop="headline"]');}) |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | blockKeywords_now(); |
| 959 | window.addEventListener('urlchange', function(){ |
| 960 | setTimeout(blockKeywords_now, 1000); // 网页 URL 变化后再次执行 |
| 961 | }) |
| 962 | |
| 963 | // 这个是监听网页插入事件,用来判断后续网页动态插入的元素 |
| 964 | const callback = (mutationsList, observer) => { |
| 965 | for (const mutation of mutationsList) { |
| 966 | for (const target of mutation.addedNodes) { |
| 967 | if (target.nodeType != 1) return |
| 968 | if (target.className === className2) {blockKeywords_1(target, 'h2.ContentItem-title meta[itemprop="name"], meta[itemprop="headline"]');} |
| 969 | } |
| 970 | } |
| 971 | }; |
| 972 | const observer = new MutationObserver(callback); |
| 973 | observer.observe(document, { childList: true, subtree: true }); |
| 974 | } |
| 975 | |
| 976 | |
| 977 | function blockKeywords_search() { |
no test coverage detected