Greasy Fork

Greasy Fork is available in English.

饭否-手机版同时回复多人

解决 m.fanfou.com 上回复消息时默认只能回复该消息中单个人的问题

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name 饭否-手机版同时回复多人
// @version 0.9
// @author HackMyBrain
// @description 解决 m.fanfou.com 上回复消息时默认只能回复该消息中单个人的问题
// @include http://m.fanfou.com/*
// @namespace http://greasyfork.icu/users/2844
// ==/UserScript==


(function (){
    var my_link = document.querySelector('a[accesskey="1"]').href;
    var textarea = document.getElementsByTagName('textarea')[0];

    function clearDuplicate(attr, NodeList, SingleNode) {
        var arr = [].slice.call(NodeList);
        if ( SingleNode != undefined ) {
            arr.unshift(SingleNode);
        }
        for(var i=0; i < arr.length; i++){
            for(var j=i+1; j < arr.length; j++) {
                if( arr[i][attr] === arr[j][attr] ) {
                    arr.splice(j, 1);
                    j--;
                }
            }
        }
        return arr;
    }
    
    function saveNicknames(e) {
        if( !e.altKey && /^http\:\/\/m\.fanfou\.com\/msg\.reply\//i.test(e.target.href) ){
            var re_anchor = e.target;
            var target_post = re_anchor.parentElement.parentElement;
            var formers = target_post.getElementsByClassName('former');
            if(formers.length > 0) {
                var author = target_post.querySelector('a.p');
                if ( !author ) {
                    if ( /^\/mentions($|\/)/.test(location.pathname) ) {
                        author = target_post.firstElementChild;
                    }
                    else if ( /^\/statuses\//.test(location.pathname) ) {
                        author = document.querySelector('b > a');
                    }
                    else {
                        author = document.createElement('a');
                        author.href = location.pathname.match(/\/[^\/]+/)[0];
                        author.innerHTML = document.title.replace(/饭否 \| /,'');
                    }
                }
                var toBeReplied = clearDuplicate('href', formers, author);
                var nicknames = [];
                for(var i = 0; i < toBeReplied.length; i++){
                    if( toBeReplied[i].href != my_link ){
                        nicknames.push('@' + toBeReplied[i].innerHTML);
                    }
                }
                nicknames = nicknames.join(' ') + ' ';
                sessionStorage.setItem('_reply_helper_nicknames_', nicknames);
            }
        }
    }
    
    function outputNicknames() {
        textarea.value = sessionStorage.getItem('_reply_helper_nicknames_');
        sessionStorage.removeItem('_reply_helper_nicknames_');
    }
    
    document.addEventListener('click', saveNicknames, false);
    if ( /\/msg\.reply\//i.test(location.href) ) {
        if ( !!sessionStorage.getItem('_reply_helper_nicknames_') ) {
            outputNicknames();
        }
        textarea.focus();
        var len = textarea.value.length;
        textarea.setSelectionRange(len, len);
    }
})();