Legacy Chat

Replaces new chat

  1. // ==UserScript==
  2. // @name Legacy Chat
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.13
  5. // @include *://*.twitch.tv/*
  6. // @exclude *://*.twitch.tv/*/chat
  7. // @exclude *://api.twitch.tv/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
  9. // @grant none
  10. // @description Replaces new chat
  11. // ==/UserScript==
  12.  
  13. var channelURL = '';
  14.  
  15. function cleanName(str) {
  16. var strL = str.length;
  17. for (var i = 0; i < strL; i++) {
  18. if (!/^\w+$/.test(str[i])) {
  19. return str.slice(0, i);
  20. }
  21. }
  22. return str;
  23. }
  24.  
  25. function replaceChat(url) {
  26. var chan = url.split("/");
  27. var chanName = cleanName(chan[3]);
  28. if (chanName == "videos")
  29. return;
  30. var embeddedChat = '<iframe class="legacy-chat" src="https://www.twitch.tv/'+chanName+'/chat" height="100%" style="width: var(--ffz-chat-width)"></iframe> ';
  31. $('[class="tw-full-height tw-block tw-flex-grow-0 tw-flex-shrink-0 tw-relative"]').html(embeddedChat);
  32. }
  33.  
  34. var observer = new MutationObserver(function() {
  35. var url = window.location.href;
  36. if ((!$('[class="tw-full-height tw-block tw-flex-grow-0 tw-flex-shrink-0 tw-relative"] .legacy-chat').length) || (channelURL != url)) {
  37. channelURL = url;
  38. replaceChat(url);
  39. }
  40. });
  41.  
  42. var config = {
  43. attributes: true,
  44. childList: true,
  45. characterData: true
  46. };
  47.  
  48. observer.observe(document.body, config);