Skip to content

Instantly share code, notes, and snippets.

Created February 13, 2022 11:08
What would you like to do?
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