function CSSEscape(s) { // informed by https://github.com/mathiasbynens/mothereff.in/blob/master/css-escapes/eff.js var result = ''; for (var i = 0; i < s.length; i += 1) if (/[\t\r\n\v\f]/.test(s[i])) result += '\\' + s.charCodeAt(i).toString(16) + ' '; else if (/[ !"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~]/.test(s[i])) result += '\\' + s[i]; else result += s[i]; if (/^\d/.test(result)) result += '\\' + s.charCodeAt(0).toString(16) + ' ' + result.slice(1); return result; }