什么值得买-营销号屏蔽器

smzdm user block 什么值得买 原创页面营销号屏蔽

目前为 2022-12-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         什么值得买-营销号屏蔽器
// @namespace    http://blog.ywwzwb.pw/
// @version      0.4
// @description  smzdm user block 什么值得买  原创页面营销号屏蔽
// @author       ywwzwb
// @match        https://post.smzdm.com/*
// @match        https://zhiyou.smzdm.com/member/*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_deleteValue
// @connect smzdm.com
// ==/UserScript==

(function () {
    'use strict';
    // _userList:
    // { "userid 1": { "uid": "userid 1", "uname" "xxxx", "uicon": "icon url", "manual_override_action": 0/1/2 } }
    //manual_override_action:
    const MANUAL_NO_ACTION = 0;
    const MANUAL_FORCE_BLOCK = 1;
    const MANUAL_FORCE_ALLOW = 2;
    var _userList/* Map<uid, uinfo> */ = getUserList();
    var _postBlockKeyword/* Set<keyword> */ = getBlockPostKeywordList();

    addSettingBtn();
    addSettingDiv();
    var customCSS = `
  .icon-block-left {
    width: 16px;
    height: 16px;
    fill: currentColor
  }
  .left-layer>div.J_block{
    height: auto;
    padding-bottom: 6px
  }
  .feed-grid-wrap #feed-main-list a.z-group-data.card-icon-with-block {
    width: 70px;
    padding-left: 0px;
    text-align: center;
  }

  .icon-block-card {
    width: 16px;
    height: 16px;
    fill: currentColor;
    vertical-align: top;
    margin-top: 1px;
    margin-right: 5px;
  }
  .icon-block-homepage {
    width: 16px;
    height: 16px;
    fill: #e62828;
    vertical-align: top;
    margin-top: 5px;
    margin-right: 3px;
    margin-left: 5px;
  }
  a.block-homepage.focus-other {
    width:auto;
    margin-left:10px;
  }
  a.block-homepage>span {
    margin-right:5px;
    color:currentColor;
  }
  .block-setting-box-bg {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0,0,0,.5);
    z-index: 9999;
    display: none;
  }
  .block-setting-box {
    width: 80%;
    z-index: 10000;
    position: fixed;
    left: 10%;
    top: 10%;
    background-color: #fff;
  }
  .block-setting-box-head-close:hover {
    fill: #e62828
  }
  .block-setting-box-head-close {
    width: 32px;
    float: right;
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .block-setting-box-head-title {
    font-size: 16px;
    color: #333;
    float: left;
  }
  .block-setting-box-head {
    height: 44px;
    line-height: 45px;
    padding: 0 14px;
    border-bottom: 1px solid #f5f5f5;
  }
  .block-user-ul {
    width:100%;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    border-bottom: 1px solid #f5f5f5;
  }
  .block-setting-box-content-li {
    float: left;
    margin-top: 5px;
    margin-bottom: 5px;
    margin-left: 10px;
    margin-right: 10px;
    width: calc(25% - 20px);
    height:92px;
    box-shadow: 1px 1px 2px 1px rgba(0, 0, 0, .2);
    border-radius: 4px;
  }
  .block-setting-box-content-li-user-left {
    float: left;
    width: 84px;
    height: 84px;
    margin-right: 14px;
    font-size: 0;
    text-align: center;
    overflow: hidden;
    margin-top: 5px;
    margin-left: 7px;
  }
  .block-setting-box-content-li-user-right {
    float: left;
    width: 80;
    height: 80px;
  }
  .block-setting-box-content-li-user-avatar {
    border-radius: 100%;
    overflow: hidden;
    width: 100%;
    height: auto;
  }
  .block-setting-box-content-li-user-title {
    font-size: 14px;
    color: #333;
    line-height: 24px;
    height: 48px;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .block-setting-box-content-li-user-block-btn {
    margin-top: 8px;
    margin-bottom: 8px;
    display: inline-block;
    line-height: 26px;
    border: 1px solid #fee4e4;
    text-align: center;
    width: 66px;
    color: #e62828;
    border-radius: 2px;
    background: #feecec;
  }
  .block-setting-box .pagenation-list-self {
    text-align: center;
    cursor: pointer;
    margin-bottom: 10px;
    margin-top: 10px;
    width:100%
  }
  .pagenation-list-self {
    font-size: 0;
  }

  .pagenation-list-self li {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    margin: 0 5px;
    color: #666;
    font-size: 14px;
    border-radius: 2px;
    background: #f7f7f7;
    overflow: hidden
  }

  .pagenation-list-self li a,.pagenation-list-self li span {
    display: block;
    width: 100%;
    height: 100%;
    color: #666;
  }

  .pagenation-list-self li.current,.pagenation-list-self li.current a,.pagenation-list-self li.page-number:hover,.pagenation-list-self li.page-turn:hover,.pagenation-list-self li a:hover {
    background-color: #e62828;
    color: #fff;
  }

  .pagenation-list-self li i {
    font-size: 12px;
  }
  #search-user{
    height: 24px;
    line-height: 24px;
    margin-left: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
    background-color: #f5f5f5;
    border: 0;
    color: #333;
    padding: 2px 10px;
    border-radius: 4px;
    width: 100%;
  }
  .block-tab {
    float: left;
    display: inline;
    margin-left: 40px;
  }
  .block-tab-box{
    box-sizing: border-box;
    margin-top: 10px;
    padding: 0 10px;
    width: 100%;
    overflow-y: scroll;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    border-bottom: 1px solid #f5f5f5;
  }
  .block-setting-tab{
    display: inline;
    padding: 2px;
    cursor: pointer;
  }
  .block-setting-tab.active{
    border-bottom-width: 2px;
    border-bottom-style: solid;
    color: #e62828;
  }
  .block-keyword-item {
    display: inline-flex;
    border: 1px solid #e62828;
    margin: 2px;
    border-radius: 3px;
    cursor: default;
  }
  .block-keyword-item>span {
    padding: 2px 4px 2px 4px;
  }
  .block-keyword-item>svg {
    background: #e62828;
    width: 20px;
    cursor: pointer;
  }
  .block-keywork-new {
    display: inline-flex;
    border: 1px solid #e62828;
    margin: 2px;
    border-radius: 3px;
  }
  .block-keywork-new>input{
    border: 0;
    margin: 2px 4px 2px 4px;
    width:100px;
  }
  .block-keywork-new>div{
    display: inline-flex;
    justify-content: center;
    align-items: center;
    background: #e62828;
    width: 20px;
    cursor: pointer;
  }
  .block-keywork-new>div>i{
    color: white;
  }
  `
    var styleSheet = document.createElement('style')
    styleSheet.type = 'text/css'
    styleSheet.innerText = customCSS
    document.head.appendChild(styleSheet)

    var blocUserWords = [
        // '值友', '数码', '科技', '之家', '耳机', '玩机', '达人', '工坊', '极客',
        // '小小值'
    ];
    // 初始化数据库

    if (window.location.href.startsWith('https://post.smzdm.com/p/')) {
        // post
        addBlockInPost();
        return;
    }
    if (window.location.href.startsWith('https://zhiyou.smzdm.com/member/')) {
        // homepage
        addBlockInHomepage();
        return;
    }
    refreshArticalList();
    $(document).ajaxComplete(function (event, xhr, settings) {
        // 下拉加载时屏蔽
        if (settings.url.startsWith('https://post.smzdm.com/json_more')) {
            refreshArticalList();
        }
    });

    // 刷新界面, 屏蔽特定的文章
    function refreshArticalList() {
        $.each($('#feed-main-list>li'), function (index, obj) {
            var title = $(obj).find('.z-feed-title').text();
            // 屏蔽众测广告
            if (isZhongce(obj)) {
                $(obj).remove();
                return;
            }
            // 屏蔽晒物
            if (isShaiwu(obj)) {
                $(obj).remove();
                return;
            }
            // 屏蔽评测文章
            if (isPingce(obj)) {
                $(obj).remove();
                return;
            }
            // 屏蔽媒体号
            if (isMediaAccountSimple(obj)) {
                $(obj).remove();
                return;
            }

            // 屏蔽标题关键字
            if (isPostTitleContainBlockKeyword(title)) {
                $(obj).remove();
                return;
            }

            // 屏蔽用户名关键字
            if (hasUserKeyWord(obj)) {
                $(obj).remove();
                return;
            }
            // 查询屏蔽数据库
            var uinfo = getUserForLi(obj);
            if (!uinfo) {
                return;
            }

            // 屏蔽垃圾营销号
            // 从数据库中查找垃圾账号
            if (isUserBlock(uinfo.uid)) {
                $(obj).remove();
                return;
            }
            //添加屏蔽按钮
            if ($(obj).find('.card-block').length == 0) {
                addBlockBtnTo(obj);
            }
        });
    }
    // 用户关键字屏蔽
    function hasUserKeyWord(item) {
        var username = $(item).find('.z-avatar-name').text();
        for (var i = 0; i < blocUserWords.length; i++) {
            if (username.includes(blocUserWords[i])) {
                return true;
            }
        }
        return false;
    }
    // 众测软文屏蔽
    function isZhongce(item) {
        return $(item).find('.z-tag-sticky').text().trim() == '众测';
    }
    // 晒物文章屏蔽
    function isShaiwu(item) {
        return $(item).find('.z-tag-sticky').text().trim() == '晒物';
    }

    // 评测文章屏蔽
    function isPingce(item) {
        return $(item).find('.z-tag-sticky').text().trim() == '评测';
    }
    // 判断媒体账号, 简易版
    function isMediaAccountSimple(item) {
        var imgsrc = $(item).find('.feed-talent-ordinary').attr('src');
        return imgsrc && imgsrc.includes('media_medal');
    }
    // 检查用户是否是垃圾账号
    function testSpammer(uid, cb) {
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'https://api.smzdm.com/users/info',
            data: 'user_smzdm_id=' + uid,
            headers:
                { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
            responseType: 'json',
            onload: response => {
                var data = response.response;
                if (parseInt(data.error_code) != 0) {
                    cb(false, true)
                    return;
                }
                // 媒体号
                if (parseInt(data.data.role.is_media) != 0) {
                    cb(true, false);
                    return;
                }
                // 官方号
                if (parseInt(data.data.role.is_official) != 0) {
                    cb(true, false);
                    return;
                }
                // 运营号
                if (parseInt(data.data.role.is_merchant) != 0) {
                    cb(true, false);
                    return;
                }
                //   评论 / 文章 < 5 or 评论 == 0 则是营销号
                var articalsCount = parseInt(data.data.articles.article);
                var commentsCount = parseInt(data.data.comments);
                if (commentsCount == 0 || commentsCount / articalsCount < 5) {
                    cb(true, false);
                    return;
                }
                cb(false, false);
            },
            onerror: response => {
                cb(false, true)
            }
        });
    }

    // 获取用户信息
    function getUserForLi(li_item) {
        var a = $(li_item).find('.z-feed-foot-l .z-avatar-name');
        var uname = a.text().trim();
        var href = a.attr('href');
        if (!href) {
            return null;
        }
        var uidResult = /\/(\d+)\/?$/.exec(href);
        if (!uidResult) {
            return null;
        }
        var uicon = $(li_item).find('.z-feed-foot-l .z-avatar-pic>img')
            .attr('src')
            .replace('-small.', '-middle.');
        return { 'uid': uidResult[1], 'uname': uname, 'uicon': uicon };
    }
    // 文章列表页面屏蔽按钮
    function addBlockBtnTo(item) {
        $(item).find('.z-feed-foot-r').children('a').addClass('card-icon-with-block');
        var a = $(`<a class='z-group-data card-icon-with-block' title='屏蔽'></a>`);
        var blockIcon = $(`
      <svg class='icon-block-card' version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox = "0 0 1024 1024" >
        <path d="M202.666667 256h-42.666667a32 32 0 0 1 0-64h704a32 32 0 0 1 0 64H266.666667v565.333333a53.333333 53.333333 0 0 0 53.333333 53.333334h384a53.333333 53.333333 0 0 0 53.333333-53.333334V352a32 32 0 0 1 64 0v469.333333c0 64.8-52.533333 117.333333-117.333333 117.333334H320c-64.8 0-117.333333-52.533333-117.333333-117.333334V256z m224-106.666667a32 32 0 0 1 0-64h170.666666a32 32 0 0 1 0 64H426.666667z m-32 288a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z m170.666666 0a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z" p-id="2813"></path>
      </svg>`);
        var span = $(`<span>屏蔽</span>`)
        a.append(blockIcon);
        a.append(span);
        $(item).find('.z-feed-foot-r').append(a);
        a.click(function () {
            var li = a.parents('li');
            var uinfo = getUserForLi(li);
            $(item).remove();
            if (uinfo) {
                manualBlockUser(uinfo);
            }
        });
    }
    // 文章内部屏蔽按钮
    function addBlockInPost() {
        if ($('.author-title').length == 0) {
            return;
        }
        var authorA = $($('.author-title')[0]);
        var authorHref = authorA.attr('href');
        if (!authorHref) {
            return null;
        }
        var uidResult = /\/(\d+)\/?$/.exec(authorHref);
        if (!uidResult || uidResult.length < 2) {
            return null;
        }
        var uid = uidResult[1];
        var uname = authorA.text().trim();
        var uicon = $('.tx_name>img').attr('src').replace('-big.', '-middle.');
        let user = getUserInfo(uid, { 'uid': uid, 'uname': uname, 'uicon': uicon });
        user.uname = uname;
        user.uicon = uicon;
        saveUserInfo(user);
        var blockIcon = $(`
      <svg class='icon-block-left' version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox = "0 0 1024 1024" >
        <path d="M202.666667 256h-42.666667a32 32 0 0 1 0-64h704a32 32 0 0 1 0 64H266.666667v565.333333a53.333333 53.333333 0 0 0 53.333333 53.333334h384a53.333333 53.333333 0 0 0 53.333333-53.333334V352a32 32 0 0 1 64 0v469.333333c0 64.8-52.533333 117.333333-117.333333 117.333334H320c-64.8 0-117.333333-52.533333-117.333333-117.333334V256z m224-106.666667a32 32 0 0 1 0-64h170.666666a32 32 0 0 1 0 64H426.666667z m-32 288a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z m170.666666 0a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z" p-id="2813"></path>
      </svg>`);
        var span = $(`<span>屏蔽</span>`)
        var isBlock = false;
        if (isUserBlock(uid)) {
            span.html('取消<br/>屏蔽')
            isBlock = true;
        }
        var div = $('<div class="J_block comment"> </div>');
        div.append(blockIcon);
        div.append(span);
        $('.qrcode').before(div)
        div.attr('data-block', isBlock);
        div.click(function () {
            var isBlock = $(this).attr('data-block') == 'true'
            isBlock = !isBlock;
            $(this).attr('data-block', isBlock);
            if (isBlock) {
                span.html('取消<br/>屏蔽')
                manualBlockUser(user);
            } else {
                span.html('屏蔽');
                manualUnblockUser(user);
            }
        });
    };
    // 用户首页屏蔽按钮
    function addBlockInHomepage() {
        if ($('.info-stuff-nickname>a').length == 0) {
            return;
        }
        var authorA = $('.info-stuff-nickname>a');
        var authorHref = authorA.attr('href');
        if (!authorHref) {
            return null;
        }
        var uidResult = /\/(\d+)\/?$/.exec(authorHref);
        if (!uidResult || uidResult.length < 2) {
            return null;
        }
        var uid = uidResult[1];
        var uname = authorA.text().trim();
        var uicon = $('.avatar-box>img').attr('src');
        let user = getUserInfo(uid, { 'uid': uid, 'uname': uname, 'uicon': uicon });
        saveUserInfo(user);
        var blockIcon = $(`
      <svg class='icon-block-homepage' version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox = "0 0 1024 1024" >
        <path d="M202.666667 256h-42.666667a32 32 0 0 1 0-64h704a32 32 0 0 1 0 64H266.666667v565.333333a53.333333 53.333333 0 0 0 53.333333 53.333334h384a53.333333 53.333333 0 0 0 53.333333-53.333334V352a32 32 0 0 1 64 0v469.333333c0 64.8-52.533333 117.333333-117.333333 117.333334H320c-64.8 0-117.333333-52.533333-117.333333-117.333334V256z m224-106.666667a32 32 0 0 1 0-64h170.666666a32 32 0 0 1 0 64H426.666667z m-32 288a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z m170.666666 0a32 32 0 0 1 64 0v256a32 32 0 0 1-64 0V437.333333z" p-id="2813"></path>
      </svg>`);
        var a = $(`<a class="focus-other block-homepage"></a>`);
        var span = $(`<span>屏蔽</span>`);
        var isBlock = false;
        if (isUserBlock(uid)) {
            span.html('取消屏蔽');
            isBlock = true;
        }
        a.append(blockIcon);
        a.append(span);
        $('.info-stuff-set').append(a)
        a.attr('data-block', isBlock);
        a.click(function () {
            var isBlock = $(this).attr('data-block') == 'true'
            isBlock = !isBlock;
            $(this).attr('data-block', isBlock);
            if (isBlock) {
                span.text('取消屏蔽');
                manualBlockUser(user);
            } else {
                span.text('屏蔽');
                manualUnblockUser(user);
            }
        });
    };
    // 添加屏蔽设置按钮
    function addSettingBtn() {
        var li = $(`
      <li>
        <span class="elevator-report">屏蔽<br>设置</span>
      </li>`);
        $('#elevator>.back-top').before(li);
        li.click(function () {
            $('.block-setting-box-bg').show();
            $('#search-user').val("");
            setPageDataForSettingBox(1, 12, '');
        });
    };
    // 添加设置框
    function addSettingDiv() {
        var bg = $(`<div class="block-setting-box-bg"></div>`);
        var box = $(`<div class="block-setting-box"></div>`);
        var boxHead = $(`<div class="block-setting-box-head"></div>`);
        var closeIcon = $(`<svg class='block-setting-box-head-close' version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox = "0 0 1024 1024" >
            <path d="M676.44928 688.042667L542.17728 553.813333 675.510613 420.437333a21.290667 21.290667 0 0 0 0-30.165333 21.290667 21.290667 0 0 0-30.165333 0L512.011947 523.605333 378.635947 390.272a21.333333 21.333333 0 1 0-30.208 30.165333L481.846613 553.813333 347.574613 688.042667a21.333333 21.333333 0 0 0 30.208 30.165333L512.011947 583.978667l134.229333 134.229333a21.248 21.248 0 0 0 30.208 0 21.333333 21.333333 0 0 0 0-30.165333" p-id="3802"></path>
        </svg>`);
        var title = $(`<span class="block-setting-box-head-title">屏蔽设置</span>`);
        var tabChoose = $(`<ul class= "block-tab">
            <li class="block-setting-tab active" tabid="tab-block-user">屏蔽作者</li>
            <li class="block-setting-tab" tabid="tab-block-title-keyword">标题关键字屏蔽</li>
            <li class="block-setting-tab" tabid="tab-block-user">更多选项</li>
        </ul>`);
        var userBlockTab = createUserBlockTab();
        var titleKeywordBlockTab = createTitleKeywordBlockTab();
        boxHead.append(title);
        boxHead.append(tabChoose);
        boxHead.append(closeIcon);
        box.append(boxHead);
        box.append(userBlockTab);
        box.append(titleKeywordBlockTab);
        bg.append(box);
        $('body').append(bg);
        closeIcon.click(function () {
            $('.block-setting-box-bg').hide();
        });
        bg.click(event => {
            if (event.target != event.currentTarget) {
                return;
            }
            $('.block-setting-box-bg').hide();
        })
        $(".block-tab li").click(function () {
            console.log("click tab");
            for (const tab of $(".block-tab li")) {
                if (tab == this) {
                    $(tab).addClass("active");
                } else {
                    $(tab).removeClass("active");
                }
            }
            let displayTab = $(this).attr("tabid");
            for (const tabBox of $(".block-tab-box")) {
                if ($(tabBox).attr("id") == displayTab) {
                    $(tabBox).show();
                } else {
                    $(tabBox).hide();
                }
            }
        });
    }
    function createUserBlockTab() {
        var userBlockTab = $(`<div class="block-tab-box" id="tab-block-user"></div>`);
        var searchUserBox = $(`<input id="search-user" type="text" value="" placeholder="筛选"/>`);
        var blockUserUL = $(`<ul class="block-user-ul" id="list-block-user"></ul>`);
        var blockUserPageUL = $(`<ul class="pagenation-list-self" id="list-block-user-page"></ul>`);
        userBlockTab.append(searchUserBox);
        userBlockTab.append(blockUserUL);
        userBlockTab.append(blockUserPageUL);
        searchUserBox.keyup(e => {
            var value = e.target.value;
            setPageDataForSettingBox(1, 12, value);
        });
        return userBlockTab;
    }
    function createTitleKeywordBlockTab() {
        let closeBtnSVG = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
            <path fill="#fff" d="M676.44928 688.042667L542.17728 553.813333 675.510613 420.437333a21.290667 21.290667 0 0 0 0-30.165333 21.290667 21.290667 0 0 0-30.165333 0L512.011947 523.605333 378.635947 390.272a21.333333 21.333333 0 1 0-30.208 30.165333L481.846613 553.813333 347.574613 688.042667a21.333333 21.333333 0 0 0 30.208 30.165333L512.011947 583.978667l134.229333 134.229333a21.248 21.248 0 0 0 30.208 0 21.333333 21.333333 0 0 0 0-30.165333" p-id="3802"></path>
        </svg>`;
        let tab = $(`<div class="block-tab-box" id="tab-block-title-keyword" style="display:none;"></div>`);
        let ul = $(`<ul></ul>`);
        tab.append(ul);
        // 新建屏蔽词
        let newBlockKeyworkLi = $(`<li class="block-keywork-new"></li>`);
        let newBlockKeyworkinput = $(`<input type="text" placeholder="添加屏蔽词"/>`);
        let newBlockKeyworkAddBtn = $(`<div><i>+</i></div>`);
        newBlockKeyworkLi.append(newBlockKeyworkinput);
        newBlockKeyworkLi.append(newBlockKeyworkAddBtn);
        ul.append(newBlockKeyworkLi);
        newBlockKeyworkAddBtn.on("click", (event) => {
            let keyword = newBlockKeyworkinput.val().trim();
            newBlockKeyworkinput.val("");
            if (insertPostBlockKeyword(keyword)) {
                createPostBlockKeywordItem(ul, keyword);
            }
        });
        // 关键词列表
        let blockKeywordList = getBlockPostKeywordList();
        for (const keyword of blockKeywordList) {
            createPostBlockKeywordItem(ul, keyword);
        }
        // UI
        ul.on("mouseenter", ".block-keyword-item", (event) => {
            $(event.currentTarget).append($(closeBtnSVG));
        });
        ul.on("mouseleave", ".block-keyword-item", (event) => {
            $(event.currentTarget).find("svg").remove();
        });
        // 删除
        ul.on("click", "svg", (event) => {
            let item = $(event.currentTarget).parent(".block-keyword-item");
            let keyword = item.find(".block-keyword").text().trim();
            item.remove();
            removePostBlockKeyword(keyword);
        });
        return tab;
    }
    function setPageDataForSettingBox(
        page /*: int*/,
        pageSize /*: int*/,
        usernameFilter /*: string*/) {
        if (page <= 0) {
            page = 1
        }
        if (pageSize <= 0) {
            pageSize = 10;
        }

        $('#list-block-user').empty();
        $('#list-block-user-page').empty();
        let filterdUser = [...getUserList().values()];
        usernameFilter = usernameFilter.trim();
        if (usernameFilter.length > 0) {
            filterdUser = filterdUser.filter(uinfo => {
                uinfo.uname.includes(usernameFilter)
            });
        }
        const blockedUser = filterdUser.filter(uinfo => isUserBlockWithInfo(uinfo));
        const userInPage = blockedUser.filter((uinfo, index) => {
            return index >= (page - 1) * pageSize && index < page * pageSize;
        });
        for (const uinfo of userInPage) {
            $('#list-block-user').append(createUserBlockCard(uinfo));
        }
        const totalPageCount = Math.ceil(blockedUser.length / pageSize);
        createPagerForUserBlock(page, totalPageCount, (newPage) => {
            setPageDataForSettingBox(newPage, pageSize, usernameFilter);
        });
    }
    function createUserBlockCard(uinfo) {
        let img = $(`<img class="block-setting-box-content-li-user-avatar"></img>`);
        if (!('uicon' in uinfo)) {
            getICONForUser(user.uid, function (success, url) {
                img.attr('src', url);
                if (success) {
                    uinfo['uicon'] = url;
                    saveUserInfo(uinfo);
                }
            });
        } else {
            img.attr('src', uinfo['uicon']);
        }
        let imga = $(`<a class="block-setting-box-content-li-user-left"></a>`);
        imga.attr('href', 'https://zhiyou.smzdm.com/member/' + uinfo['uid']);
        imga.append(img);
        let title = $(`<a class="block-setting-box-content-li-user-title"></a>`);
        title.text(uinfo.uname);
        title.attr('href', 'https://zhiyou.smzdm.com/member/' + uinfo['uid']);
        let blockBtn =
            $(`<a class="block-setting-box-content-li-user-block-btn"><span>取消屏蔽</span></a>`);
        let li = $(`<li class="block-setting-box-content-li"></li>`);
        li.append(imga);
        let userRight =
            $(`<div class=""block-setting-box-content-li-user-right"></div>`);
        userRight.append(title);
        userRight.append(blockBtn);
        li.append(userRight);
        blockBtn.click(function () {
            manualUnblockUser(uinfo);
        });
        return li;
    }
    function createPagerForUserBlock(currentPage, totalPageCount, gotoPageCallback) {
        let maxPagerCount = 5;
        let pagerStart = currentPage - parseInt((maxPagerCount / 2));
        if (pagerStart <= 0) {
            pagerStart = 1;
        }
        let pagerEnd = pagerStart + maxPagerCount;
        if (pagerEnd > totalPageCount) {
            pagerEnd = totalPageCount;
        }
        if (pagerStart != 1) {
            let lastPage =
                $(`<li class=""><i class="icon-angle-left-o-thin"></i></li>`);
            $('#list-block-user-page').append(lastPage);
            lastPage.click(function () {
                gotoPageCallback(currentPage - 1);
            });
            let firstPage = $(`<li class="page-number">1</li>`);
            $('#list-block-user-page').append(firstPage);
            firstPage.click(function () {
                gotoPageCallback(1);
            });
            $('#list-block-user-page').append($(`<li class="noHover">...</li>`));
        }
        for (let i = pagerStart; i <= pagerEnd; i++) {
            let pager = $(`<li class="page-number"></li>`);
            pager.text(i);
            if (i == currentPage) {
                pager.addClass('current');
            }
            pager.click(function () {
                gotoPageCallback(i);
            });
            $('#list-block-user-page').append(pager);
        }
        if (pagerEnd != totalPageCount) {
            $(`<li class=""><i class="icon-angle-left-o-thin"></i></li>`);
            $('#list-block-user-page').append($(`<li class="noHover">...</li>`));
            let nextPage = $(
                `<li class="page-turn next-page"><i class="icon-angle-right-o-thin"></i></li>`);
            $('#list-block-user-page').append(nextPage);
            nextPage.click(function () {
                gotoPageCallback(currentPage + 1);
            });
        }
    }
    function createPostBlockKeywordItem(ul, keyword) {
        let span = $(`<span class="block-keyword"></span>`);
        span.text(keyword);
        let li = $(`<li class="block-keyword-item"></li>`);
        li.append(span);
        ul.append(li);
    }
    function getICONForUser(uid, cb) {
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'https://api.smzdm.com/users/info',
            data: 'user_smzdm_id=' + uid,
            headers:
                { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
            responseType: 'json',
            onload: response => {
                var data = response.response;
                if (parseInt(data.error_code) != 0) {
                    cb(false,
                        'https://res.smzdm.com/images/user_logo/default_avatar/5-middle.png');
                    return;
                }
                cb(true, data.data.meta.avatar);
            },
            onerror: response => {
                cb(false,
                    'https://res.smzdm.com/images/user_logo/default_avatar/5-middle.png');
            }
        });
    }
    function getUserList() {
        if (_userList != undefined) {
            return _userList;
        }
        let list = GM_getValue("user_list");
        if (list != undefined) {
            return new Map(Object.entries(list));
        }
        // convert v1 to v2
        list = new Map();
        let allKeys = GM_listValues();
        for (var id of allKeys) {
            let oldUInfo = GM_getValue(id);
            if (oldUInfo.oldUInfo.uid == undefined) {
                continue;
            }
            let newUInfo = {
                "uid": oldUInfo.uid,
                "uname": oldUInfo.uname,
                "uicon": oldUInfo.uicon,
                "manual_override_action": oldUInfo.flag
            }
            list.set(id, newUInfo)
            GM_deleteValue(id);
        }
        GM_setValue("user_list", list);
        return list;
    }
    function manualBlockUser(uinfo) {
        uinfo.manual_override_action = MANUAL_FORCE_BLOCK;
        saveUserInfo(uinfo);
    }
    function manualUnblockUser(uinfo) {
        uinfo.manual_override_action = MANUAL_FORCE_ALLOW;
        saveUserInfo(uinfo);
    }
    function isUserBlock(id) {
        let uinfo = getUserInfo(id, undefined);
        if (uinfo == undefined) {
            return false;
        }
        if (uinfo.manual_override_action == MANUAL_FORCE_BLOCK) {
            // force block
            return true;
        }
        if (uinfo.manual_override_action == MANUAL_FORCE_ALLOW) {
            // force allow
            return false;
        }
        // TODO: 按其他信息阻断
        return false;
    }
    function isUserBlockWithInfo(uinfo) {
        if (uinfo.manual_override_action == MANUAL_FORCE_BLOCK) {
            // force block
            return true;
        }
        if (uinfo.manual_override_action == MANUAL_FORCE_ALLOW) {
            // force allow
            return false;
        }
        // TODO: 按其他信息阻断
        return false;
    }
    function getUserInfo(id, defaultUserInfo) {
        let uinfo = _userList.get(id);
        if (uinfo == undefined) {
            return defaultUserInfo;
        }
        return uinfo;
    }
    function saveUserInfo(uinfo) {
        if (uinfo == undefined) {
            return;
        }
        _userList.set(uinfo.uid, uinfo);
        GM_setValue("user_list", Object.fromEntries(_userList));
    }

    function getBlockPostKeywordList() {
        if (_postBlockKeyword == undefined) {
            return new Set(GM_getValue("block_post_keyword_list", []));
        }
        return _postBlockKeyword
    }
    function insertPostBlockKeyword(keyword) {
        if (keyword.length == 0) {
            return false;
        }
        if (_postBlockKeyword.has(keyword)) {
            return false;
        }
        _postBlockKeyword.add(keyword);
        savePostBlockKeyword();
        return true;
    }
    function removePostBlockKeyword(keyword) {
        if (!_postBlockKeyword.has(keyword)) {
            return false;
        }
        _postBlockKeyword.delete(keyword);
        savePostBlockKeyword();
        return true;
    }
    function savePostBlockKeyword() {
        GM_setValue("block_post_keyword_list", Array.from(_postBlockKeyword));
    }
    function isPostTitleContainBlockKeyword(title) {
        for (const keyword of _postBlockKeyword) {
            if (title.indexOf(keyword) >= 0) {
                return true;
            }
        }
        return false;
    }
})();