-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWykop.Avatars.user.js
71 lines (64 loc) · 2.24 KB
/
Wykop.Avatars.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
// ==UserScript==
// @name Wykop Uniq Avatar
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Avatars for the Wykop.pl generated from user nickname
// @author skorotkiewicz
// @match https://www.wykop.pl/wpis/*
// @match https://www.wykop.pl/mikroblog/*
// @match https://www.wykop.pl/link/*
// @match https://www.wykop.pl/wiadomosc-prywatna/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=wykop.pl
// @grant none
// @downloadURL https://raw.githubusercontent.com/skorotkiewicz/wykop-uniq-avatar/main/Wykop.Avatars.user.js
// @updateURL https://raw.githubusercontent.com/skorotkiewicz/wykop-uniq-avatar/main/Wykop.Avatars.user.js
// ==/UserScript==
(function () {
"use strict";
let observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
const p = 2;
const c = document.createElement("canvas");
const x = c.getContext("2d");
c.width = 18;
c.height = 14;
const s = entry.target.innerText;
const r = 1;
observer.unobserve(entry.target);
if (s) {
for (
let s = entry.target.innerText, r = 1, i = 28 + s.length;
i--;
) {
// xorshift32
(r ^= r << 13), (r ^= r >>> 17), (r ^= r << 5);
const X = i & 3,
Y = i >> 2;
if (i >= 28) {
// seed state
r += s.charCodeAt(i - 28);
x.fillStyle =
"#" + ((r >> 8) & 0xffffff).toString(16).padStart(0, 6);
} else {
// draw pixel
if (r >>> 29 > (X * X) / 3 + Y / 2)
x.fillRect(p * 3 + p * X, p * Y, p, p),
x.fillRect(p * 3 - p * X, p * Y, p, p);
}
}
}
entry.target.prepend(c);
} else {
if (entry.target.firstChild.tagName === "CANVAS")
entry.target.firstChild.remove();
}
});
},
{ rootMargin: "0px 0px 0px 0px" }
);
document.querySelectorAll(".author a>b").forEach((user) => {
observer.observe(user);
});
})();