Roll20 Character Switcher

Switches the chatting character to the one whose sheet or macro you clicked on

当前为 2017-11-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Roll20 Character Switcher
// @namespace    de.idrinth
// @homepage     https://github.com/Idrinth/Roll20-Character-Switcher
// @version      1.2.0
// @description  Switches the chatting character to the one whose sheet or macro you clicked on
// @author       Idrinth, KingMarth
// @match        https://app.roll20.net/editor/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var charswitcher = function(event) {
        var e = window.event || event;
        if (e.target.tagName !== 'BUTTON') {
            return;
        }
        var id='';
        if(e.target.hasAttribute('type') && e.target.getAttribute('type') === 'roll') {
            var character = e.target;
            while (!character.hasAttribute('data-characterid')) {
                if(!character.parentNode) {
                    return;
                }
                character = character.parentNode;
            }
            id = 'character|' + character.getAttribute('data-characterid');
        } else if(e.target.hasAttribute('class') && e.target.getAttribute('class') === 'btn') {
            var macro = e.target;
            while (!macro.hasAttribute('data-macroid')) {
                if(!macro.parentNode) {
                    return;
                }
                macro = macro.parentNode;
            }
            id = 'character|' + (macro.getAttribute('data-macroid')).split('|')[0];
        }
        if(!id) {
            return;
        }
        var select = document.getElementById('speakingas');
        for (var i = 0; i < select.options.length; i++) {
            if (select.options[i].value === id) {
                select.selectedIndex = i;
                return;
            }
        }
    };
    document.getElementsByTagName('body')[0].addEventListener('mousedown', charswitcher);
    document.getElementsByClassName('tokenactions')[0].addEventListener('mousedown', charswitcher);
})();