function unslash(text) {
let options = text.match(/\|([^\|]+)\|/);
//console.log(options);
let choices = options[1].split('/');
let chosen = choices[choices.length * Math.random() | 0];
text = text.replace(options[0], chosen);
return text;
}
function unstar(text) {
let options = text.match(/\s+([^\s\*]+\*)\s+/);
let targetStar = options[1];
let targetUnstar = targetStar.replace('*', '');
// now find the options for replacement
let starOptionsIter = text.matchAll(/^(\*[^\*\s]+)$/gm);
// only keep the 1st match group of each
let starOptions = Array.from(starOptionsIter).map(x => x[0]);
let starOptionsUnstar = starOptions.map(x => x.replace('*', ''));
// add our targetUnstar =
starOptionsUnstar.push(targetUnstar);
//console.log(starOptionsUnstar);
let starChosen = starOptionsUnstar[starOptionsUnstar.length * Math.random() | 0];
// now replace the targetStar with the chosen
//console.log(starChosen);
text = text.replace(targetStar, starChosen);
// clean up the option list so we don't reveal our sources
starOptionsIter = text.matchAll(/^(\*[^\*\s]+)$/gm);
for (let opt of starOptionsIter) {
text = text.replace(opt[0], '').trim();
}
return text;
}
function remarkCloze() {
let clozeEl = document.querySelector('#front-sentence');
let sentenceText = clozeEl.textContent;
sentenceText = unslash(sentenceText);
//console.log(sentenceText);
sentenceText = unstar(sentenceText);
console.log(sentenceText);
}
if (document.readyState !== 'loading') {
remarkCloze();
} else {
document.addEventListener('DOMContentLoaded', remarkCloze);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.