Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Nice Names Twitch
  3. // @version 0.1
  4. // @description Changes the background of chats to a contrasting color
  5. // @author Jerald J
  6. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  7. // @match https://www.twitch.tv/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. function invert(rgb) {
  13. rgb = [].slice.call(arguments).join(",").replace(/rgb\(|\)|rgba\(|\)|\s/gi, '').split(',');
  14. for (var i = 0; i < rgb.length; i++) rgb[i] = (i === 3 ? 1 : 255) - rgb[i];
  15. color = rgbToHex(rgb[0], rgb[1], rgb[2]);
  16. color = shadeBlend(-0.5,color);
  17. console.log(color);
  18. return color;
  19. }
  20.  
  21. function shadeBlend(p,c0,c1) {
  22. var n=p<0?p*-1:p,u=Math.round,w=parseInt;
  23. if(c0.length>7){
  24. var f=c0.split(","),t=(c1?c1:p<0?"rgb(0,0,0)":"rgb(255,255,255)").split(","),R=w(f[0].slice(4)),G=w(f[1]),B=w(f[2]);
  25. return "rgb("+(u((w(t[0].slice(4))-R)*n)+R)+","+(u((w(t[1])-G)*n)+G)+","+(u((w(t[2])-B)*n)+B)+")"
  26. }else{
  27. var f=w(c0.slice(1),16),t=w((c1?c1:p<0?"#000000":"#FFFFFF").slice(1),16),R1=f>>16,G1=f>>8&0x00FF,B1=f&0x0000FF;
  28. return "#"+(0x1000000+(u(((t>>16)-R1)*n)+R1)*0x10000+(u(((t>>8&0x00FF)-G1)*n)+G1)*0x100+(u(((t&0x0000FF)-B1)*n)+B1)).toString(16).slice(1)
  29. }
  30. }
  31.  
  32. function rgbToHex(r, g, b) {
  33. return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
  34. }
  35.  
  36. function componentToHex(c) {
  37. var hex = c.toString(16);
  38. return hex.length == 1 ? "0" + hex : hex;
  39. }
  40. setInterval(function(){
  41. $(".chat-author__display-name").each(function() {
  42. $(this).parent().parent().parent().css("background-color",invert($(this).css("color")));
  43. });
  44. }, 500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement