Created
July 29, 2017 07:14
-
-
Save GeonoTRON2000/5e2e0938bd4815704c1eb29053e2ff5b to your computer and use it in GitHub Desktop.
Parse a BBCode [font=] tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var apply = document.getElementsByClassName("postmsg"); | |
var sigs = document.getElementsByClassName("postsignature"); | |
var i; | |
for (i = 0; i < sigs.length; i++) { | |
apply[apply.length] = sigs[i]; | |
} | |
var fonts = []; | |
var texts = []; | |
for (i = 0; i < apply.length; i++) { | |
var applyTo = apply[i]; | |
var thishtml = applyTo.innerHTML; | |
var j; | |
for (j = 0; j < thishtml.split("[font=").length-1; j++) { | |
var stuff = thishtml.split("[font=")[j+1].split("]"); | |
fonts[j] = stuff[0]; | |
texts[j] = stuff[1].split("[")[0]; | |
} | |
for (j = 0; j < fonts.length; j++) { | |
fonts[j] = fonts[j].replace(/'|"/g, ""); | |
texts[j] = texts[j].replace(/'|"/g, ""); | |
thishtml = thishtml.replace(/\[font=(.+?)\](.+?)\[\/font\]/, "<span style=\"font-family: '"+fonts[j]+"'\">"+texts[j]+"</span>"); | |
} | |
applyTo.innerHTML = thishtml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment