Last active
January 1, 2018 16:24
-
-
Save yamalight/dc18e5a79dd4169357dc15ed86f7b6f1 to your computer and use it in GitHub Desktop.
Flowreader Colorful Listview
This file contains hidden or 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
// ==UserScript== | |
// @name Flowreader Colorful Listview | |
// @namespace http://flowreader.colorful.list.view | |
// @description Colorizes items headers based on their source | |
// @include http*://flowreader.com/* | |
// @version 0.2.0 | |
// @grant GM_addStyle | |
// ==/UserScript== | |
const colors = {}; | |
const computeColor = (title) => { | |
let h = 0; | |
for (let i = 0; i < title.length; i++) { | |
let s = i !== 0 ? title.length % i : 1; | |
let r = s !== 0 ? title.charCodeAt(i) % s : title.charCodeAt(i); | |
h += r; | |
} | |
let hs = { | |
h: (h % 36 + 1) * 10, | |
s: 30 + (h % 5 + 1) * 10, | |
}; | |
colors[title] = hs; | |
return hs; | |
}; | |
GM_addStyle(` | |
.item .timeago { color: #444 !important; } | |
.item .heading .author a { color: #444 !important; font-weight: bold !important; } | |
`); | |
const timeline = document.getElementById("contentHolder"); | |
timeline.addEventListener("DOMNodeInserted", function () { | |
const elements = document.getElementsByClassName('item'); | |
Array | |
.from(elements) | |
.filter(el => !el.getAttribute('colored')) | |
.filter(el => el.querySelector('div.author')) | |
.map(el => { | |
const title = el.querySelector('div.author').textContent; | |
el.setAttribute('colored', title); | |
return title; | |
}) | |
.forEach((title) => { | |
if (!colors[title]) { | |
const color = computeColor(title); | |
GM_addStyle(` | |
div[colored='${title}'] { | |
background: hsl(${color.h},${color.s}%,80%) !important; } | |
div[colored='${title}']:hover { | |
background: hsl(${color.h},${color.s}%,85%) !important; } | |
div[colored='${title}']//a[contains(@class, 'read')] { | |
background: hsl(${color.h},${color.s}%,90%) !important; } | |
div[colored='${title}']//a[contains(@class, 'read')]:hover { | |
background: hsl(${color.h},${color.s}%,95%) !important; } | |
`); | |
} | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment