-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotCardMenu.js
More file actions
139 lines (115 loc) · 4.46 KB
/
BotCardMenu.js
File metadata and controls
139 lines (115 loc) · 4.46 KB
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
(function () {
'use strict';
const STORAGE_HIDDEN_BOTS = 'hidden_bots';
const STORAGE_HIDDEN_AUTHORS = 'hidden_authors';
const getHiddenBots = () => JSON.parse(localStorage.getItem(STORAGE_HIDDEN_BOTS) || '[]');
const saveHiddenBots = (arr) => localStorage.setItem(STORAGE_HIDDEN_BOTS, JSON.stringify(arr));
function addMenuButtons() {
document.querySelectorAll('a[href^="/chat/"]').forEach(card => {
if (card.querySelector('.ux-bot-menu-btn')) return;
const href = card.getAttribute('href');
const idMatch = href.match(/\/chat\/([^\/?#]+)/);
const botId = idMatch ? idMatch[1] : null;
let author = 'unknown';
const text = card.innerText || '';
const authorMatch = text.match(/by\s+([^\n]+)/i);
if (authorMatch) author = authorMatch[1].trim();
if (!botId) return;
const menuBtn = document.createElement('button');
menuBtn.innerText = '⋮';
menuBtn.title = 'Bot menu';
menuBtn.className = 'ux-bot-menu-btn absolute top-2 right-2 text-lg z-50 bg-transparent border-none cursor-pointer text-foreground';
menuBtn.style.userSelect = 'none';
menuBtn.onclick = (e) => {
e.stopPropagation();
e.preventDefault();
showBotMenu(e.pageX, e.pageY, botId, author, card);
};
if (window.getComputedStyle(card).position === 'static') {
card.style.position = 'relative';
}
card.appendChild(menuBtn);
});
}
function showBotMenu(x, y, botId, author, card) {
const oldMenu = document.getElementById('ux-bot-menu-popup');
if (oldMenu) oldMenu.remove();
const menu = document.createElement('div');
menu.id = 'ux-bot-menu-popup';
menu.style.position = 'absolute';
menu.style.top = y + 'px';
menu.style.left = x + 'px';
menu.style.background = '#202024';
menu.style.border = '1px solid #444';
menu.style.borderRadius = '12px'; // увеличенное скругление
menu.style.boxShadow = '0 4px 12px rgba(0,0,0,0.5)';
menu.style.zIndex = 9999;
menu.style.minWidth = '160px';
menu.style.color = '#eee';
menu.style.fontSize = '14px';
menu.style.userSelect = 'none';
menu.style.transition = 'opacity 0.2s ease, transform 0.2s ease';
menu.style.opacity = '0';
menu.style.transform = 'scale(0.95)';
document.body.appendChild(menu);
// плавное появление
requestAnimationFrame(() => {
menu.style.opacity = '1';
menu.style.transform = 'scale(1)';
});
function createMenuItem(text, onClick) {
const item = document.createElement('div');
item.innerText = text;
item.style.padding = '10px';
item.style.cursor = 'pointer';
item.style.transition = 'background 0.2s ease, border-radius 0.2s ease';
item.onmouseenter = () => item.style.background = '#3f3f46';
item.onmouseleave = () => item.style.background = 'transparent';
item.onclick = onClick;
return item;
}
const hideBot = createMenuItem('Hide bot', () => {
hideSingleBot(botId, card);
menu.remove();
});
const hideAuthor = createMenuItem(`Hide all bots of the author: ${author}`, () => {
alert(`Sorry, this feature is still very bad, I'm working on it.\n\nMade with ♡ by UXImprover`);
menu.remove();
});
menu.appendChild(hideBot);
menu.appendChild(hideAuthor);
const clickOutside = (e) => {
if (!menu.contains(e.target)) {
menu.remove();
document.removeEventListener('click', clickOutside);
}
};
document.addEventListener('click', clickOutside);
}
function hideSingleBot(botId, card) {
let hiddenBots = getHiddenBots();
if (!hiddenBots.includes(botId)) {
hiddenBots.push(botId);
saveHiddenBots(hiddenBots);
}
card.style.display = 'none';
}
function filterHiddenCards() {
const hiddenBots = getHiddenBots();
document.querySelectorAll('a[href^="/chat/"]').forEach(card => {
const href = card.getAttribute('href');
const idMatch = href.match(/\/chat\/([^\/?#]+)/);
const botId = idMatch ? idMatch[1] : null;
if (botId && hiddenBots.includes(botId)) {
card.style.display = 'none';
} else {
card.style.display = '';
}
});
}
function mainLoop() {
addMenuButtons();
filterHiddenCards();
}
setInterval(mainLoop, 1500);
})();