-
Notifications
You must be signed in to change notification settings - Fork 0
/
Farbmarkierungen auf µC.net.user.js
262 lines (223 loc) · 9.34 KB
/
Farbmarkierungen auf µC.net.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// ==UserScript==
// @name Farbmarkierungen auf µC.net
// @author Krapao (2012)
// @author vlad_tepesch (2019)
// @namespace http://www.mikrocontroller.net
// @description add some color coding to posts from self, thread opener and old posts on uC.net
// @include http://www.mikrocontroller.net/*
// @include https://www.mikrocontroller.net/*
// @include http://embdev.net/*
// @include https://embdev.net/*
// @version 10
// ==/UserScript==
//
// changelog:
// v4: by Krapo
// tidied up release
// v5: by vlad_tepesch
// added some includes to also work on https and english version of site
// v6: by vlad_tepesch
// changed coloring by age to use different shades for older or younger posts
// changed age coloring to color post info field instead of complete background
// inserted variable for different colors into param section
// changed some colors
// v7: by vlad_tepesch
// optimizations
// using topic ID to detect thread opener -> solves issue with wrong coloring on multi-page-threads
// individual colors for USERNAME_HIGHLIGHT
// v8: by vlad_tepesch
// fix the width of the colored headers after µC.net style update around 2019-11-18
// v9: by vlad_tepesch
// added snippet to show own user id
// v10: by vlad_tepesch
// added stickySidebars option (removes gradient from title bar)
// added insertToTop option that creates a link to go back to top into the right sidebar
//
// --------------------------------------------
// --------- Individuelle Anpassungen ---------
// --------------------------------------------
// own user name or id
// if ID is known (determine it from a own posts attribute (<div class="post..." data-user-id="18486"))
// this saves the effort of doing string comparisons
var USERNAME_EIGENER = 'Vlad T.';
var USERID_EIGENER = 18486; //< set to 0 if unknown
var USERNAME_ZITAT = /vlad/gi;
// Matches for Vips are done with regular expressions
// but also user ids can be entered directly.
// this saves the effort of doing string comparisons
// d.h. an Quotes mit \ denken z.B. bei . und ()
// \s+ = mindestens ein Whitespace (Leerzeichen, Newline)
var USERNAME_HIGHLIGHT = [
new VIP( 1, '#FF0000'), // andreas Schwarz
new VIP( /\)\s+\(Moderator\)/, '#FF7700')
];
// normal subject color: #FA0
var ownColor = '#0000FF'; // blau
var threadOpenerColor = '#00A000'; // mittelhelles grün
var specialUserColor = '#FF0000'; //
var stickySidebars = true;
var insertToTop = true;
var Months = (30 * 24 * 60 * 60 * 1000); // ca. 1 Monat
var ZOMBIE_DATUM = 0.2 * Months; // ab diesem Alter beginnt das Einfärben nach Alter
var ZOMBIE_VERY_OLD_DATUM = 18 * Months; // Beiträgen älter als dies bekommen die dunkelste Färbung
var zombieIntensityYoung = 0xf0; // standard post: f0 // Startfarbton für Einfärbung nach Alter
var zombieIntensityOld = 0x80; // dunkelster Farbton, der benutzt wird.
// ---------------------------------
// --------- Funktionsteil ---------
// ---------------------------------
if(/\/user\/edit$/.test(window.location)){
var userid = document.querySelector("#new_user_id").value;
if(userid){
var table = document.querySelector("#form_new_user_email").closest('table');
if(table){
var row = table.insertRow(2);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "<strong>User ID</strong>";
cell2.innerHTML = userid;
}
}
}
if(insertToTop){
var srbar = document.getElementById('sidebar-right');
if(srbar){
var el = srbar.querySelector('div ul');
var n = document.createElement('li');
n.innerHTML = '<a href="#" style="float: right;">nach oben</a>';
el.insertBefore(n, el.firstChild);
}
}
if(stickySidebars)
{
makeSidebarSticky('sidebar-right');
makeSidebarSticky('sidebar-left');
document.getElementById('top').style.background = '#fa0';
var mainCont = document.getElementById('main');
mainCont.closest('table').style.borderCollapse = 'unset';
mainCont.style.borderTopWidth = '5px';
mainCont.style.borderTopColor = '#fa0';
mainCont.style.borderTopStyle = 'solid';
}
if(! /\/topic\//.test(window.location)){
return;
}
var today = new Date();
var subjects = document.evaluate("//div[@class='subject']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var authornames = document.evaluate("//span[@class='name']", subjects.snapshotItem(0).parentNode, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var openerId = document.evaluate("//div[@class='topic ']/@data-user-id", document.body, null, XPathResult.STRING_TYPE, null).stringValue;
var dstart = new Date();
addGlobalStyle(' div.info { margin: 0px 0px 0px 0px; padding:5px 5px 5px 5px;}');
//addGlobalStyle(' div.author {visibility:collapse;} div.author * {visibility:visible;} ');
//alert( " " + openerId);
// color thread opener
if(openerId!=""){
addGlobalStyle(".post-userid-"+openerId+" .subject { background: linear-gradient(to left, #FFA500, "+threadOpenerColor+");}");
}else{
var guestOpenerName = document.evaluate("@data-guest-name", subjects.snapshotItem(0).parentNode, null, XPathResult.STRING_TYPE, null).stringValue;
if(guestOpenerName != ""){ // happens on multipage with guest opener
addGlobalStyle('.post[data-guest-name="'+guestOpenerName+'"] .subject { background: linear-gradient(to left, #FFA500, '+threadOpenerColor+');}');
}
}
// set style rules for all vips that are defined by id instead of expression
for (var j = 0; j < USERNAME_HIGHLIGHT.length; j++) {
if( isNumber(USERNAME_HIGHLIGHT[j].expr)){ // test for id
addGlobalStyle(".post-userid-"+USERNAME_HIGHLIGHT[j].expr+" .subject { background: linear-gradient(to left, #FFA500, "+USERNAME_HIGHLIGHT[j].col+");}");
USERNAME_HIGHLIGHT.splice(j, 1);
--j;
}
}
// set css rule if own id is known
if(USERID_EIGENER!=0){
addGlobalStyle(".post-userid-"+USERID_EIGENER+" .subject { background: linear-gradient(to right, #FFA500, "+ownColor+')');
}
var d1 = new Date();
var d2 = new Date();
var d3 = new Date();
var d4 = new Date();
for (var i = subjects.snapshotLength - 1; i >= 0; i--) {
var subject = subjects.snapshotItem(i);
var beitrag = subject.parentNode;
var shortauthorname = authornames.snapshotItem(i).textContent;
//Beiträge einiger User hervorheben
for (var j = 0; j < USERNAME_HIGHLIGHT.length; j++) {
if ( USERNAME_HIGHLIGHT[j].expr.test(shortauthorname) ) {
subject.style.background = 'linear-gradient(to left, #FFA500, '+USERNAME_HIGHLIGHT[j].col +')';
break;
}
}
// Beiträge markieren, in denen auf USERNAME_ZITAT Bezug genommen wird
var texts = document.evaluate("//div[@class='text gainlayout']", beitrag, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if ( USERNAME_ZITAT.test(texts.snapshotItem(i).textContent) ) {
subject.style.background = 'linear-gradient(to left, #FFA500, '+ownColor+')'; // orange => magenta
}
// Beiträge älter als ... kennzeichnen
var past = new Date();
var dateAttrib = beitrag.getAttribute('data-updated-at');
if (dateAttrib) {
past.setTime(dateAttrib);
var age = today-past;
if ( age > ZOMBIE_VERY_OLD_DATUM ){
age = ZOMBIE_VERY_OLD_DATUM;
}
if ( age > ZOMBIE_DATUM ) {
var scaledAge = (age - ZOMBIE_DATUM)/(ZOMBIE_VERY_OLD_DATUM-ZOMBIE_DATUM);
var val = scaledAge
* (zombieIntensityOld-zombieIntensityYoung)
+ zombieIntensityYoung;
val = Math.round(val);
var info = beitrag.getElementsByClassName("info")[0];
info.style.backgroundColor = "rgb("+val+","+val+","+val+")";
}
}
// Eigene Beiträge besonders markieren
if( USERID_EIGENER != 0){
if ( shortauthorname.indexOf(USERNAME_EIGENER) > 0 ) {
subject.style.background = 'linear-gradient(to right, #FFA500, '+ownColor+')';
}
}
}
var d5 = new Date();
//alert("collect:" + (dstart - today)+" col opener: " +(d1-dstart)+" col vip: " + (d2-d1)+" col me:" + (d3-d2)+" col cit:" + (d4-d3)+" col age:" + (d5-d4)+"\n"+ (d5-dstart) );
function VIP(i_expr, i_col){
this.expr = i_expr;
this.col = i_col;
};
function isNumber(o) {
return typeof o === 'number' && isFinite(o);
};
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css.replace(/;/g, ' !important;');
head.appendChild(style);
}
function makeSidebarSticky(id)
{
if(! document.getElementById(id + '_sub'))
{
var bar = document.getElementById(id);
if(bar)
{
var newDiv = document.createElement('div');
bar.style.paddingLeft = '0px';
bar.style.paddingRight = '0px';
bar.style.paddingTop = '0px';
newDiv.id = id + '_sub';
newDiv.classList.add('sticky');
newDiv.style.borderTopWidth = '5px';
newDiv.style.borderTopColor = '#fa0';
newDiv.style.borderTopStyle = 'solid';
newDiv.style.paddingLeft = '6px';
newDiv.style.paddingRight = '6px';
newDiv.style.paddingTop = '6px';
newDiv.style.top = '0px';
while (bar.childNodes.length > 0) {
newDiv.appendChild(bar.childNodes[0]);
}
bar.appendChild(newDiv);
}
}
}