Text Coloring

Report bugs and suggest new features for the web client here.

Moderator: Eowul

Forum rules
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
Gub
Adventurer
Posts: 93
Joined: 04 Mar 2010 08:07

Re: Text Coloring

Post by Gub » 22 Aug 2013 00:32

For your trigger check the regular expression box, and put in (peculiar|exotic|unusual) in the box (that triggers on peculiar OR exotic OR unusual)

Code: Select all

var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
$("#mudoutput .line").last().html(src_str);
There's a simpler version. The other had a lot additional checks that I don't think will be needed.

Basically all those funny symbols are regular expressions, often referred to as "regex". Regex is super handy and great to use, but it has a little bit of a learning curve. You can try some of it out here http://regexone.com/

Gub
Adventurer
Posts: 93
Joined: 04 Mar 2010 08:07

Re: Text Coloring

Post by Gub » 22 Aug 2013 00:55

Code: Select all

var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
$("#mudoutput .line").last().html(src_str);
This gives you a little more control over the color. Note in this code the color is green, but could be changed to anything.

Laurel

Re: Text Coloring

Post by Laurel » 22 Aug 2013 02:32

Now ya talkin'!
I'm with Rincon on this one.

User avatar
Eowul
Wizard
Posts: 106
Joined: 03 Mar 2010 21:55
Location: Middle Earth

Re: Text Coloring

Post by Eowul » 22 Aug 2013 08:08

Nice one Gub. I am just thinking, we could send the last line (as jquery object) as one of the variables available within the trigger (like the args var that contains the original matching regexp), and then your trigger would not be using any internal API's at all.
Caretaker of Arda

Gub
Adventurer
Posts: 93
Joined: 04 Mar 2010 08:07

Re: Text Coloring

Post by Gub » 22 Aug 2013 08:36

I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:

Code: Select all

var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");
I think any wrapper around the jquery calls I made would be good.

User avatar
Eowul
Wizard
Posts: 106
Joined: 03 Mar 2010 21:55
Location: Middle Earth

Re: Text Coloring

Post by Eowul » 22 Aug 2013 11:41

Gub wrote:I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:

Code: Select all

var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");
I think any wrapper around the jquery calls I made would be good.
You abstracted the calls even more then I had initially thought, but this sounds good .. Only question would be, would it be safe to do the replace on a .html() of the last line, if another trigger added different HTML before, it could mess things up, perhaps use .text() instead? Or would this be a 'user error' kind of thing?
Caretaker of Arda

Gub
Adventurer
Posts: 93
Joined: 04 Mar 2010 08:07

Re: Text Coloring

Post by Gub » 22 Aug 2013 22:42

I think you may be right, it is too abstracted. Maybe something closer to this?

Code: Select all

var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);
I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?

User avatar
Eowul
Wizard
Posts: 106
Joined: 03 Mar 2010 21:55
Location: Middle Earth

Re: Text Coloring

Post by Eowul » 23 Aug 2013 07:37

Gub wrote:I think you may be right, it is too abstracted. Maybe something closer to this?

Code: Select all

var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);
I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?
I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.
Caretaker of Arda

User avatar
Eowul
Wizard
Posts: 106
Joined: 03 Mar 2010 21:55
Location: Middle Earth

Re: Text Coloring

Post by Eowul » 25 Aug 2013 12:54

eowul wrote:I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.
Added gwc.output.replace with searchValue, newValue and an optional [use html] argument. The last argument determines if text() or htm() is used as the input value. Output is always added using html()
Caretaker of Arda

Yanus
Adventurer
Posts: 95
Joined: 08 Mar 2010 15:58

Re: Text Coloring

Post by Yanus » 19 Oct 2013 14:46

.
Last edited by Yanus on 30 May 2014 22:44, edited 1 time in total.

Post Reply
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/