Forums

RS-Linkify Thread is sticky

Quick find code: 261-262-33-65181208

Indecent Act

Indecent Act

Posts: 7,456 Rune Posts by user Forum Profile RuneMetrics Profile
Thanks Blasty :)

Yeah the smileys have been a problem ever since I can remember. The best I could do was make a toggle for them. I may have another crack at detecting them in links but it's tricky since the link is broken by the smiley and thus not detected as a link. I have had partial success but nothing reliable enough to use.

The youtube URL encoding I'll look at sometime, as you say on submit might be a good place to handle that. Youtube URLs have been one of my single biggest headaches tbh. I have to define rules to identify them and the length is one of those rules, encoding is going to really mess with that. I fear I wont be able to make a one size fits all solution. As I say I'll look into it sometime but I don't know how it will go.

As for the data attribute (like Jagex use) I have no problems with that. However I verify it's an image before embedding anyway (the spoiler was an oversight). As soon as I did for the spoiler it basically filters out anything that's not an image.

Not sure why the quotes in the spoiler URL are messing with it. I'll take a look at that soon. The spoiler system needs a complete rework, it was literally tacked on ages ago. When I did version 3 I didn't change it, I just threw it in as it was. It's been bothering me for a while. I think it's time to redo it from scratch.


As always your help is simply awesome. I just hope you know how much I appreciate your help :)

10-May-2014 10:40:58 - Last edited on 10-May-2014 10:53:40 by Indecent Act

Blasty
Feb Member 2017

Blasty

Posts: 9,319 Rune Posts by user Forum Profile RuneMetrics Profile
Indecent Act said :
I may have another crack at detecting them in links but it's tricky since the link is broken by the smiley and thus not detected as a link.


That definitely sounds like an interesting challenge!

I thought encoding certain characters might be a good way to get around the smiley problem since non-linkify users wouldn't see a smiley, but since the smiley doesn't change the copied text, it might seem more strange than beneficial to have encoded characters where there usually isn't. This would also mean linkify decoding encoded characters in urls to check validity.

Encoding with consideration of smiley faces would be a more universal solution, though more difficult :O

The reason the spoiler isn't working is because of an unclosed quote mark:

onclick="toggleImg(this,
'
H TTP://img1.wikia.nocookie.net/__cb20120603103000/runescape/images/7/74/Saradomin_d
'
hide_old.png
'
)"

Indecent Act said :
As always your help is simply awesome. I just hope you know how much I appreciate your help :)


Aww, you're too kind ­<3 it's always wonderful to be contribute to linkify :)

i

­­
­­<
Blasty
the Blue
>­­
­­
Blasty
// @BlastytheBlue // Blasty#5167
| Co-owner of Mine Nation

10-May-2014 12:32:44

Blasty
Feb Member 2017

Blasty

Posts: 9,319 Rune Posts by user Forum Profile RuneMetrics Profile
What do you think of this replacement for smileys breaking links? (would be one of the earlier replacements)

postText.replace(
/[^ >]*<img ([^>]* )?class=\"sm\d+\" [^>]*>[^\s<]*/g,
// -- matches smileys surrounded by non-space characters and non-tag characters

function(a){
if(true){
// -- this should test if the replacement is a link

return a.replace(
// -- replaces smiley <img>'s with alt text
(A)

/<img ([^>]* )?class=\"sm\d+\" [^>]*>/g,
// -- matches the <img>

function(b){
return /alt=\"([^"]*)\"/.exec(b)[1]
// -- matches the alt

}
)
} else {
return a;
}
}
)

The return value of
(A)
is a replacement such that:
before smileys: "video - http:[...]/watch?v= Oabc"
after smileys: "video - http:[...]/watch?v<img alt="= O">abc"
surrounding match: "http:[...]/watch?v<img alt="= O">abc"
replacement result: "http:[...]/watch?v= Oabc" --- here you can match the surrounding characters to check if it's a url, in this case we return the replacement

before smileys: "hi : )"
after smileys: "hi <img alt=": )">"
surrounding match: ": )"
replacement results: ": )" --- here the match would return negative, in thise case return the original <img>

I didn't plan it properly while writing so it doesn't make sense since the condition relies on one of its results, but if you rearrange it so that it replaces, then checks for link, then returns either replacement or original text, then it should work.

i

­­
­­<
Blasty
the Blue
>­­
­­
Blasty
// @BlastytheBlue // Blasty#5167
| Co-owner of Mine Nation

10-May-2014 15:11:23 - Last edited on 11-May-2014 03:53:33 by Blasty

Indecent Act

Indecent Act

Posts: 7,456 Rune Posts by user Forum Profile RuneMetrics Profile
@Blasty,

I haven't looked closely at your code yet, but I have looked at the logic behind it and that seems sound.

There is just one thing (forgive me if I don't make sense, tired and I'm ready for bed). I use the DOM to clean up the posts before linkifing. I create an element, put in the html and then read the innerText. This way things like buttons, embedded links, broken code in jmod posts, all the HTML gets cleaned out.

I could max out character limit just listing the issues this method solved for me. the lack of consistency with the HTML on these forums makes it really hard to make a one size fits all for regex to linkify.  I originally read the innerHTML but the headaches it caused simply wasn't worth it. The two big advantages are smaller strings to push though the regex engine, and all plain text urls are isolated from the HTML.

I will look into it further, tbh I never considered the smileys an issue. It was standard procedure for all HLF users to disable them because of links. Since then they removed that ability so when I added it RS Linkify I felt it was all good.

Anyway at a glance your code looks good, I'll see what I can do :)

10-May-2014 17:45:10 - Last edited on 10-May-2014 18:32:31 by Indecent Act

Hevilmystic
Feb Member 2022

Hevilmystic

Posts: 60,012 Emerald Posts by user Forum Profile RuneMetrics Profile
http://i.imgur.com/L0PLVeR.png

May I have this?

I'm not sure how it'll look with the sides of posts, but I am next to useless when it comes to changing anything with a picture.

Edit: Never mind, I inspected element and changed my avatar URL to it. Time to try editing it.

http://i.imgur.com/qhdaDPi.png

*shrug* I suck at recolouring and keeping the antialias look.

Box
,
box
,
box
!
Unslain Bosses - Clan

10-May-2014 21:27:06 - Last edited on 11-May-2014 00:02:08 by Hevilmystic

Blasty
Feb Member 2017

Blasty

Posts: 9,319 Rune Posts by user Forum Profile RuneMetrics Profile
Hevilmystic said :
*shrug* I suck at recolouring and keeping the antialias look.


The trick is to use a mask, then you can color it in any way easily

https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/

https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/blue.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/b_on_w.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/multi.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/w.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/w_on_b.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/lava.png
https://googledrive.com/host/0B_P4A1paVEPbYU9LbjJsRl9Zdkk/glacor.png

i

­­
­­<
Blasty
the Blue
>­­
­­
Blasty
// @BlastytheBlue // Blasty#5167
| Co-owner of Mine Nation

11-May-2014 03:28:01 - Last edited on 11-May-2014 03:46:22 by Blasty

Quick find code: 261-262-33-65181208 Back to Top