Fic's Mixify Auto Welcome Script

This script can be used on Mixify.com while streaming your DJ set. The main reason why I created this script is that I couldn't see every single person who enters the stream so I thought it could be nice if script can annonce in chat who entered the stream with a warm welcome message.

当前为 2015-08-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fic's Mixify Auto Welcome Script
  3. // @namespace Booth
  4. // @include http://www.mixify.com/*/live/*
  5. // @version 1.3
  6. // @grant none
  7. // @description This script can be used on Mixify.com while streaming your DJ set. The main reason why I created this script is that I couldn't see every single person who enters the stream so I thought it could be nice if script can annonce in chat who entered the stream with a warm welcome message.
  8. // ==/UserScript==
  9.  
  10. var session = []; /* List of all users that entered the stream */
  11. var DJ = $("#marqueeTitle")[0].innerHTML.replace('</h1>', '').replace('<h1>', '').trim(); /*Currnt DJ name*/
  12. var me = $("ul#userDropDown li:eq(2) a").text().trim(); /* Your name on Mixify */
  13. var msgList = ["Welcome ", "Ez ", "Yo ", "Greetings ", "Sup ", "Hey ", "Hi ", "Whazzup ", "Hello"]; /* List of greetings */
  14. var msg;
  15.  
  16. /* If you are on your own stream script is running */
  17. if (me === DJ) {
  18.  
  19. var url = "http://www.mixify.com/room/spectators/cache/1/?";
  20. var dataString = $("#specatorsDockItem").attr("data-querystring"); /* Getting url to call AJAX */
  21. url = url + dataString;
  22.  
  23. if (localStorage.getItem("active") === null) { /* Was this stream refreshed? */
  24. localStorage.setItem("active", true); /* You entered the stream for the first time */
  25. session.push(DJ); /* Ignore DJ while sending welcome msg */
  26. } else {
  27. FillUsersAfterRefresh(); /* You refreshed the stream, ignore current guests in the room */
  28. }
  29.  
  30. setInterval( /* Calling AJAX that is called my hovering mouse over attendees icon */
  31. function () {
  32.  
  33. jQuery.ajaxSetup({ async: false }); /* Getting data via AJAX */
  34. var data = jQuery.get(url);
  35. var toObject = $(data.responseText); /* Converting string to object */
  36. var users = $(toObject).find(".username"); /* Getting all guests on stream */
  37.  
  38. for (i = 0; i < users.length; i++) {
  39. if (users[i].getAttribute("target") !== null && users[i].innerHTML != "Guest" && jQuery.inArray(users[i].innerHTML.trim(), session) === -1) { /* Ignore duplicates and guests */
  40. console.log("New guest is: " + users[i].innerHTML);
  41. msg = msgList[Math.floor(Math.random() * msgList.length)]; /* Set random msg from msgList */
  42. $("#chat_input").val(msg + users[i].innerHTML.trim() + "!"); /* Post welcome msg in chat */
  43. $('#chat_input').focus().trigger(jQuery.Event('keydown', { keyCode: 13 }));
  44. session.push(users[i].innerHTML.trim()); /* Mark user as the one that already visited the stream */
  45. }
  46. }
  47. }, 5000); /* Check for new guests every 5 seconds (Change 5000 ms to any other value you want) */
  48. }
  49.  
  50. function FillUsersAfterRefresh() {
  51. jQuery.ajaxSetup({ async: false });
  52. var data = jQuery.get(url);
  53. var toObject = $(data.responseText);
  54. var users = $(toObject).find(".username");
  55. for (i = 0; i < users.length; i++) {
  56. if (users[i].getAttribute("target") !== null && users[i].innerHTML != "Guest")
  57. session.push(users[i].innerHTML.trim());
  58. }
  59. }