-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhn-anonymizer.js
103 lines (80 loc) · 2.47 KB
/
hn-anonymizer.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
// ==UserScript==
// @name HN Anonymizer
// @author booleandilemma
// @description Anonymize your Hacker News username
// @homepageURL https://github.com/booleandilemma/hn-anonymizer
// @match https://news.ycombinator.com/*
// @version 1.0.0
// @grant none
// @license GPL-3.0
// @namespace https://greasyfork.org/users/777592
// ==/UserScript==
"use strict";
/* ========================== Configuration Info Starts Here ========================== */
/*
* Customize your username with this variable
* or leave it empty for asterisks.
*/
const customUsername = "";
/*
* Customize your profile url with this variable,
* or leave it blank to leave your profile url as is.
*/
const customProfileUrl = "";
/*
* Customize your HN karma with this variable.
*/
const karma = "47974";
/* ========================== Configuration Info Ends Here ========================== */
const UserScriptName = "HN Anonymizer";
/**
* Logs an info message to the console.
* @param {string} message - Specifies the message to log.
*/
function logInfo(message) {
console.info(`${UserScriptName}: ${message}`);
}
/**
* Logs an error message to the console.
* @param {string} message - Specifies the message to log.
*/
function logError(message) {
console.error(`${UserScriptName}: ${message}`);
}
function main() {
const usernameElement = document.getElementById("me");
if (usernameElement != null) {
if (customUsername !== "") {
usernameElement.innerHTML = customUsername;
} else {
usernameElement.innerHTML = "*****";
}
logInfo("Username anonymized");
if (customProfileUrl !== "") {
usernameElement.setAttribute("href", customProfileUrl);
logInfo("Profile URL anonymized");
}
} else {
logError("No username element found.");
}
const karmaElement = document.getElementById("karma");
if (karmaElement != null) {
karmaElement.innerText = karma;
logInfo("Karma anonymized");
} else {
logError("No karma element found.");
}
const asteriskElements = document.querySelectorAll('[color="#ff6600"]');
for (let i = 0; i < asteriskElements.length; i++) {
const asteriskElement = asteriskElements[i];
const voteArrow = document.createElement("div");
voteArrow.classList.add("votearrow");
voteArrow.title = "upvote";
asteriskElement.innerText = "";
asteriskElement.appendChild(voteArrow);
}
if (asteriskElements.length > 0) {
logInfo("Comments anonymized");
}
}
main();