-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickclear.user.js
95 lines (82 loc) · 3.86 KB
/
quickclear.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
// ==UserScript==
// @name Quick Profile Clear
// @version 1.0.3
// @description Quickly clear all user fields to a pre-set set of fields
// @author lyxal (https://github.com/lyxal) (https://stackexchange.com/users/12951433/lyxal?tab=accounts)
// @match *://*.stackexchange.com/users/*
// @match *://*.stackoverflow.com/users/*
// @match *://stackoverflow.com/users/*
// @match *://superuser.com/users/*
// @match *://serverfault.com/users/*
// @match *://askubuntu.com/users/*
// @match *://stackapps.com/users/*
// @match *://mathoverflow.net/users/*
// @exclude *://stackexchange.com/users/*
// @exclude *://chat.stackexchange.com/users/*
// @exclude *://chat.stackoverflow.com/users/*
// @exclude *://chat.meta.stackexchange.com/users/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
var bioText = `Profile spam removed by moderator
` // Feel free to change
function clearUser() {
const networkButton = document.querySelector(".d-flex.ai-center.ws-nowrap.s-btn.s-btn__outlined.s-btn__muted.s-btn__icon.s-btn__sm.d-flex.ai-center");
const networkID = networkButton.href;
const ID = networkID.match(/https:\/\/stackexchange\.com\/users\/(\d+)/)[1];
document.getElementById("displayName").value = `Profile Spam Account ${ID}`;
document.getElementById("location").value = "Spam";
document.getElementById("WebsiteUrl").value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
document.getElementById("TwitterUrl").value = "";
document.getElementById("GitHubUrl").value = "";
document.getElementById("wmd-input").innerHTML = bioText
localStorage.setItem("spammer" + document.location.host + userID, "true");
submitButton.click();
}
function generateRandomString(length) {
const characters = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789!@#$%^&*-=_+';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}
return result;
}
function sanityCheck() {
// Get the current time (without seconds and without space)
const neededCharacters = generateRandomString(Math.floor(Math.random() * 5) + 5); // Generate a random string with a length between 5 and 10
// Prompt the user for input
const userInput = prompt('Enter the characters: ' + neededCharacters);
// Check if the input is correct
if (userInput && userInput === neededCharacters) {
return true;
} else {
alert('Sanity check failed. Please try again.');
return false;
}
}
var userIDRegex = /\/users\/edit\/(\d+)/g.exec(document.location);
if (userIDRegex == null) {
return; // e.g. flag summary page
}
var userID = userIDRegex[1];
var moderatorLinkElement = $('a[data-se-mod-button-id=' + userID + ']');
if (moderatorLinkElement.length == 0) { // Current user is not a moderator, or wrong tab - no action possible
return;
}
var saveButton = document.getElementById("cancel")
var destroyLink = document.createElement('a');
let submitButtons = document.getElementsByClassName("flex--item s-btn s-btn__filled js-save-button");
let submitButton = submitButtons[submitButtons.length - 1];
destroyLink.setAttribute('class', 's-btn s-btn__filled');
destroyLink.setAttribute('style', 'background-color: red;');
destroyLink.appendChild(document.createTextNode('Clear User Fields'));
destroyLink.onclick = function () {
if (sanityCheck()) {
clearUser()
}
}
moderatorLinkElement.after(destroyLink);
})();