Created
February 13, 2022 11:08
-
-
Save titomus/6344bbfe277ad60a703cbf0bccecc9b3 to your computer and use it in GitHub Desktop.
Content Spinning JS
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
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