I haven't done any javascript but I was wondering if someone could help me with a quick code for making all the usernames on twitch.tv blue in the chat if they are a certain color. I really hate the spring green color ( #00FF7F ) and would like to replace it with a solid blue ( #00000F )
The usernames in the char look something like this:
I can change one at a time manually by changing the color there in the inspect element but I would like a short thing I can put in the console that will pretty much be like:
That's possible:
You need to run the code once the page load, and run it again every time the page receives data (averagely complex) or run it in a timer (a bit more expensive).
var x = document.getElementsByClassName('nick');
var y = 0;
while( y < x.length )
{
var z = x[y];
// Edit z.style.color now as desired
++y;
}
I didn't test it tho, let me know.
And thanks Script Coder for still using my plugin :3
Thanks for the help.
@SGH When I try that it freezes chrome and stops shockwave.
Tell me if I am understanding the code correctly:
x is a variable that is an array of elements from the class type nick (the user nicknames) , y is just an iterator. Variable z is the y element in the array of x then I need to assign the new color
I tried something like this:
1 2 3 4 5 6 7 8 9
var x = document.getElementsByClassName('nick');
var y = 0;
while( y < x.length )
{
var z = x[y];
if( z.style.color == #00FF7F )
z.style.color = #0000FF;
++y;
}
but it doesn't seem to work I get an error:
Syntax Error: Unexpected Token ILLEGAL
message: "Unexpected token ILLEGAL"
"SyntaxError: Unexpected token ILLEGAL
at Object.InjectedScript._evaluateOn (<anonymous>:603:39)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:562:52)
at Object.InjectedScript.evaluate (<anonymous>:481:21)"
Since when? I have used the console before for simple things like getting all the links off a website and stuff I don't see why this would be any different can you please explain why?
@tntxtnt: He just wants to substitute colors, not to replace all of them.
You begin all tiny projects like this by the shortest time debug tests.
So, don't waste time re-packing your project each time, follow my advice and we'll get through.
There's a little I forgot to tell you:
1. Colors are stored as strings. As such, differently-formatted colors may not work (rgb vs # vs rgba...).
In my test, rgb(x, y, z) was the pattern.
2. You should use document.defaultView.getComputedStyle
var z = x[y];
var color = document.defaultView.getComputedStyle(z,0).color;
if(color == "rgb(0, 1, 2")
{
z.style.color = "rgb(1,2,3)"; // override the color using .style.color
}
++y;
And thanks for pointing out the ++y.
Chrome's tabs get stuck if that's forgotten.
Cool thanks it works SGH :) Now I just have to put a timer or something It seems like setinterval is what I want
Sweet it works thanks again SGH :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
setInterval( function() //set an interval
{
var x = document.getElementsByClassName('nick'); //create an array of all the nicknames
var y = 0; //iterator for array
while( y < x.length ) //loop through all elements of array
{
var z = x[y]; //create variable of just one element in array
var color = document.defaultView.getComputedStyle(z,0).color; //assign a standard for collor
if( z.style.color == "rgb(0, 255, 127)" ) //if it is spring green
z.style.color = "rgb(0, 0, 255)"; // override the color using .style.color to blue
++y; //increment
}
}
, 1000 ); //set timer of 1 second
I think the syntax error was I didn't realize they were strings instead of integers and I didn't know jquery was a thing you could use on the chrome console thanks for the second option :)
Ah yeah it was I just didn't have the quotes :P This works also: