ScratchTools icon indicating copy to clipboard operation
ScratchTools copied to clipboard

Add feature to turn unlinked links into linked ones

Open ScolderCreations opened this issue 2 years ago • 20 comments

Self explanatory. Untested though, let me know if anything goes wrong.

ScolderCreations avatar Jul 27 '22 02:07 ScolderCreations

The way you did this looks cool, however it won't work due to 3 issues:

  1. Using innerHTML might be dangerous based on the way you're using it (I don't think it is but there's a possibility).
  2. Because of this, no images will load and page JavaScript won't run.
  3. What if you press load more comments or something? Then the new elements that are created won't include tags for their turbowarp links.

rgantzos avatar Jul 27 '22 02:07 rgantzos

The way you did this looks cool, however it won't work due to 3 issues:

  1. Using innerHTML might be dangerous based on the way you're using it (I don't think it is but there's a possibility).
  2. Because of this, no images will load and page JavaScript won't run.
  3. What if you press load more comments or something? Then the new elements that are created won't include tags for their turbowarp links.

Good points. Number 1 probably won’t be a problem since the only content it can insert must be a turbowarp.org link containing numbers, and there’s no wildcard characters (which would be dangerous.) Number 2 makes a bit of sense, I’ll make it wait for everything else. Number 3: How would we fix this?

ScolderCreations avatar Jul 27 '22 02:07 ScolderCreations

I'm not completely sure about how you can linkify an element, but I'll look into it. I recommend doing something like this:

document.querySelectorAll('.content').forEach(function(el) {
   linkify(el)
})

However, like I said, I'm not sure how to linkify elements so the linkify function won't do anything. For now, I'll just look for a way to do this.

rgantzos avatar Jul 27 '22 15:07 rgantzos

I intended for this to be used with project descriptions, mainly. If it works with some comments that’s just a bonus.

ScolderCreations avatar Aug 05 '22 17:08 ScolderCreations

@ScolderCreations We now have a ScratchTools.waitForElements(selector, callback) API. That should make it so this works perfeclty.

rgantzos avatar Aug 24 '22 03:08 rgantzos

@ScolderCreations We now have a ScratchTools.waitForElements(selector, callback) API. That should make it so this works perfeclty.

Great. I’ll get to work…

ScolderCreations avatar Aug 25 '22 17:08 ScolderCreations

@rgantzosonscratch Should work now.

ScolderCreations avatar Aug 25 '22 19:08 ScolderCreations

@rgantzosonscratch Should work now.

Would you be able to make it work for all links, not just Turbowarp?

rgantzos avatar Aug 25 '22 22:08 rgantzos

@/rgantzosonscratch Should work now.

Would you be able to make it work for all links, not just Turbowarp?

Yeah, give me a moment…

ScolderCreations avatar Aug 26 '22 19:08 ScolderCreations

@rgantzosonscratch Should work now.

ScolderCreations avatar Aug 26 '22 20:08 ScolderCreations

@rgantzosonscratch Should work now.

Alright thanks, I’ll test it soon.

rgantzos avatar Aug 26 '22 21:08 rgantzos

@ScolderCreations the API waitForElements requires an ID.

rgantzos avatar Aug 29 '22 18:08 rgantzos

@ScolderCreations the API waitForElements requires an ID.

oh

ScolderCreations avatar Aug 29 '22 18:08 ScolderCreations

Alright, so you're defining "el", but you only use "e" when setting innerText. Also, innerText and innerHTML aren't the same thing, and several arguments in ScratchTools.waitForElements() have not been defined.

rgantzos avatar Aug 29 '22 20:08 rgantzos

Alright, so you're defining "el", but you only use "e" when setting innerText. Also, innerText and innerHTML aren't the same thing, and several arguments in ScratchTools.waitForElements() have not been defined.

What is the “id” argument?

ScolderCreations avatar Aug 29 '22 20:08 ScolderCreations

Alright, so you're defining "el", but you only use "e" when setting innerText. Also, innerText and innerHTML aren't the same thing, and several arguments in ScratchTools.waitForElements() have not been defined.

What is the “id” argument?

Just a string that classifies between which part of features are looking for certain elements, and each one can only be used for one query each.

rgantzos avatar Aug 29 '22 20:08 rgantzos

@rgantzosonscratch how bout now?

ScolderCreations avatar Sep 08 '22 17:09 ScolderCreations

@rgantzosonscratch how bout now?

Still doesn't work.

rgantzos avatar Sep 29 '22 21:09 rgantzos

  1. What if you press load more comments or something? Then the new elements that are created won't include tags for their turbowarp links.

Number 3: How would we fix this?

Say lm is the load more button lm.addEventListener("click", linkify())

Steb03 avatar Dec 11 '22 18:12 Steb03

5. What if you press load more comments or something? Then the new elements that are created won't include tags for their turbowarp links.

Number 3: How would we fix this?

Say lm is the load more button lm.addEventListener("click", linkify())

The waitForElements API works just fine for this.

rgantzos avatar Dec 11 '22 18:12 rgantzos