feat: iltapulu catalog sports events highlighter

This commit is contained in:
ae 2024-09-06 15:13:10 +03:00
parent eb4b4dfe9c
commit a33a617e7b
Signed by: ae
GPG Key ID: 995EFD5C1B532B3E

View File

@ -0,0 +1,54 @@
// ==UserScript==
// @name ip-highlight
// @description TV catalog item highlighter
// @author ae
// @namespace Violentmonkey Scripts
// @match *://www.iltapulu.fi/
// @version 1.0
// ==/UserScript==
const channelTags = [
"#channel-1", // YLE 1
"#channel-2", // YLE 2
"#channel-3", // MTV3
"#channel-4", // 4
"#channel-6", // MTV Sub
"#channel-5", // TV5
"#channel-62" // 6
]
const highlightCodes = {
sport: "#1c9346"
}
const findSportsItems = () => {
let rawItems = []
channelTags.forEach((tag) => {
const query = `${tag} .op`
const channelItems = document.querySelectorAll(query)
rawItems.push(...channelItems)
})
let sportsItems = []
rawItems.forEach((item) => {
const afterStyle = window.getComputedStyle(item, "::after")
if (afterStyle.content !== "none" && afterStyle.content !== '""') {
sportsItems.push(item)
}
})
return sportsItems
}
window.addEventListener("load", () => {
const sportsItems = findSportsItems()
sportsItems.forEach((item) => {
item.parentElement.style.backgroundColor = highlightCodes["sport"]
})
console.log("ip-highlight.js: All sports events highlighted successfully!")
})