Skip to content

Instantly share code, notes, and snippets.

@mlnrDev
Last active August 14, 2023 20:41
Show Gist options
  • Save mlnrDev/ce661058c86dc7b050f739c602828d42 to your computer and use it in GitHub Desktop.
Save mlnrDev/ce661058c86dc7b050f739c602828d42 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name SBB colored categories (configurable)
// @namespace cane-sbb-colors
// @version 1.0.8
// @description Configurable colors for categories on sb.ltn.fi
// @author Nanobyte & cane
// @match https://sb.ltn.fi/*
// @icon https://sb.ltn.fi/static/browser/logo.png
// @updateURL https://gist.github.com/mlnrDev/ce661058c86dc7b050f739c602828d42/raw/cane-sbb-colors.user.js
// @downloadURL https://gist.github.com/mlnrDev/ce661058c86dc7b050f739c602828d42/raw/cane-sbb-colors.user.js
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
const categories = {
'sponsor': '#00d400',
'intro': '#00ffff',
'outro': '#0202ed',
'interaction': '#cc00ff',
'selfpromo': '#ffff00',
'music_offtopic': '#ff9900',
'preview': '#008fd6',
'poi_highlight': '#ff1684',
'filler': '#7300ff',
'exclusive_access': '#008a5c',
'chapter': '#ffd679',
};
(function () {
'use strict';
let style = '.mruy_sbcc{padding:1px 4px;display:inline-block;width:100%;border-radius:4px;}';
Object.keys(categories).forEach(category => {
if (!GM_getValue(category)) {
GM_setValue(category, categories[category]);
}
style += `.mruy_sbcc_${category}{background-color:${GM_getValue(category)};color:#000;}`;
});
GM_addStyle(style);
[...document.querySelectorAll('table')].forEach(table => {
const headers = [...table.querySelectorAll('thead th')].map(item => item.textContent.trim());
if (headers.includes('Start') && headers.includes('End')) {
const columnIndex = headers.indexOf('Category');
const rows = [...table.querySelectorAll('tbody tr')];
rows.forEach(row => {
const categoryElement = row.children[columnIndex];
const category = categoryElement.textContent.trim();
if (!categories[category]) {
return
}
categoryElement.innerHTML = `<span class="mruy_sbcc mruy_sbcc_${category}">${categoryElement.innerHTML}</span>`;
});
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment