-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedly-colorful-list-view.user.js
93 lines (83 loc) · 3.62 KB
/
feedly-colorful-list-view.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ==UserScript==
// @name Feedly Colorful Listview
// @namespace http://feedly.colorful.list.view
// @description Colorizes items headers based on their source
// @include http*://feedly.com/*
// @include http*://*.feedly.com/*
// @version 0.12.2
// ==/UserScript==
const colors = {};
// since GM_addStyle was deprecated - use custom function
// that simply appends styles to head of the document
const addStyle = (styleText) => {
const style = document.createElement('style');
style.appendChild(document.createTextNode(styleText));
document.head.appendChild(style);
};
// replaces all non-letters (utf-8) to cleanup the string for coloring
// fixes https://github.com/yamalight/feedly-colorful-list-view/issues/2
const cleanTitle = (title) => {
return title?.replace?.(/[^\p{L}\s]/gu, '');
};
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;
};
addStyle(`
.entry { border-color: transparent !important; }
.entry .SelectedEntryScroller > div { border-color: transparent !important; }
.entry .ago { color: #444 !important; }
.entry .EntryMetadataSource--title-only { color: #444 !important; font-weight: bold !important; }
#timeline div.selected { border: 1px solid #444 !important; }
.theme--dark .TitleOnlyLayout--selected { background: inherit !important; }
.theme--dark .entry .SelectedEntryScroller > * { background: inherit !important; }
.theme--dark .fx .entry .TitleOnlyLayout:hover { background: inherit !important; }
.theme--dark .fx .entry .TitleOnlyLayout { border: transparent !important; }
.theme--dark .fx .entry .EntryTitle { color: rgba(0, 0, 0, 0.88)!important; }
.theme--dark .fx .entry .EntryMetadataSource--title-only { color: rgba(0, 0, 0, 0.75)!important; }
.theme--dark .fx .entry.entry--read .EntryMetadataSource--title-only { color: rgba(0, 0, 0, .54)!important; font-weight: normal!important; }
.theme--dark .fx .entry.entry--read .EntryTitle { color: rgba(0, 0, 0, .54)!important; font-weight: normal!important; }
.theme--dark .fx .entry { color: rgba(0, 0, 0, .54)!important; background: rgb(255 255 255 / 88%); }
.theme--dark .fx .entry .EntryTitle { color: #000; }
.theme--dark .fx .entry .EntryTitleLink { color: #000; }
`);
const observer = new MutationObserver(function () {
const elements = document.getElementsByClassName('entry');
Array.from(elements)
.filter((el) => !el.getAttribute('colored'))
.filter((el) => el.querySelector('a.EntryMetadataSource'))
.map((el) => {
const title = cleanTitle(
el.querySelector('a.EntryMetadataSource').textContent
);
el.setAttribute('colored', title);
return title;
})
.forEach((title) => {
if (!colors[title]) {
const color = computeColor(title);
addStyle(`
article[colored='${title}'] {
background: hsl(${color.h},${color.s}%,80%) !important; }
article[colored='${title}']:hover {
background: hsl(${color.h},${color.s}%,85%) !important; }
article[colored='${title}']//a[contains(@class, 'read')] {
background: hsl(${color.h},${color.s}%,90%) !important; }
article[colored='${title}']//a[contains(@class, 'read')]:hover {
background: hsl(${color.h},${color.s}%,95%) !important; }
`);
}
});
});
const timeline = document.getElementById('root');
observer.observe(timeline, { childList: true, subtree: true });