Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Nice Names Twitch
- // @version 0.1
- // @description Changes the background of chats to a contrasting color
- // @author Jerald J
- // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
- // @match https://www.twitch.tv/*
- // @grant none
- // ==/UserScript==
- function invert(rgb) {
- rgb = [].slice.call(arguments).join(",").replace(/rgb\(|\)|rgba\(|\)|\s/gi, '').split(',');
- for (var i = 0; i < rgb.length; i++) rgb[i] = (i === 3 ? 1 : 255) - rgb[i];
- color = rgbToHex(rgb[0], rgb[1], rgb[2]);
- color = shadeBlend(-0.5,color);
- console.log(color);
- return color;
- }
- function shadeBlend(p,c0,c1) {
- var n=p<0?p*-1:p,u=Math.round,w=parseInt;
- if(c0.length>7){
- 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]);
- 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)+")"
- }else{
- 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;
- 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)
- }
- }
- function rgbToHex(r, g, b) {
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
- }
- function componentToHex(c) {
- var hex = c.toString(16);
- return hex.length == 1 ? "0" + hex : hex;
- }
- setInterval(function(){
- $(".chat-author__display-name").each(function() {
- $(this).parent().parent().parent().css("background-color",invert($(this).css("color")));
- });
- }, 500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement