Last active
July 2, 2016 03:14
-
-
Save nem035/0e902ff9445b978c3d5c4c14602e42ec to your computer and use it in GitHub Desktop.
Simple script to run in the browser console at http://www.ascii.cl/htmlcodes.htm and obtain the ascii data by its type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// object that will contain the data | |
var result = { | |
dec: [], | |
hex: [], | |
symbols: [], | |
htmlNums: [], | |
htmlNames: [], | |
names: [] | |
}; | |
// function to extract values from each <td> | |
function extractDataFromTD(td) { | |
// split the values on <br> | |
var vals = td.innerHTML.split('<br>'); | |
// trim the excess whitespace unless | |
// the actual data is a whitespace | |
return vals.map(function(d) { | |
return d === ' ' ? d : d.trim(); | |
}); | |
} | |
function extractDataFromTDs(tds) { | |
// first <td> is the decimal values | |
var dec = extractDataFromTD(tds[0]); | |
// second <td> is the hex values | |
var hex = extractDataFromTD(tds[1]); | |
// third <td> is the symbols | |
var symbols = extractDataFromTD(tds[2]); | |
// fourth <td> is the HTML numbers | |
// innerHTML automatically converts special chars so | |
// we have to convert them back | |
var htmlNums = extractDataFromTD(tds[3]).map(function(num) { | |
return num.replace('amp;', ''); | |
}); | |
// fifth <td> is the HTML name | |
var htmlNames = extractDataFromTD(tds[4], false); | |
// sixth <td> is the human readable name | |
var names = extractDataFromTD(tds[5]); | |
return { | |
dec: dec, | |
hex: hex, | |
symbols: symbols, | |
htmlNums: htmlNums, | |
htmlNames: htmlNames, | |
names: names | |
}; | |
} | |
// extract arrays of arrays containing <td>s with data | |
var tdArrays = Array.prototype.map.call(document.querySelectorAll('tr.z1'), function(tr) { | |
// each data row is the second sibling down from tr.z1 | |
var dataRow = tr.nextSibling.nextSibling; | |
// filter out <td> arrays | |
return Array.prototype.slice.call(dataRow.childNodes).filter(function(elem) { | |
return elem.tagName === 'TD'; | |
}); | |
}); | |
// extract data for each array of <td>s | |
var data = tdArrays.map(extractDataFromTDs); | |
// join each type of data from all <td>s | |
var dataTypes = Object.keys(result); | |
data.forEach(function(d) { | |
dataTypes.forEach(function(type) { | |
result[type] = result[type].concat(d[type]); | |
}); | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment