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 .) 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.
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)
Offline
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 .) 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
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 .) 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.
Offline
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 .) 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.
Offline
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)
Offline
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.
Offline
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.
Offline
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.
Some things need to be more than one line.
Offline
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.
Some things need to be more than one line.
I know. I'm just saying it's possible to be done in one.
Offline
(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.
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)
Offline
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.
Offline
Here's (roughly) what jvvg is proposing:
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.
Offline
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.
[].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)
Offline
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.
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:
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\" />"); }
Offline
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.
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.
Offline
Shorter!
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"/>');}
Offline
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
Offline
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)
Offline
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...
Offline
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...
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)
Offline
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...
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.
Offline