OnePlusBBS QuickKey

一加社区快捷键

当前为 2019-12-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OnePlusBBS QuickKey
// @description  一加社区快捷键
// @namespace    https://greasyfork.org/
// @author       choosezzz
// @version      1.3
// @match        https://www.oneplusbbs.com/forum*
// @match        https://www.oneplusbbs.com/thread*
// @match        https://www.oneplusbbs.com/homemod-space-uid*
// @icon         https://static.oneplus.cn/data/attachment/common/4c/common_121_icon.png
// @grant        none
// ==/UserScript==

(function() {
    //65-90 [a-z]
    //keyCode 48 96 = 0
    //keyCode 49 97 = 1
    //keyCode 50 98 = 2
    //keyCode 51 99 = 3
    //keyCode 52 100 = 4
    //keyCode 53 101 = 5
    //keyCode 54 102 = 6
    //keyCode 55 103 = 7
    //keyCode 56 104 = 8
    //keyCode 57 105 = 9
    //event.ctrlKey,event.shiftKey,event .altKey

    //判断是否已显示操作选项
    var cateShow = false;
    //分类选项索引
    var cateIndex = 0;

    //移动操作
    var moveShow = false;
    //游乐园
    var moveIndex = 21;
    document.onkeydown = function(event) {
        var href = window.location.href;
        var e = event || window.event;
        if (!e) {
            return;
        }
        //个人主页
        if (href.search("homemod-space-uid*") != -1) {
            //Ctrl+Alt
            if (e.altKey && e.ctrlKey) {
                var uid = href.replace(/https:\/\/www.oneplusbbs.com\/homemod-space-uid-/g, "").replace(/.html/g, "");
                $("a_sendpm_" + uid).click();
            }
        }

        //Ctrl+number
        if (((e.keyCode >= 49 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 105)) && e.ctrlKey) {
            var msgId = e.keyCode - 96 < 0 ? e.keyCode - 48 : e.keyCode - 96;
            quickPaste(e, msgId);
        }

        //普通帖子页
        if (href.indexOf("thread-") != -1 || href.indexOf("viewthread") != -1) {
            handlePost(e);
        }

        //列表页
        if (href.indexOf("forum-") != -1) {
            handleList(e);
        }

    }
    //屏蔽默认快捷键
    function stopDefault(e) {

        // W3C标准
        if (e.preventDefault) {
            e.preventDefault();
        } else {
            //IE
            window.event.returnValue = false;
        }
        return false;
    }

    function quickPaste(e, id) {

        var href = window.location.href;
        stopDefault(e);
        var quickMsg = new Array(
            // Ctrl + 1
            "输入自定义内容",
            // Ctrl + 2
            "输入自定义内容",
            // Ctrl + 3
            "输入自定义内容",
            // Ctrl + 4
            "输入自定义内容",
            // Ctrl + 5
            "输入自定义内容",
            // Ctrl + 6
            "输入自定义内容",
            // Ctrl + 7
            "输入自定义内容",
            // Ctrl + 8
            "输入自定义内容",
            // Ctrl + 9
            "输入自定义内容"
        );

        //帖子页
        if (href.search("thread-") != -1 || href.indexOf("viewthread") != -1) {
            //操作说明输入
            var mods = $("fwin_mods");
            if (mods && mods.style.display != "none") {
                var reason = $("reason");
                if (reason && quickMsg.length >= id) {
                    reason.value = quickMsg[id - 1];
                    //reason.select();
                }
            }
            //回帖输入
            var reply = $("fwin_reply");
            if (reply && reply.style.display != "none") {
                var postmessage = $("postmessage");
                if (postmessage && quickMsg.length >= id) {
                    postmessage.value = quickMsg[id - 1];
                }
            }
        }
        //个人页,快速发送消息内容
        if (href.search("homemod-space-uid-") != -1) {
            var showMsgBox = $("fwin_showMsgBox");
            if (showMsgBox && showMsgBox.style.display != "none") {
                var pmmessage = $("pmmessage");
                if (pmmessage && quickMsg.length >= id) {
                    pmmessage.value = quickMsg[id - 1];
                }
            }
        }
        //管理页面
        if (href.search("op=ban&uid=")!=-1){
            $("ct").getElementsByClassName("pt")[0].value=quickMsg[id - 1];
        }
    }

    function handlePost(e) {

        // Ctrl + z 快速回复
        if (e.keyCode == 90 && e.ctrlKey) {
            stopDefault(e);
            $("post_reply").click();
            return;
        }

        //获取操作列表
        var modMenu = $("modmenu");
        if (!modMenu) {
            console.log("当前板块无权限");
            return;
        }
        var links = modMenu.getElementsByTagName("a");
        //Ctrl+Alt 快速分类功能
        if (e.altKey && e.ctrlKey) {
            stopDefault(e);
            //快捷点击分类链接
            if (!cateShow) {
                let type = links[10];
                if (type) {
                    type.click();
                    cateShow = true;
                }
            } else {
                let types = $("typeid");
                if (types && types.options.length > 0) {
                    types.options[cateIndex].selected = "true";
                    cateIndex++;
                }
                if (cateIndex == types.options.length) {
                    cateIndex = 0;
                }
            }
            return;
        }
        //Ctrl+X 快速移动功能
        if (e.ctrlKey && e.keyCode == 88) {
            stopDefault(e);
            //快捷点击移动链接
            if (!moveShow) {
                let type = links[9];
                if (type) {
                    type.click();
                    moveShow = true;
                }
            } else {
                var moveTo = $("moveto");
                if (moveTo && moveTo.options.length > 0) {
                    moveTo.options[moveIndex].selected = "true";
                    moveTo.onchange();
                    //游乐园 <--> 轻摄影
                    moveIndex = moveIndex == 21 ? 13 : 21;
                }

            }
        } else {
            //重置
            moveIndex = 21;
            cateIndex = 0;
            moveShow = false;
            cateShow = false;
        }
    }

    function handleList(e) {
        var checkBoxs = document.getElementsByClassName("o");
        if (!checkBoxs || checkBoxs.length < 5) {
            console.log("此版块权限");
        }
        var mdly = $("mdly");
        if (mdly) {
            var ops = mdly.getElementsByTagName("p")[0].getElementsByTagName("a");
            if (e.altKey && e.ctrlKey) {
                stopDefault(e);
                ops[2].click();
            }
            if (e.ctrlKey && e.keyCode == 88) {
                stopDefault(e);
                ops[1].click();
            }
            if (e.keyCode == 90 && e.ctrlKey) {
                stopDefault(e);
                ops[0].click();
            }
        }
    }
})();