ScratchTools
ScratchTools copied to clipboard
Add feature to turn unlinked links into linked ones
Self explanatory. Untested though, let me know if anything goes wrong.
The way you did this looks cool, however it won't work due to 3 issues:
- Using innerHTML might be dangerous based on the way you're using it (I don't think it is but there's a possibility).
- Because of this, no images will load and page JavaScript won't run.
- What if you press load more comments or something? Then the new elements that are created won't include tags for their turbowarp links.
The way you did this looks cool, however it won't work due to 3 issues:
- Using innerHTML might be dangerous based on the way you're using it (I don't think it is but there's a possibility).
- Because of this, no images will load and page JavaScript won't run.
- 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?
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.
I intended for this to be used with project descriptions, mainly. If it works with some comments that’s just a bonus.
@ScolderCreations We now have a ScratchTools.waitForElements(selector, callback)
API. That should make it so this works perfeclty.
@ScolderCreations We now have a
ScratchTools.waitForElements(selector, callback)
API. That should make it so this works perfeclty.
Great. I’ll get to work…
@rgantzosonscratch Should work now.
@rgantzosonscratch Should work now.
Would you be able to make it work for all links, not just Turbowarp?
@/rgantzosonscratch Should work now.
Would you be able to make it work for all links, not just Turbowarp?
Yeah, give me a moment…
@rgantzosonscratch Should work now.
@rgantzosonscratch Should work now.
Alright thanks, I’ll test it soon.
@ScolderCreations the API waitForElements requires an ID.
@ScolderCreations the API waitForElements requires an ID.
oh
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.
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?
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.
@rgantzosonscratch how bout now?
@rgantzosonscratch how bout now?
Still doesn't work.
- 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())
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 buttonlm.addEventListener("click", linkify())
The waitForElements API works just fine for this.