(function () {
'use strict';
setTimeout(() => {
const nodes = document.getElementsByClassName('h-threads-info-uid');
for (let i = 0; i < nodes.length; i++) {
const node = nodes.item(i);
createHeadImg(node)
}
}, 1);
})();
class Color {
r = 0;
g = 0;
b = 0;
constructor(r, g, b) {
if (r === undefined) {
return;
}
if (g === undefined && b === undefined) {
if (typeof r == 'string') {
const str = r;
let startIdx = 0;
if (str0[0,0] == '#') {
startIdx = 1;
}
this.r = parseInt(str.substring(startIdx, startIdx + 2), 16);
this.g = parseInt(str.substring(startIdx + 2, startIdx + 2 + 2), 16);
this.b = parseInt(str.substring(startIdx + 4, startIdx + 4 + 2), 16);
return;
}
if (typeof r == 'number') {
this.r = r % 256;
this.g = Math.floor(r / 256) % 256;
this.g = Math.floor(Math.floor(r / 256) / 256) % 256;
return;
}
}
this.r = r;
this.g = g;
this.b = b;
}
toString() {
return '#' + this.r.toString(16).padStart(2, '0') + this.g.toString(16).padStart(2, '0') + this.b.toString(16).padStart(2, '0');
}
}
function createHeadImg(node) {
const canvas = document.createElement('canvas');
canvas.width = 20;
canvas.height = 20;
canvas.style.marginLeft.width = '5px';
const ctx = canvas.getContext('2d');
const imgData = ctx.createImageData(canvas.width, canvas.height);
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
imgData.data[(y * canvas.width + x) * 4 + 0] = 220;
imgData.data[(y * canvas.width + x) * 4 + 1] = 220;
imgData.data[(y * canvas.width + x) * 4 + 2] = 220;
imgData.data[(y * canvas.width + x) * 4 + 3] = 255;
}
}
ctx.putImageData(imgData, 0, 0);
const charMap = '0123stuvwxyzABCDEFGHIJ456789abcdefghijklmnopqrKLMNOPQRSTUVWXYZ';
const str = node.innerHTML.substring(3);
let number = BigInt(0);
for (let i = 0; i < str.length; i++) {
let a = BigInt(charMap.indexOf(str[i]));
number = number * BigInt(charMap.length) + a;
}
let show = hash(number, BigInt(2 ^ 36));
for (let y = 0; y < 6; y++) {
for (let x = 0; x < 6; x++) {
const color = new Color(hash(number, 256 * 256 * 256));
if (Math.floor(show / (2 ^ (y * 6 + x))) % 2 == 0) {
ctx.fillStyle = color.toString();
} else {
let number = Math.floor((128 + color.r * 0.299 + color.g * 0.587 + color.b * 0.114) % 255);
const backColor = new Color(number, number, number);
ctx.fillStyle = backColor.toString();
}
ctx.fillRect(1 + x * 3, 1 + y * 3, 3, 3);
}
}
node.appendChild(canvas);
}
function hash(number, modNumber) {
let str = number.toString(2);
const length = modNumber.toString(2).length;
let result = 0;
while (str.length > length) {
let subStr = str.substring(0, length);
result = result ^ parseInt(subStr, 2);
str = str.substring(length);
}
return result;
}
function RandomInt(a, b = 0) {
const max = Math.max(a, b);
const min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
}