Skip to content

Instantly share code, notes, and snippets.

@drphrozen
Created April 9, 2013 07:04
Show Gist options
  • Save drphrozen/5343599 to your computer and use it in GitHub Desktop.
Save drphrozen/5343599 to your computer and use it in GitHub Desktop.
if (typeof String.prototype.decodeEntities == 'undefined') {
(function () {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
String.prototype.decodeEntities = function () {
var str = this;
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
str = element.textContent;
element.textContent = '';
return str;
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment