This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-03 19:16:53

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Antidote Script in One Line

I realize that Antidote is an outdated topic, but I've been thinking, and realized how repetitive it is.  It is possible to summarize all of the code into one line (with only one semicolon per line, otherwise, that's cheap  tongue .)  I only included the img tag, but you get the idea.  More tags can be added can be added by adding .replace(regex, output) before the semicolon.

Code:

document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/g, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");

Last edited by GeonoTRON2000 (2012-12-03 19:34:36)


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

Offline

 

#2 2012-12-03 19:45:35

joletole
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

I realize that Antidote is an outdated topic, but I've been thinking, and realized how repetitive it is.  It is possible to summarize all of the code into one line (with only one semicolon per line, otherwise, that's cheap  tongue .)  I only included the img tag, but you get the idea.  More tags can be added can be added by adding .replace(regex, output) before the semicolon.

Code:

document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/g, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");

If you still have antidote installed, THEN GET RID OF IT! It causes weird thing's to happen to your computer.

Offline

 

#3 2012-12-03 19:46:29

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

joletole wrote:

GeonoTRON2000 wrote:

I realize that Antidote is an outdated topic, but I've been thinking, and realized how repetitive it is.  It is possible to summarize all of the code into one line (with only one semicolon per line, otherwise, that's cheap  tongue .)  I only included the img tag, but you get the idea.  More tags can be added can be added by adding .replace(regex, output) before the semicolon.

Code:

document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/g, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");

If you still have antidote installed, THEN GET RID OF IT! It causes weird thing's to happen to your computer.

Nobody still does.  I'm just saying this one is basically a one-line version.


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

Offline

 

#4 2012-12-03 20:01:32

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

joletole wrote:

GeonoTRON2000 wrote:

I realize that Antidote is an outdated topic, but I've been thinking, and realized how repetitive it is.  It is possible to summarize all of the code into one line (with only one semicolon per line, otherwise, that's cheap  tongue .)  I only included the img tag, but you get the idea.  More tags can be added can be added by adding .replace(regex, output) before the semicolon.

Code:

document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/g, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");

If you still have antidote installed, THEN GET RID OF IT! It causes weird thing's to happen to your computer.

Nobody still does.  I'm just saying this one is basically a one-line version.

From what I see in it, it will mess up the browser, because replacing document.body.innerHTML often has undesired results.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#5 2012-12-03 20:05:28

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

jvvg wrote:

GeonoTRON2000 wrote:

joletole wrote:

If you still have antidote installed, THEN GET RID OF IT! It causes weird thing's to happen to your computer.

Nobody still does.  I'm just saying this one is basically a one-line version.

From what I see in it, it will mess up the browser, because replacing document.body.innerHTML often has undesired results.

1) That's what the original antidote script does
2) That only happens when the website uses advanced tactics, also using javascript, which most forum softwares don't do.

EDIT: also, surprisingly, I learned about the TBGs through examination of the antidote script...

Last edited by GeonoTRON2000 (2012-12-03 20:08:12)


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

Offline

 

#6 2012-12-03 20:08:12

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

jvvg wrote:

GeonoTRON2000 wrote:


Nobody still does.  I'm just saying this one is basically a one-line version.

From what I see in it, it will mess up the browser, because replacing document.body.innerHTML often has undesired results.

1) That's what the original antidote script does
2) That only happens when the website uses advanced tactics, also using javascript, which most forum softwares don't do.

1. The original antidote cause my page to glitch up a bit with some JS stuff.
2. Even so, it's safer to do do it element by element.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#7 2012-12-03 20:08:41

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

jvvg wrote:

GeonoTRON2000 wrote:

jvvg wrote:


From what I see in it, it will mess up the browser, because replacing document.body.innerHTML often has undesired results.

1) That's what the original antidote script does
2) That only happens when the website uses advanced tactics, also using javascript, which most forum softwares don't do.

1. The original antidote cause my page to glitch up a bit with some JS stuff.
2. Even so, it's safer to do do it element by element.

Try doing that in one line.  tongue


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

Offline

 

#8 2012-12-03 20:18:02

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

jvvg wrote:

GeonoTRON2000 wrote:


1) That's what the original antidote script does
2) That only happens when the website uses advanced tactics, also using javascript, which most forum softwares don't do.

1. The original antidote cause my page to glitch up a bit with some JS stuff.
2. Even so, it's safer to do do it element by element.

Try doing that in one line.  tongue

Some things need to be more than one line.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#9 2012-12-03 20:26:17

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

jvvg wrote:

GeonoTRON2000 wrote:

jvvg wrote:


1. The original antidote cause my page to glitch up a bit with some JS stuff.
2. Even so, it's safer to do do it element by element.

Try doing that in one line.  tongue

Some things need to be more than one line.

I know.  I'm just saying it's possible to be done in one.


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

Offline

 

#10 2012-12-03 20:32:39

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Antidote Script in One Line

Code:

(mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}

Why did you put {1} there? It serves no purpose.

Some things need to be more than one line.

Code:

you();!function(){can()}('put');multiple();statements();on(1);'line' in JavaScript;

There's no real limit on line length in JavaScript; when minified, the jQuery is one line.

Last edited by nXIII (2012-12-03 20:34:28)


nXIII

Offline

 

#11 2012-12-03 20:34:03

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

nXIII wrote:

Code:

(mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}

Why did you put {1} there? It serves no purpose.

Some things need to be more than one line.

Code:

you();!function(){can()}('put');multiple();statements();on(1);'line' in JavaScript;

To exist.  tongue


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

Offline

 

#12 2012-12-03 20:50:45

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Antidote Script in One Line

@nXIII:
I meant to say some things should be more than one line, not that they need to be.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#13 2012-12-03 21:09:31

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

Here's (roughly) what jvvg is proposing:

Code:

var posts = document.getElementsByClassName("postright");
for (var i = 0; i < posts.length; i++) {
  posts[i].innerHTML = posts[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");
}

You'll notice there are 4 lines.  tongue


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

Offline

 

#14 2012-12-03 21:21:21

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

Here's (roughly) what jvvg is proposing:

Code:

var posts = document.getElementsByClassName("postright");
for (var i = 0; i < posts.length; i++) {
  posts[i].innerHTML = posts[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");
}

You'll notice there are 4 lines.  tongue

Code:

[].forEach.call(document.querySelectorAll('.postright'),function(p){p.innerHTML=p.innerHTML.replace(/\[img](ht|f)tps?:\/\/\S+\[\/img]/gi, '<img style=max-width:510px src="$1" alt="$1">');});

One line.

Last edited by nXIII (2012-12-03 21:21:53)


nXIII

Offline

 

#15 2012-12-07 21:29:23

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

nXIII wrote:

GeonoTRON2000 wrote:

Here's (roughly) what jvvg is proposing:

Code:

var posts = document.getElementsByClassName("postright");
for (var i = 0; i < posts.length; i++) {
  posts[i].innerHTML = posts[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");
}

You'll notice there are 4 lines.  tongue

Code:

[].forEach.call(document.querySelectorAll('.postright'),function(p){p.innerHTML=p.innerHTML.replace(/\[url](ht|f)tps?:\/\/\S+\[\/img]/gi, '<img style=max-width:510px src="$1" alt="$1">');});

One line.

or just:

Code:

for (var i = 0; i < document.getElementsByClassName("postright").length; i++) { document.getElementsByClassName("postright")[i].innerHTML = document.getElementsByClassName("postright")[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />"); }

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

Offline

 

#16 2012-12-07 21:49:52

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

nXIII wrote:

GeonoTRON2000 wrote:

Here's (roughly) what jvvg is proposing:

Code:

var posts = document.getElementsByClassName("postright");
for (var i = 0; i < posts.length; i++) {
  posts[i].innerHTML = posts[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />");
}

You'll notice there are 4 lines.  tongue

Code:

[].forEach.call(document.querySelectorAll('.postright'),function(p){p.innerHTML=p.innerHTML.replace(/\[url](ht|f)tps?:\/\/\S+\[\/img]/gi, '<img style=max-width:510px src="$1" alt="$1">');});

One line.

or just:

Code:

for (var i = 0; i < document.getElementsByClassName("postright").length; i++) { document.getElementsByClassName("postright")[i].innerHTML = document.getElementsByClassName("postright")[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />"); }

That's longer.


nXIII

Offline

 

#17 2012-12-07 23:22:16

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Antidote Script in One Line

Shorter!

Code:

for(var i=0,e=document.querySelectorAll('.postright');i<e.length;i++){e[i].innerHTML=e[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi,'<img style="max-width:510px;"src="$1"alt="$1"/>');}

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#18 2012-12-07 23:33:44

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

nXIII wrote:

GeonoTRON2000 wrote:

nXIII wrote:


Code:

[].forEach.call(document.querySelectorAll('.postright'),function(p){p.innerHTML=p.innerHTML.replace(/\[url](ht|f)tps?:\/\/\S+\[\/img]/gi, '<img style=max-width:510px src="$1" alt="$1">');});

One line.

or just:

Code:

for (var i = 0; i < document.getElementsByClassName("postright").length; i++) { document.getElementsByClassName("postright")[i].innerHTML = document.getElementsByClassName("postright")[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />"); }

That's longer.

But easier to understand.

@MathWizz: cool


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

Offline

 

#19 2012-12-07 23:46:17

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

nXIII wrote:

GeonoTRON2000 wrote:

or just:

Code:

for (var i = 0; i < document.getElementsByClassName("postright").length; i++) { document.getElementsByClassName("postright")[i].innerHTML = document.getElementsByClassName("postright")[i].innerHTML.replace(/\[img\]((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)\[\/img\]/gi, "<img style=\"max-width: 510px;\" src=\"$1\" alt=\"$1\" />"); }

That's longer.

But easier to understand.

Mine is much less repetitive and uses a shorter iterator. That's doesn't make it harder to understand.

EDIT: Also, yours fetches the list of elements three times in every loop iteration. Mine fetches them once.

Last edited by nXIII (2012-12-07 23:47:04)


nXIII

Offline

 

#20 2012-12-08 00:53:50

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

nXIII wrote:

GeonoTRON2000 wrote:

nXIII wrote:


That's longer.

But easier to understand.

Mine is much less repetitive and uses a shorter iterator. That's doesn't make it harder to understand.

EDIT: Also, yours fetches the list of elements three times in every loop iteration. Mine fetches them once.

Oh, no, you lost 2 bytes of RAM...  tongue


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

Offline

 

#21 2012-12-08 01:10:43

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Antidote Script in One Line

GeonoTRON2000 wrote:

nXIII wrote:

GeonoTRON2000 wrote:

But easier to understand.

Mine is much less repetitive and uses a shorter iterator. That's doesn't make it harder to understand.

EDIT: Also, yours fetches the list of elements three times in every loop iteration. Mine fetches them once.

Oh, no, you lost 2 bytes of RAM...  tongue

No, it makes the loop slower, is very bad practice, and makes the script longer. You have no excuse.

Last edited by MathWizz (2012-12-08 01:11:35)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#22 2012-12-08 15:43:47

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: Antidote Script in One Line

MathWizz wrote:

GeonoTRON2000 wrote:

nXIII wrote:


Mine is much less repetitive and uses a shorter iterator. That's doesn't make it harder to understand.

EDIT: Also, yours fetches the list of elements three times in every loop iteration. Mine fetches them once.

Oh, no, you lost 2 bytes of RAM...  tongue

No, it makes the loop slower, is very bad practice, and makes the script longer. You have no excuse.

I don't need an excuse.  I didn't forget my homework.


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

Offline

 

Board footer