Created
November 20, 2022 06:16
-
-
Save altilunium/3b994c11a9de1b7e96878204d7c34526 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<div id="nyaa"></div> | |
</body> | |
<script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script> | |
<script type='text/javascript' src='tweets.js'></script> | |
<script> | |
var words = [] | |
function blah(i){ | |
var t = i.tweet.full_text | |
var t = t.replace(/(^|[^@\w])@(\w{1,15})\b/g,'') | |
var b = t.replace(/[^\w\s]/gi, '').toUpperCase() | |
var b = b.replace('\n',' ') | |
var c = b.split(' ') | |
c.forEach(function(i){ | |
i = i.replace('\n',' ') | |
words.push(i) | |
}) | |
} | |
nya.forEach(blah) | |
console.log(words) | |
let counter = {}; | |
for (element of words.flat()) { | |
if (counter[element]) { | |
counter[element] += 1; | |
} else { | |
counter[element] = 1; | |
} | |
}; | |
console.log(counter); | |
var items = Object.keys(counter).map(function(key) { | |
return [key, counter[key]]; | |
}); | |
items.sort(function(first, second) { | |
return second[1] - first[1]; | |
}); | |
console.log(items) | |
var theStr = "<table style='table-layout:fixed;width:900px'><tr style='font-weight:800'><td style='width:15%'>Words</td><td style='width:95%;'>Number of mentions</td></tr>" | |
function puri(i) { | |
theStr = theStr + "<tr><td>"+i[0]+"</td><td>"+i[1]+"</td></tr>" | |
} | |
items.forEach(puri) | |
theStr = theStr + "</table>" | |
var t = document.getElementById("nyaa") | |
t.innerHTML = theStr | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment