Advertisement
Harieo

Twitch Extension Paste 1

Apr 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var twitch = window.Twitch.ext;
  2.  
  3. var authorizationComplete = false;
  4.  
  5. twitch.onAuthorized(function(credentials) {
  6. console.log("Auth complete");
  7. authorizationComplete = true;
  8.  
  9. document.getElementById("config-form").addEventListener("submit", handleFormSubmission);
  10. document.getElementById("submit-button").removeAttribute("disabled");
  11. //getConfiguration();
  12. });
  13.  
  14. twitch.configuration.onChanged(()=>{
  15. let config = twitch.configuration.broadcaster ? this.twitch.configuration.broadcaster.content : [];
  16. try {
  17. config = JSON.parse(config);
  18. } catch (e) {
  19. config = [];
  20. console.log(e.message);
  21. }
  22.  
  23. console.log(config);
  24. })
  25.  
  26. function handleFormSubmission() {
  27. console.log("Handling form submission");
  28. console.log("Starting with: " + twitch.configuration.broadcaster.content + " at " + twitch.configuration.broadcaster.version);
  29. if (!authorizationComplete) {
  30. console.log("Call before auth");
  31. return;
  32. }
  33.  
  34. var usernameElement = document.getElementById("username-box");
  35. twitch.configuration.set("broadcaster", "2", JSON.stringify({
  36. "username": usernameElement.value,
  37. }));
  38. console.log("Done");
  39. console.log(JSON.stringify({
  40. "username": usernameElement.value
  41. }));
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement