Last active
January 24, 2022 11:47
-
-
Save netsi1964/7cf3f83a38051f25ffc51c15934c4e39 to your computer and use it in GitHub Desktop.
Reading (bad) news can be hard...
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
// 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