Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active January 24, 2022 11:47
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/7cf3f83a38051f25ffc51c15934c4e39 to your computer and use it in GitHub Desktop.
Save netsi1964/7cf3f83a38051f25ffc51c15934c4e39 to your computer and use it in GitHub Desktop.
Reading (bad) news can be hard...
// Reading (bad) news can be hard.
// This script you should run in the console and then hover over headlines to get a new random headline.
// Simply copy it
// Open developer toolbar (press F12)
// In the "console" paste the script, press ENTER
// Enjoy! Simply hover over a headline to get a new random text :-)
// Try reading it seeing the photo together with the new random text
// THIS VERSION is for https://www.dr.dk
//
var HEADLINE_SELECTOR = '.dre-title-text, .dre-teaser-title__text, #dr-frontpage__top-spot #text'
function random(e) {
e.target.textContent = texts[Math.floor(Math.random()*texts.length)];
}
var elements = Array.from(document.querySelectorAll(HEADLINE_SELECTOR));
var texts = elements.map(ele => ele.textContent);
texts = [...texts.sort(() => Math.random()>.5 ? -1 : 1)]
elements.forEach((ele,i) =>
{
ele.dataset.before = ele.textContent;
ele.textContent = texts[i];
ele.removeEventListener('mouseenter', random);
ele.addEventListener('mouseenter', random);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment