-
Notifications
You must be signed in to change notification settings - Fork 0
/
joker.js
41 lines (37 loc) · 1.51 KB
/
joker.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
window.addEventListener('click', () => {
if (document.getElementById('joker')) {
return;
}
// create joker
const search = document.querySelector("[data-testid='search-alt']");
if (!search) {
return;
}
let joker = document.createElement('img');
joker.src = chrome.runtime.getURL('img/joker.svg');
joker.style.padding = '0.5rem';
joker.style.height = '1.5rem';
joker.style.cursor = 'pointer';
joker.setAttribute('id', 'joker');
joker.setAttribute('title', 'Joker');
joker.setAttribute('aria-label', 'Joker');
joker.addEventListener('click', () => {
const inputText = document.querySelectorAll(".copyable-text.selectable-text[contenteditable='true']")[1];
const request = new XMLHttpRequest();
request.open('GET', 'https://v2.jokeapi.dev/joke/Any?blacklistFlags=religious,political,racist&format=txt');
request.addEventListener('load', () => {
if (request.status >= 200 && request.status < 300) {
inputText.innerHTML = request.responseText;
inputText.dispatchEvent(new Event('input', {bubbles: true}));
const send = document.querySelector("[data-testid='send']").parentElement;
send.click();
} else {
console.warn(request.statusText, request.responseText);
}
});
request.send();
});
// append joker
const parent = search.parentElement.parentElement.parentElement;
parent.appendChild(joker);
})