Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created March 10, 2022 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsi1964/e00ad7e53ae824ddb7bf9c8c9b3a8cf7 to your computer and use it in GitHub Desktop.
Save netsi1964/e00ad7e53ae824ddb7bf9c8c9b3a8cf7 to your computer and use it in GitHub Desktop.
Make news fun again
var tags = Array.from(document.querySelectorAll('*')).filter(ele => !/^(a|script|iframe|title|meta|head|body|style|html|link|svg|path|g|button|img|picture|ol|ul|source|nav)$/ig.exec(ele.tagName));
var temp = tags.reduce((sum, curr) => {
const tag = curr.tagName;
const len = curr.textContent.length;
if (sum[tag]) {
sum[tag].len += len;
sum[tag].count++;
} else {
sum[tag] = { len, count:1};
}
return sum
}, {})
var keys = Object.keys(temp).filter(key => {
pot = temp[key];
return pot.count > 5
});
var sels = keys.filter(key => {
var pot = temp[key]
var avg = pot.len/pot.count;
return avg > 20 && avg < 70
})
sels.forEach((sel) => {
var headlines = Array.from(document.querySelectorAll(sel));
headlines.forEach(h => h.innerText = headlines[Math.floor(Math.random()*headlines.length)].innerText)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment