|
// ==UserScript== |
|
// @name Twitch hitsquadgodfather command buttons |
|
// @namespace https://kurotaku.de |
|
// @version 1.7 |
|
// @description Adds buttons to send commands in the Twitch chat |
|
// @author Kurotaku |
|
// @license MIT |
|
// @match https://www.twitch.tv/hitsquadgodfather* |
|
// @match https://www.twitch.tv/*/hitsquadgodfather/chat* |
|
// @icon https://static.twitchcdn.net/assets/favicon-32-e29e246c157142c94346.png |
|
// @updateURL https://gist.github.com/Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e/raw/Twitch%2520hitsquadgodfather%2520command%2520buttons.user.js |
|
// @downloadURL https://gist.github.com/Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e/raw/Twitch%2520hitsquadgodfather%2520command%2520buttons.user.js |
|
// @require https://gist.github.com/Kurotaku-sama/9ebeb659500f6eee2f780344948e1e8f/raw/kuros_library.user.js |
|
// @require https://gist.github.com/Kurotaku-sama/a5a08a94398ea55123f8c09069fe68ee/raw/kuros_twitch_button_library.user.js |
|
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js |
|
// @grant GM_getValue |
|
// @grant GM_setValue |
|
// @grant GM_registerMenuCommand |
|
// ==/UserScript== |
|
|
|
|
|
let twitch_channel = 'hitsquadgodfather'; |
|
|
|
(async function() { |
|
await init_gm_config(); // Initialize the configuration |
|
main(); |
|
|
|
// Zosky's restart timer |
|
if(GM_config.get("script_enabled")) |
|
if(GM_config.get("restart_timer")) |
|
zoskys_restart_timer(); |
|
})(); |
|
|
|
|
|
function init_gm_config() { |
|
GM_registerMenuCommand('Settings', () => { |
|
GM_config.open(); |
|
}); |
|
let frame = document.createElement('div'); |
|
document.body.appendChild(frame); |
|
GM_config.init( |
|
{ |
|
'id': 'configuration', |
|
'title': 'Twitch hitsquadgodfather config', |
|
'fields': |
|
{ |
|
'script_enabled': |
|
{ |
|
'label': 'Enable/Disable the script', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'auth_username': |
|
{ |
|
'label': 'Username', |
|
'type': 'textbox' |
|
}, |
|
'auth_oauth': |
|
{ |
|
'label': 'Oauth (required for IRC connection to chat!)<br>Can be generated here: https://twitchapps.com/tmi/', |
|
'type': 'textbox' |
|
}, |
|
'restart_timer': { |
|
'label': 'Show approx stream restart timer for voucher redemptions<br>Function made by zosky <3', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'voucher_buttons': { |
|
'label': 'Voucher redemption buttons', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'buttons_general': |
|
{ |
|
'label': 'General buttons', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'buttons_trivia': |
|
{ |
|
'label': 'Trivia buttons', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'showdown_buttons': { |
|
'label': 'Showdown buttons', |
|
'type': 'checkbox', |
|
'default': true |
|
}, |
|
'bypass_shadowban': { |
|
'label': 'Prevent Shadowban:<br>Enable this only, if you get shadowbanned after a couple of commands.<br>(Shadowban is when your messages are temporarily not appear)', |
|
'type': 'checkbox', |
|
'default': false |
|
}, |
|
}, |
|
'events': { |
|
'save': () => {location.reload()}, |
|
}, |
|
'frame': frame, |
|
}); |
|
} |
|
|
|
|
|
async function generate_voucher_buttons() { |
|
insert_voucher_buttons( |
|
generate_voucher_button("1,000 Clams Voucher", 5000, "+1k Clams") + |
|
generate_voucher_button("2,000 Clams Voucher", 10000, "+2k Clams") |
|
); |
|
} |
|
|
|
|
|
function generate_command_buttons() { |
|
let buttongroups = ""; |
|
if(GM_config.get("buttons_general")) |
|
buttongroups += `${btngrp_label("General")} |
|
<div class="k-buttongroup"> |
|
${btngrp_button("hitsquad", "Hitsquad")} |
|
${btngrp_button("strikes", "Strikes")} |
|
${btngrp_button("coderaid", "Coderaid")} |
|
</div>`; |
|
|
|
if(GM_config.get("buttons_trivia")) |
|
buttongroups += `${btngrp_label("Trivia")} |
|
<div class="k-buttongroup"> |
|
${btngrp_button("answer1", "1")} |
|
${btngrp_button("answer2", "2")} |
|
${btngrp_button("answer3", "3")} |
|
${btngrp_button("answer4", "4")} |
|
${btngrp_button("triviapoints", "Points")} |
|
</div>`; |
|
|
|
if(GM_config.get("showdown_buttons")) { |
|
// Selection |
|
buttongroups += `${btngrp_label("Showdown")} |
|
<div class="k-buttongroup"> |
|
${btngrp_button("wizard", "Wizard")} |
|
${btngrp_button("knight", "Knight")} |
|
${btngrp_button("cleric", "Cleric")} |
|
${btngrp_button("experience", "Experience")} |
|
</div>`; |
|
// Labels to show roles |
|
buttongroups += `<div class="k-labelgroup"> |
|
${lblgrp_label("wizard", "Wizard")} |
|
${lblgrp_label("knight", "Knight")} |
|
${lblgrp_label("cleric", "Cleric")} |
|
${lblgrp_label("close", "Close")} |
|
</div>`; |
|
// Wizard |
|
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="wizard"> |
|
${btngrp_button("attack", "Attack", "targetbutton")} |
|
${btngrp_button("flames", "Flames")} |
|
${btngrp_button("shield", "Shield")} |
|
${btngrp_button("moan", "Moan")} |
|
</div>`; |
|
// Knight |
|
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="knight"> |
|
${btngrp_button("attack", "Attack", "targetbutton")} |
|
${btngrp_button("frenzy", "Frenzy")} |
|
${btngrp_button("rally", "Rally")} |
|
${btngrp_button("moan", "Moan")} |
|
</div>`; |
|
// Cleric |
|
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="cleric"> |
|
${btngrp_button("attack", "Attack", "targetbutton")} |
|
${btngrp_button("divine", "Divine", "targetbutton")} |
|
${btngrp_button("heal", "Heal")} |
|
${btngrp_button("moan", "Moan")} |
|
</div>`; |
|
} |
|
|
|
buttongroups += `</div> |
|
<div id="targets" class="k-buttongroups hidden" data-action=""> |
|
<label class="k-buttongroup-label targets">Targets</label> |
|
<div class="k-buttongroup"> |
|
${btngrp_button("1", "1")} |
|
${btngrp_button("2", "2")} |
|
${btngrp_button("3", "3")} |
|
${btngrp_button("4", "4")} |
|
${btngrp_button("5", "5")} |
|
<button class="closebutton">Close</button> |
|
</div></div>`; |
|
|
|
insert_command_button(buttongroups); |
|
} |
|
|
|
|
|
// Additional functions |
|
function show_role(event) { |
|
let roles = document.querySelectorAll(".k-role"); |
|
roles.forEach(el => { |
|
if(el.getAttribute("data-role") === event.target.getAttribute("data-role")) |
|
el.classList.remove("hidden") |
|
else |
|
el.classList.add("hidden") |
|
}); |
|
} |
|
|
|
|
|
function zoskys_restart_timer() { // Thanks to zosky for this great function! |
|
setInterval(()=>{ |
|
// get the current length |
|
let t = document.querySelector('.live-time').textContent.split(':').map(n=>parseInt(n,10)) |
|
// parse & calc |
|
let seconds = (t[0]*3600) + t[1]*60 + t[2] |
|
let maxStreamTime = 172800 |
|
let timeLeft = maxStreamTime - seconds |
|
let h = Math.floor(timeLeft / 3600) |
|
let m = Math.floor((timeLeft - (h * 3600)) / 60) |
|
let s = timeLeft - (h * 3600) - (m * 60) |
|
// format |
|
if (h < 10) h = "0"+h |
|
if (m < 10) m = "0"+m |
|
if (s < 10) s = "0"+s |
|
let tLeftString = `${h}:${m}:${s}` |
|
// add to page |
|
const newNode = document.createElement("div") |
|
const textNode = document.createTextNode(`Approx ${tLeftString} till stream restart for vouchers`) |
|
newNode.appendChild(textNode) |
|
newNode.id = 'timeLeft' |
|
newNode.style['width'] = '100%' |
|
newNode.style['text-align'] = 'center' |
|
newNode.style['font-size'] = 'x-large' |
|
newNode.style['background'] = 'purple' |
|
const mastHead = document.querySelectorAll("section > div")[0] |
|
try { document.getElementById('timeLeft').remove() } catch {console.log('nodeNotPresentYet') } |
|
mastHead.insertBefore(newNode, mastHead.children[0]) |
|
}, 1000 ) |
|
} |
Sry than i cant rly help you bcs I can't reproduce it, what you could try is in line 188:
sendMessageToTwitchChat(suffix + cmd); // + ' - ' + makeid(5));
turn it into this:
sendMessageToTwitchChat(suffix + cmd + ' - ' + makeid(5));
Tell me if it worked than please, if it works I will make this as an separate option in the settings.