口碑关系 自动删除好友的Greasemonkey脚本

 无聊的好友太多了, 一个一个删除太慢了,只好写个Greasemonkey脚本自动完成:

具体实现的功能:

在好友的列表页面( http://guanxi.koubei.com/apps/friend/myfriends.php?cat_id=356&page=1 类似的页面), 右上角会自动出现一个 remove按钮,选中你想删除的好友,直接点击这个按钮就OK了, 最后会提醒你done, 点击后刷新当前页面.

 

具体的实现代码如下, 接下来该怎么作就看你的了,不会的自己google.

 

// ==UserScript==
// @name           removefriend
// @namespace      removefriend
// @description    remove friend
// @include        http://guanxi.koubei.com/apps/friend/myfriends.php*
// ==/UserScript==


function doRemove()
{
    var url = 'http://guanxi.koubei.com/apps/friend/interface/edit_friend.php';
    var _w = unsafeWindow;
    var _d = document;
    var _show = null;
    var sc = 0;
    var rc = 0;
    function done() {
        alert("done");
        _w.location.href = _w.location.href;
    }
    function getUrl(url, data) {
        var str = '';
        for(var i in data) {
            if(str) str += '&';
            str += i + "=" + encodeURIComponent(data[i]);
        }
        url = url.indexOf("?") > 7 ? (url + "&" + str) : (url + "?" + str);
       
        GM_xmlhttpRequest({
            method:"GET",
            url:url,
            onload:function(o){rc++; if(rc == sc) {done();}},
            onerror:function(){}
        });
        sc++;
       
    }
    function begin(o) {
        var inputs = _d.getElementsByTagName("INPUT");
        for(var i = 0, len = inputs.length; i < len; i ++) {
            // 如果这个links
            if(encodeURIComponent(inputs[i].name == 'contact%5B%5D') && inputs[i].checked) {
                getUrl(url, {"action" : "remove_friend_relation", "contact[]" : inputs[i].value, "crumb" : _w.crumb });
               
            }
        }
    }
    function addButton() {
        if(!_show) {
            _show = _d.createElement("div");
            var html = "<style>#gxd-btn{background-color:#ccc;width:200px;position:absolute;left:600px;top:20px;}</style>";
            html += "<div id='gxd-btn'><input type='button' value='Remove'></div>";
            _show.innerHTML = html;
            _d.body.appendChild(_show);
            _show.addEventListener("click", begin, false);
        }
    }
    addButton();
}
window.addEventListener("load", doRemove, false);

This article is posted by on , link is .

Leave a reply

  • says:
    哎,问题是产品是否乐意呢?
  • says:
    我靠,作为关系的工程师,你应该直接把这个功能加入到关系里面。