Kekeke Highlight

Highlight same user in Kekeke chat

  1. // ==UserScript==
  2. // @name Kekeke Highlight
  3. // @name:zh-TW Kekeke Highlight
  4. // @namespace https://greasyfork.org
  5. // @version 0.0.1
  6. // @description Highlight same user in Kekeke chat
  7. // @description:zh-tw 在kekeke聊天室中,嗨賴指定使用者的留言。
  8. // @author george7551858
  9. // @icon http://www.google.com/s2/favicons?domain=https://kekeke.cc/
  10. // @include https://kekeke.cc/*
  11. // @include https://www.kekeke.cc/*
  12. // @license MIT
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. window.addEventListener('load', function() {
  17. 'use strict';
  18.  
  19. var highLightColor = 'yellow';
  20. var lastTargetColor;
  21.  
  22. console.log('Kekeke Highlight: start');
  23.  
  24. document.addEventListener('click', function (e) {
  25. if (e.originalTarget.classList.contains('SquareCssResource-message')
  26. || e.originalTarget.classList.contains('SquareCssResource-messageContainer')) {
  27. doHighLight(e.originalTarget);
  28. }
  29. });
  30.  
  31. var doHighLight = function(target){
  32. var targetChatContent = target.closest('.SquareCssResource-chatContent');
  33. var targetColorNickname = targetChatContent.querySelector('.GlobalCssResource-colorNickname');
  34. var targetNameColor = targetColorNickname.style.color;
  35. console.log('Kekeke Highlight: %c' + targetColorNickname.innerText + ' ' + targetNameColor,
  36. 'color:' + targetNameColor);
  37.  
  38. if (targetNameColor == lastTargetColor) {
  39. console.log('Kekeke Highlight: cancel');
  40. targetNameColor = '?';
  41. }
  42.  
  43. document.querySelectorAll('.SquareCssResource-chatContent').forEach(function(item){
  44. item.style.backgroundColor = ''; // clear all highlight
  45.  
  46. var chatNameColor = item.querySelector('.GlobalCssResource-colorNickname').style.color;
  47. if (chatNameColor == targetNameColor) {
  48. item.style.backgroundColor = highLightColor;
  49. }
  50. });
  51.  
  52. lastTargetColor = targetNameColor;
  53. };
  54. });