| 748 | |
| 749 | // 添加屏蔽用户按钮(用户信息悬浮框中) |
| 750 | function blockUsers_button() { |
| 751 | const callback = (mutationsList, observer) => { |
| 752 | for (const mutation of mutationsList) { |
| 753 | for (const target of mutation.addedNodes) { |
| 754 | if (target.nodeType != 1) return |
| 755 | //console.log(target, target.className) |
| 756 | if (target.tagName == 'DIV' && target.className && (target.className.indexOf('css-') == 0 || target.style == 'opacity: 1;')) { |
| 757 | const item = target.querySelector('.MemberButtonGroup.ProfileButtonGroup.HoverCard-buttons'), |
| 758 | item1 = target.querySelector('img.Avatar+div span.UserLink>a.UserLink-link[data-za-detail-view-element_name=User]'); |
| 759 | if (item1) { |
| 760 | const name = item1.textContent, userid = item1.href.split('/')[4], users = menu_value('menu_customBlockUsers'); |
| 761 | for (let num = 0;num<users.length;num++) { // 判断是否已存在 |
| 762 | if (users[num] === name) { // 已存在 |
| 763 | target.querySelectorAll('.Button.Button--primary.Button--red').forEach(function(item){item.style.display = 'none';}) // 隐藏知乎自带的已屏蔽按钮 |
| 764 | item.insertAdjacentHTML('afterbegin', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red"><span style="display: inline-flex; align-items: center;"><svg width="1.2em" height="1.2em" viewBox="0 0 24 24" class="Zi Zi--Ban" fill="currentColor"><path fill-rule="evenodd" d="M16.346 18.113a7.5 7.5 0 0 1-10.46-10.46l10.46 10.46Zm1.767-1.767L7.654 5.886a7.5 7.5 0 0 1 10.46 10.46ZM22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z" clip-rule="evenodd"></path></svg></span> 已屏蔽</button>`); |
| 765 | item.firstElementChild.onclick = function(){this.disabled = true;blockUsers_button_del(this.dataset.name, this.dataset.userid, false)} |
| 766 | return |
| 767 | } |
| 768 | }; |
| 769 | if (item && !target.querySelector('button[data-name][data-userid]')) { |
| 770 | item.insertAdjacentHTML('beforeend', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="width: 100%;margin: 7px 0 0 0;"><span style="display: inline-flex; align-items: center;"><svg width="1.2em" height="1.2em" viewBox="0 0 24 24" class="Zi Zi--Ban" fill="currentColor"><path fill-rule="evenodd" d="M16.346 18.113a7.5 7.5 0 0 1-10.46-10.46l10.46 10.46Zm1.767-1.767L7.654 5.886a7.5 7.5 0 0 1 10.46 10.46ZM22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z" clip-rule="evenodd"></path></svg></span> 屏蔽用户</button>`); |
| 771 | item.lastElementChild.onclick = function(){this.disabled = true;blockUsers_button_add(this.dataset.name, this.dataset.userid, false)} |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | }; |
| 778 | const observer = new MutationObserver(callback); |
| 779 | observer.observe(document, { childList: true, subtree: true }); |
| 780 | } |
| 781 | |
| 782 | // 添加屏蔽用户按钮(用户主页) |
| 783 | function blockUsers_button_people() { |