MCPcopy Index your code
hub / github.com/XIU2/UserScript / blockUsers_button_people

Function blockUsers_button_people

Zhihu-Enhanced.user.js:783–800  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

781
782 // 添加屏蔽用户按钮(用户主页)
783 function blockUsers_button_people() {
784 let item = document.querySelector('.MemberButtonGroup.ProfileButtonGroup.ProfileHeader-buttons'), // 获取按钮元素位置
785 name = document.querySelector('.ProfileHeader-name').firstChild.textContent, // 获取用户名
786 users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表
787 userid = location.href.split('/')[4];
788 for (let num = 0;num<users.length;num++) { // 判断是否已存在
789 if (users[num] === name) { // 已存在
790 document.querySelectorAll('.Button.Button--primary.Button--red').forEach(function(item){item.style.display = 'none';}) // 隐藏知乎自带的已屏蔽按钮
791 item.insertAdjacentHTML('afterbegin', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="margin: 0 0 0 12px;"><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>`);
792 item.firstElementChild.onclick = function(){this.disabled = true;blockUsers_button_del(this.dataset.name, this.dataset.userid, true)}
793 return
794 }
795 };
796 if (item) {
797 item.insertAdjacentHTML('beforeend', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="margin: 0 0 0 12px;"><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>`);
798 item.lastElementChild.onclick = function(){this.disabled = true;blockUsers_button_add(this.dataset.name, this.dataset.userid, true)}
799 }
800 }
801
802 // 屏蔽用户按钮绑定事件(添加)
803 function blockUsers_button_add(name, userid, reload) {

Callers 1

blockUsersFunction · 0.85

Calls 3

blockUsers_button_delFunction · 0.85
blockUsers_button_addFunction · 0.85
menu_valueFunction · 0.70

Tested by

no test coverage detected