Skip to content

Instantly share code, notes, and snippets.

@GeonoTRON2000
Created July 29, 2017 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeonoTRON2000/5e2e0938bd4815704c1eb29053e2ff5b to your computer and use it in GitHub Desktop.
Save GeonoTRON2000/5e2e0938bd4815704c1eb29053e2ff5b to your computer and use it in GitHub Desktop.
Parse a BBCode [font=] tag
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