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.7
  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. var typedMsg;
  16.  
  17. /* If you are on your own stream script is running */
  18. if (me === DJ) {
  19.  
  20. var url = "http://www.mixify.com/room/spectators/cache/1/?";
  21. var dataString = $("#specatorsDockItem").attr("data-querystring"); /* Getting url to call AJAX */
  22. url = url + dataString;
  23.  
  24. if (sessionStorage.getItem("active") === null) { /* Was this stream refreshed? */
  25. sessionStorage.setItem("active", true); /* You entered the stream for the first time */
  26.  
  27. } else {
  28. FillUsersAfterRefresh(); /* You refreshed the stream, ignore current guests in the room */
  29. }
  30. session.push(DJ); /* Ignore DJ while sending welcome msg */
  31. setInterval( /* Calling AJAX that is called my hovering mouse over attendees icon */
  32. function () {
  33.  
  34. jQuery.ajaxSetup({ async: false }); /* Getting data via AJAX */
  35. var data = jQuery.get(url);
  36. var toObject = $(data.responseText); /* Converting string to object */
  37. var users = $(toObject).find(".username"); /* Getting all guests on stream */
  38.  
  39. for (i = 0; i < users.length; i++) {
  40. if (users[i].getAttribute("target") !== null && users[i].innerHTML != "Guest" && jQuery.inArray(users[i].innerHTML.trim(), session) === -1) { /* Ignore duplicates and guests */
  41. console.log("New guest is: " + users[i].innerHTML);
  42.  
  43. typedMsg = $("#chat_input").val(); /* Save current msg in textbox */
  44.  
  45. msg = msgList[Math.floor(Math.random() * msgList.length)]; /* Set random msg from msgList */
  46. $("#chat_input").val(msg + users[i].innerHTML.trim() + "!"); /* Post welcome msg in chat */
  47. $('#chat_input').focus().trigger(jQuery.Event('keydown', { keyCode: 13 }));
  48.  
  49. $("#chat_input").val(typedMsg); /* Return typed msg in textbox */
  50.  
  51. session.push(users[i].innerHTML.trim()); /* Mark user as the one that already visited the stream */
  52. }
  53. }
  54. }, 5000); /* Check for new guests every 5 seconds (Change 5000 ms to any other value you want) */
  55. }
  56.  
  57. function FillUsersAfterRefresh() {
  58. jQuery.ajaxSetup({ async: false });
  59. var data = jQuery.get(url);
  60. var toObject = $(data.responseText);
  61. var users = $(toObject).find(".username");
  62. for (i = 0; i < users.length; i++) {
  63. if (users[i].getAttribute("target") !== null && users[i].innerHTML != "Guest")
  64. session.push(users[i].innerHTML.trim());
  65. }
  66. }