Skip to content

Instantly share code, notes, and snippets.

@thierryk
Created May 27, 2016 23:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thierryk/58f8cccfb90360a84fa8f38f75615960 to your computer and use it in GitHub Desktop.
Save thierryk/58f8cccfb90360a84fa8f38f75615960 to your computer and use it in GitHub Desktop.
Bookmarklet to count number of characters per class attribute
javascript:%28function%28%29%7Bvar p%3Dprompt%28%27Enter a wrapper ID %28leave blank to check the entire page%29%3A%27%29%2Cwrapper%3Dp%3Fdocument.getElementById%28p%29%3Adocument.body%2CallTags%3Dwrapper.getElementsByTagName%28%27*%27%29%2CclassNames%3D%7B%7D%2CcharacterLength%3D0%2Ctag%2Cclasses%2CnodeWithClasses%3D0%2Cidentifier%2CuniqueClasses%3D%5B%5D%2Ci%2Cz%2Cbox%2CspaceSeparator %3D new RegExp%28/%5E%5Cs%24/%29%2Ccount%3D1%3Bfor%28i%3D0%3Bi<allTags.length%3Bi++%29if%28tag%3DallTags%5Bi%5D%2Ctag.className%29for%28nodeWithClasses+%3D1%2Cclasses=%28tag%20instanceof%20SVGElement%29%3F--nodeWithClasses:tag.className.split%28%27%27%29%2Cz%3D0%3Bz%3Cclasses.length%3Bz++%29identifier%3Dclasses%5Bz%5D%2Cidentifier.charAt%280%29%3D%3D%3Didentifier.charAt%280%29.toUpperCase%28%29%26%26%28uniqueClasses.indexOf%28identifier%29%3E-1%7C%7C%28uniqueClasses.push%28identifier%29%2C++count%29%29%2CcharacterLength+%3Didentifier.length%2C%28spaceSeparator.test%28identifier.charAt%280%29%29%29%3F--characterLength%3A%27%27%3BuniqueClasses.sort%28%29%2Calert%28%27I found %27+%28characterLength%29+%27 characters for %27+nodeWithClasses+%27 @class %5CnThat%5C%27s an average of %27+characterLength/nodeWithClasses+%27 characters per class attribute%27%29%3B%7D%29%28%29%3B%0A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment