oneClickRemoveWeiboFans

Add a button to remove your shit followers.

当前为 2017-03-01 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name                oneClickRemoveWeiboFans
// @name:zh-CN          oneClickRemoveWeiboFans 一键删除微博粉丝
// @namespace           undefined
// @version             0.0.3
// @description         Add a button to remove your shit followers.
// @description:zh-CN   在粉丝页面添加一个[一键删除]按钮
// @author              catscarlet
// @match               http://weibo.com/*/fans*
// @match               http://weibo.com/p/*/myfollow?*relate=fans*
// @require             https://code.jquery.com/jquery-latest.js
// @run-at              document-end
// @grant               unsafeWindow
// @grant               GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    var $ = $ || window.$;

    $(function() {
        console.log('oneClickRemoveWeiboFans loaded');

        var relationlistdiv1 = $('.WB_cardwrap S_bg2');
        var relationlistdiv2 = $('#Pl_Official_RelationFans__88');

        relationlistdiv1.bind('DOMNodeInserted', function(e) {
            console.log('oneClickRemoveWeiboFans .WB_cardwrap S_bg2 detected DOMNodeInserted');
            f();
        });

        relationlistdiv2.bind('DOMNodeInserted', function(e) {
            console.log('oneClickRemoveWeiboFans #Pl_Official_RelationFans__88 detected DOMNodeInserted');
            f();
        });

        setTimeout(f, 1000);

        function f() {
            console.log('oneClickRemoveWeiboFans pending');
            if (!document.getElementsByClassName('follow_list').length) {

                setTimeout(f, 1000);
            } else {
                getFans();
            };
        }

    });

    function detectPage() {
        return 0;
    }

    function getFans() {
        if ($('.follow_box').attr('oneClickRemoveWeiboFansFlag')) {
            //console.log('oneClickRemoveWeiboFans already get fans');
            return;
        } else {
            $('.follow_box').attr('oneClickRemoveWeiboFansFlag', '1');
        }
        console.log('oneClickRemoveWeiboFans get fans');
        var follow_list = $('.follow_list');
        $(follow_list).find('li').each(function() {
            var follow = $(this);

            if (follow.hasClass('follow_item S_line2')) {
                var opt_box = follow.find('.opt_box');
                var info = opt_box.find('a.W_btn_b');
                if ($(info).attr('action-type') == 'follow') {
                    var fanuid = getParameterByName('uid', $(info).attr('action-data'));
                    var fanfnick = getParameterByName('fnick', $(info).attr('action-data'));
                    var str = '<a href="javascript:;" class="W_btn_b removeFanDirectlyBtn" style="background-color: #f56213" action-type="removeFanDirectly" fanuid="' + fanuid + '" fanfnick="' + fanfnick + '">一键移除</a>';
                    opt_box.append(str);
                }
            }
        });

        $('.removeFanDirectlyBtn').on('click', removeFanDirectly);
        console.log('oneClickRemoveWeiboFans button ready');
    };

    function getParameterByName(name, url) {
        if (!url) {
            url = window.location.href;
        }
        name = name.replace(/[\[\]]/g, '\\$&');
        var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
        var results = regex.exec(url);
        if (!results) {
            return null;
        }
        if (!results[2]) {
            return '';
        }
        return decodeURIComponent(results[2].replace(/\+/g, ' '));
    }

    function removeFanDirectly() {
        var thisBtn = $(this);
        thisBtn.off('click');
        thisBtn.text('正在移除');
        thisBtn.css('background-color', '#32a2d5');

        var uid = $(this).attr('fanuid');
        var fnick = $(this).attr('fanfnick');
        var data = 'uid=' + uid;

        var thisli = $(this).parent().parent().parent();

        $.ajax({
            type: 'POST',
            url: '/aj/f/remove?ajwvr=6&__rnd=' + Math.round(new Date().getTime()),
            data: data,
            dataType: 'json',
            async: true,
            success: function(msg) {
                var code = msg.code;
                if (code == 100000) {
                    console.log('移除粉丝:' + fnick);
                    thisli.remove();
                } else {
                    thisBtn.css('background-color', '#9e9e9e');
                    thisBtn.text('移除失败');
                    console.log('移除失败,可能是网络错误,或是微博更新了界面。');
                }
            },
            error: function(msg) {
                console.log(msg);
            }
        });
    }
})();