JSFiddle - React, Tailwind, and code Playground
by Darby Rathbone
HTML
{username}{something}{username}
JavaScript
/*var re =
var text =
for (var matches = re.exec(text), i = 0, results = []; matches; matches = re.exec(text)) {
results[i] = matches;
for (var j = 0; j < matches.length; j++) {
alert(matches[1]);
Object.defineProperty(document, results[i][1], { get: function () {
return this.value;
},
set: function (e) {
this.value = e;
}
});
text = text.replace(results[i][j], "<span class='" + this[results[i][1]] + "'>" + this[results[i][1]] + "</span>");
}
i++;
}
username = 'blackkbot';
*/
var myRe = /(?:[\{])(\w*)(?:[\}])/g;
var str = document.body.innerHTML, list = [];
var myArray;
while ((myArray = myRe.exec(str)) !== null) {
list.push({myArray[1]:null});
if(!this.hasOwnProperty(myArray[1]))
Object.defineProperty(list, myArray[1], {
'get' : function(){return function () {
return this;
}.bind(this[myArray[i]]);},
'set' : function(){return function (e) {
this = e;
}.bind(this[myArray[i]]);}});
// var msg = "Found " + myArray[0] + " " + ". ";
console.log(this[myArray[1]]);
}
console.log(list);
username = 'blackkbot';