Orcpub to Dice by PCalc

Redirect Orcpub links to Dice

当前为 2024-01-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name     Orcpub to Dice by PCalc
// @include  https://www.dungeonmastersvault.com/*
// @namespace    http://tampermonkey.net/
// @description  Redirect Orcpub links to Dice
// @license MIT
// @author       Igor Makarov
// @grant        none
// @require      https://code.jquery.com/jquery-latest.js
// @version 0.0.1.20240121185703
// ==/UserScript==

var buttonsCount = 0;
function modifyButtons() {
    let buttons = $('button.roll-button');
    if (buttons.length == buttonsCount) {
        return;
    }
    buttonsCount = buttons.length;
    buttons.each(function() {
        $(this).prop('onclick', null);
        let text = $(this).text();
        $(this).click(function(e){
            e.stopPropagation();
            console.log(`Roll: ${text}`);
            let roll;
            if (text == '0') {
                roll = 'd20';
            } else if (text.startsWith('+') || text.startsWith('-')) {
                roll = `d20${text}`;
            } else {
                roll = text;
            }
            if (e.shiftKey) {
                window.location.href = `dice://roll/${roll}(DIS)`;
            } else if (e.ctrlKey || e.metaKey) {
                window.location.href = `dice://roll/${roll}(ADV)`;
            } else {
                window.location.href = `dice://roll/${roll}`;
            }
        });
    });
}

$(document).ready(modifyButtons);
$(document).bind("DOMSubtreeModified", modifyButtons);