// @ts-check
// ==UserScript==
// @name Filtrer sport
// @namespace http://tampermonkey.net/
// @version 2024.10.22
// @description Filtrer sport på dr.dk/nyheder fra.
// @author dotnetCarpenter
// @match https://www.dr.dk/nyheder
// @icon https://www.google.com/s2/favicons?sz=64&domain=dr.dk
// @grant none
// @supportURL https://gist.github.com/dotnetCarpenter/855c165ff4a7d69d5458b2ce477da59d
// ==/UserScript==
(function() {
"use strict"
/********************** DEBUG FUNCTIONS **********************/
// trace :: a -> b -> b
const trace = s => a => (console.debug (s, a), a)
// dbgln :: String | Symbol -> Object -> a
const dbgln = accessor => a => (console.debug (a?.[accessor]), a)
/********************** FUNCTORS **********************/
// Just :: a -> Functor
const Just = x => ({ fmap: f => Maybe (f (x)) })
// Nothing :: Functor
const Nothing = { fmap: () => Nothing }
// Maybe :: a -> Just | Nothing
const Maybe = x => x == null
? Nothing
: Just (x)
/********************** UTILITY FUNCTIONS **********************/
// fmap :: (a -> b) -> Functor -> Functor
const fmap = f => Functor => Functor.fmap (f)
// maybe :: (a -> Functor) -> c -> a -> b | c
const maybe = f => c => a => {
let b
const fmapAndUnwrap = pipe (f, fmap (x => b = x))
fmapAndUnwrap (a)
return b ?? c
}
// pipe :: Array<(a -> b)> -> a -> b
const pipe = (...fs) => x => fs.reduce ((x, f) => f (x), x)
// map :: (a -> b) -> Array -> Array
const map = f => array => array.map (f)
// filter :: (a -> Boolean) -> Array -> Array
const filter = f => array => array.filter (f)
/********************** PROGRAM **********************/
// compareTextContent :: Array -> HtmlElement -> Boolean
const compareTextContent = textContentList => element => textContentList.includes (element.textContent)
// findParent :: String -> HtmlElement -> Null | HtmlElement
const findParent = tagName => element => {
if (! (element || element.parentElement)) return null
return element.parentElement.tagName.toLowerCase () === tagName
? element.parentElement
: findParent (tagName)
(element.parentElement)
}
// querySelector :: String -> HtmlElement -> HtmlElement
const querySelector = s => d => d.querySelector (s)
// querySelectorAll :: String -> HtmlElement -> NodeList
const querySelectorAll = s => d => d.querySelectorAll (s)
// cardTopicSelector :: String
const cardTopicSelector = ".hydra-latest-news-page__short-news-item .dre-teaser-meta-label.dre-teaser-meta-label--primary"
// headlineSelector :: String
const headlineSelector = ".hydra-latest-news-page-short-news-article__heading, .hydra-latest-news-page-short-news-card__title"
// sportTopics :: Array
const sportTopics = [
"Atletik",
"Badminton",
"Champions League",
"Cykling",
"Engelsk fodbold",
"Fodbold",
"Golf",
"Håndbold",
"Herrelandsholdet",
"Kort sport",
"Kvindelandsholdet",
"Sport",
"Superliga",
"Tennis",
]
// xfade :: Array