Terence Eden is one of my favourite old school bloggers, he still posts regularly and is thoughtful about tech issues and today he posted on BlueSky an observation that headlines are fundamentally better when ending with “I have a solution: wolves”
This is irresistible to test out, and see if we can do that with some Javascript:
Let’s break out that image from the post so you can see it better. Thank you Telegraph, you terrible newspaper.
We can try it on the Guardian - although I probably found the Telegraph funnier:
It works quite well on the Guardian if you apply it to a single article. The repetition works:
You’re probably wondering if you can have the javascript yourself, and yes you can. To use it you need to create a bookmark and use the code as the URL. Will it work on mobile, probably not, but it works on my desktop Mac OS X, Chrome, and that’ll do me as I’m not trying to make a production level project here, just make myself laugh.
javascript:(()=>{const PH="I have a solution: wolves.",MW=6,SEL="p,h1,h2,h3,h4,h5,h6,li,dt,dd,blockquote,figcaption,caption,legend,summary,[role='heading']",SK=new Set(["SCRIPT","STYLE","NOSCRIPT","IFRAME","SVG","MATH","TEXTAREA","CANVAS","CODE","PRE","SELECT","OPTION"]),wRe=/[\p{L}\p{N}’']+/gu,inNav=e=>e.closest('nav,[role="navigation"],[role="menu"],header,footer,aside,[aria-hidden="true"]'),hasSkipAnc=e=>{for(let p=e;p;p=p.parentElement){if(p.isContentEditable||SK.has(p.tagName))return true}return false},stripEnd=s=>s.replace(/\s+$/,"").replace(/["')\]]+$/,"").replace(/\s+$/,""),already=t=>stripEnd(t).endsWith(PH),lastText=el=>{const tw=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,{acceptNode(n){if(!n.nodeValue||!n.nodeValue.trim())return NodeFilter.FILTER_REJECT;for(let p=n.parentNode;p;p=p.parentNode){if(p.nodeType===1){if(p.isContentEditable||SK.has(p.tagName))return NodeFilter.FILTER_REJECT}}return NodeFilter.FILTER_ACCEPT}});let last=null;while(tw.nextNode())last=tw.currentNode;return last};const nodes=Array.from(document.querySelectorAll(SEL)).filter(el=>!inNav(el)&&!hasSkipAnc(el)&&!el.querySelector(SEL));for(const el of nodes){const text=el.textContent||"";const wc=(text.match(wRe)||[]).length;if(wc<MW||already(text))continue;const t=lastText(el);if(!t)continue;const v=t.nodeValue,sp=(v.match(/\s+$/)||[""])[0];let body=v.slice(0,v.length-sp.length);const m=body.match(/(["')\]]+)$/);const cl=m?m[1]:"";if(cl)body=body.slice(0,-cl.length).replace(/\s+$/,"");else body=body.replace(/\s+$/,"");if(!/[.!?…]$/.test(body))body+=".";body+=" "+PH;t.nodeValue=body+cl+sp}})();
Anyway. Let’s do one more for shit lols. What would be good?
AH SOD - ONE MORE FOR LUCK - WHAT WILL IT TO TO THE DAILY MAIL?
Yeah. Wolves everywhere.