Created
April 13, 2019 02:52
-
-
Save Poeticalto/9d7ff00c8e0d86c8caf0cedee30ea933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name NewCompte Draft Site Bid Updater | |
// @namespace https://poeticalto.github.io/ | |
// @version 0.1 | |
// @description A script designed to send all updates from NewCompte's draft site to a specified location | |
// @author Poeticalto | |
// @match insert_draft_site_link_here | |
// @run-at document-end | |
// @grant unsafeWindow | |
// ==/UserScript== | |
// IMPORTANT: REMEMBER TO CHANGE THE MATCH CONDITION TO THE URL OF THE DRAFT SITE | |
// AND REMEMBER TO SET HOWEVER YOU'RE GOING TO SEND THE CHAT | |
(function() { | |
'use strict'; | |
// I'm not good enough at programming to figure out where the event triggers are, so this is a workaround. | |
// For this script, we are ignoring chat sent by users | |
// Define empty compare strings for the three types | |
let oldBid = ""; | |
let oldNomination = ""; | |
let oldWinner = ""; | |
// Note that each of the three types has a distinct class. | |
// However, since we are getting elements by class name, we need to check that there are | |
// actually elements to access before accessing. | |
// The "list-group-item bid" class corresponds to a user bidding | |
if (document.getElementsByClassName("list-group-item bid").length > 0) { | |
// All chat is stylized as "timestamp | chat", so remove the timestamp by splitting | |
oldBid = document.getElementsByClassName("list-group-item bid")[0].innerText.split(" | ")[1]; | |
} | |
// The "list-group-item nomination" class corresponds to a user nominating | |
if (document.getElementsByClassName("list-group-item nomination").length > 0) { | |
oldNomination = document.getElementsByClassName("list-group-item nomination")[0].innerText.split(" | ")[1]; | |
} | |
// The "list-group-item winningbid" class corresponds to the system message declaring the winning bid | |
if (document.getElementsByClassName("list-group-item winningbid").length > 0) { | |
oldWinner = document.getElementsByClassName("list-group-item winningbid")[0].innerText.split(" | ")[1]; | |
} | |
setInterval(check, 250); | |
// check function compares the most recent element in each tag to the saved once. | |
// If they differ, then send the most recent element and save. Otherwise, skip. | |
function check() { | |
if (document.getElementsByClassName("list-group-item bid").length > 0) { | |
if (oldBid != document.getElementsByClassName("list-group-item bid")[0].innerText.split(" | ")[1]) { | |
oldBid = document.getElementsByClassName("list-group-item bid")[0].innerText.split(" | ")[1]; | |
sendUpdate(oldBid); | |
} | |
} | |
if (document.getElementsByClassName("list-group-item nomination").length > 0) { | |
if (oldNomination != document.getElementsByClassName("list-group-item nomination")[0].innerText.split(" | ")[1]) { | |
oldNomination = document.getElementsByClassName("list-group-item nomination")[0].innerText.split(" | ")[1]; | |
sendUpdate(oldNomination); | |
} | |
} | |
if (document.getElementsByClassName("list-group-item winningbid").length > 0) { | |
if (oldWinner != document.getElementsByClassName("list-group-item winningbid")[0].innerText.split(" | ")[1]) { | |
oldWinner = document.getElementsByClassName("list-group-item winningbid")[0].innerText.split(" | ")[1]; | |
sendUpdate(oldWinner); | |
} | |
} | |
} | |
})(); | |
function sendUpdate(sendText) { | |
console.log(sendText); | |
// The following example will send an update to a discord webhook. | |
let discordWebhook = "INSERT_WEBHOOK_HERE"; | |
let request = new XMLHttpRequest(); | |
request.open('POST', discordWebhook, true); | |
request.setRequestHeader('Content-Type', 'application/json'); | |
let data = JSON.stringify({"content":sendText, "username":"S18 Draft Bot"}); | |
request.send(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment