Skip to content

Instantly share code, notes, and snippets.

@revenkroz
Created July 5, 2020 16:49
Show Gist options
  • Save revenkroz/9b6623e00d3cdf12434021b0bea6236f to your computer and use it in GitHub Desktop.
Save revenkroz/9b6623e00d3cdf12434021b0bea6236f to your computer and use it in GitHub Desktop.
(function() {
function autoSend(value) {
const elem = document.querySelector('[data-a-target="chat-input"]');
const valueSetter = Object.getOwnPropertyDescriptor(elem, 'value').set;
const proto = Object.getPrototypeOf(elem);
const prototypeValueSetter = Object.getOwnPropertyDescriptor(proto, 'value').set;
if (valueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(elem, value);
} else {
valueSetter.call(elem, value);
}
elem.dispatchEvent(new Event('input', { bubbles: true }));
document.querySelector('[data-a-target="chat-send-button"]').click();
}
const controls = document.createElement('div');
controls.style = `
position: fixed;
top: 24px;
left: 24px;
background-color: #fff;
padding: 16px;
border-radius: 4px;
display: flex;
flex-direction: row;
justify-content: space-between;
z-index: 999999;
`;
const commands = [
// default
{
name: '!roll20',
command: '!roll20',
},
{
name: '!roll12',
command: '!roll12',
},
{
name: '!roll8',
command: '!roll8',
},
{
name: '!roll6',
command: '!roll6',
},
// fight
{
name: 'Попадание',
command: '!roll20',
modifier: 5,
message: 'Я попал на',
},
{
name: 'Урон моргенштерном',
command: '!roll8',
modifier: 3,
message: 'Урон моргенштерном',
},
{
name: 'Урон скимитаром',
command: '!roll6',
modifier: 3,
message: 'Урон скимитаром',
},
// other
{
name: 'Инициатива',
command: '!roll20',
modifier: -1,
message: 'Моя инициатива',
},
{
name: 'Внимание',
command: '!roll20',
modifier: 3,
message: 'Мое внимание',
},
{
name: 'Скрытность',
command: '!roll20',
modifier: -1,
message: 'Моя скрытность',
},
];
commands.forEach((command) => {
const numberBtn = document.createElement('div');
numberBtn.innerHTML = command.name;
numberBtn.classList.add('tw-core-button--primary');
numberBtn.style = `
cursor: pointer;
padding: 8px;
margin: 0 8px;
border-radius: 4px;
`;
numberBtn.addEventListener('click', () => {
autoSend(command.command);
if (typeof command.modifier !== 'undefined') {
setTimeout(function() {
const response = document.querySelector('.chat-line__message:last-child .text-fragment').innerText;
const responseNumber = parseInt(response.replace(/[А-Яа-яA-Za-z]/g, ''));
autoSend(`${command.message || 'У меня'}: ${responseNumber + command.modifier}`);
}, 1500);
}
});
controls.appendChild(numberBtn);
});
document.body.appendChild(controls);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment