I have a script to replace content of a document:
var mytitle = document.title ;
document.title = mytitle
.replace(/old1/gi, "new1")
.replace(/old2/gi, "new2")
.replace(/old3/gi, "new3")
.replace(/old4/gi, "new4")
.replace(/old5/gi, "new5");
var mybody=document.body.innerHTML ;
document.body.innerHTML=mybody
.replace(/old1/gi, "new1")
.replace(/old2/gi, "new2")
.replace(/old3/gi, "new3")
.replace(/old4/gi, "new4")
.replace(/old5/gi, "new5");
You can see i must write replace(/old1/gi, "new1").replace(/old2/gi, "new2").replace(/old3/gi, "new3").replace(/old4/gi, "new4").replace(/old5/gi, "new5");
2 times.
How to make script works even just write above code once? like this:
var myreplace=replace(/old1/gi, "new1").replace(/old2/gi, "new2").replace(/old3/gi, "new3").replace(/old4/gi, "new4").replace(/old5/gi, "new5");
var mytitle = document.title ;
document.title = mytitle.myreplace;
var mybody=document.body.innerHTML ;
document.body.innerHTML=mybody.myreplace
Notice: old1
,new1
... are strings.