NightBot-AutoDJ song-name helper

Make craftwar's obs plugin (https://craftwarblog.blogspot.com/2018/01/obs-plugin-playing-song.html) able to get NightBot-AutoDJ song name.

目前为 2018-12-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author craftwar
  3. // @name NightBot-AutoDJ song-name helper
  4. // @description Make craftwar's obs plugin (https://craftwarblog.blogspot.com/2018/01/obs-plugin-playing-song.html) able to get NightBot-AutoDJ song name.
  5. // @copyright 2018, craftwar (https://craftwarblog.blogspot.com/)
  6. // @license GPL-3.0+; https://www.gnu.org/licenses/gpl-3.0.txt
  7. // @homepageURL https://github.com/craftwar/userscript/tree/master/NightBot-song-name-helper
  8. // @version 0.1.20181230
  9. // @namespace github.com.craftwar
  10. // @match https://beta.nightbot.tv/song_requests*
  11. // @grant none
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. (() => {
  16. const body_observer = new MutationObserver( (record, observer)=> {
  17. const element = document.querySelector(".current-track > h4:first-child > strong:first-child").childNodes[0];
  18. if (element) {
  19. observer.disconnect();
  20.  
  21. const song_observer = new MutationObserver( ()=> {
  22. document.title = element.wholeText + " - YouTube";
  23. });
  24. song_observer.observe(element, { characterData: true });
  25. }
  26. });
  27.  
  28. const body_element = document.querySelector("body");
  29. body_observer.observe(body_element, { subtree: true, childList: true });
  30. })();