Skip to content

Instantly share code, notes, and snippets.

@titomus
Created February 13, 2022 11:08
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 titomus/6344bbfe277ad60a703cbf0bccecc9b3 to your computer and use it in GitHub Desktop.
Save titomus/6344bbfe277ad60a703cbf0bccecc9b3 to your computer and use it in GitHub Desktop.
Content Spinning JS
function spin(txt){
var matches = txt.match(/{([^{}]*)}/g);
if (!matches) return txt;
for (i in matches) {
spin = matches[i]+'';
ori_spin = spin;
spin = spin.replace("{", "").replace("}", "");
spin_strs = spin.split('|');
txt = txt.replace(ori_spin,spin_strs[Math.floor(Math.random() * spin_strs.length)]);
}
return spin(txt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment