-
Notifications
You must be signed in to change notification settings - Fork 1
/
codenamesSearch.user.js
76 lines (67 loc) · 2.94 KB
/
codenamesSearch.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
// ==UserScript==
// @name Codenames AniList Search
// @namespace http://tampermonkey.net/
// @version 1.0.5
// @description Adds AniList search buttons to Codenames tiles.
// @author You
// @match https://codenames.game/*
// @downloadURL https://raw.githubusercontent.com/4Lajf/codenames-scripts/main/codenamesSearch.user.js
// @updateURL https://raw.githubusercontent.com/4Lajf/codenames-scripts/main/codenamesSearch.user.js
// @grant none
// ==/UserScript==
(function () {
'use strict';
const attachSearchButtons = () => {
// Find all tiles
const tiles = document.querySelectorAll('.card.shadow-card');
tiles.forEach(tile => {
// Avoid duplicates
if (tile.querySelector('.search-btn')) return;
// Create a new search button element
const searchBtn = document.createElement('button');
searchBtn.innerText = '🔍';
searchBtn.classList.add('search-btn');
Object.assign(searchBtn.style, {
position: 'absolute',
top: '5px',
right: '5px',
zIndex: 1000,
cursor: 'pointer'
});
searchBtn.onclick = () => {
// Extract the text from the tile
const tileText = tile.textContent.trim().replace("🔍", "")
const searchQuery = encodeURIComponent(tileText);
// Open a new search tab
// AniList
window.open(`https://anilist.co/search/anime?sort=SEARCH_MATCH&search=${searchQuery}`, '_blank');
// AniDB
// window.open(`https://anidb.net/anime/?adb.search=${searchQuery}&do.search=1`, '_blank');
// Anime News Network
// window.open(`https://www.animenewsnetwork.com/search?q=${searchQuery}`, '_blank');
// Kitsu
// window.open(`https://kitsu.io/anime?text=${searchQuery}`, '_blank');
// MyAnimeList
// window.open(`https://myanimelist.net/anime.php?q=${searchQuery}`, '_blank');
};
// Make sure the tile can contain an absolutely positioned element
if (getComputedStyle(tile).position === 'static') {
tile.style.position = 'relative';
}
// Attach the search button to the tile
tile.appendChild(searchBtn);
});
};
// Use MutationObserver to track changes and add buttons when tiles are added
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
attachSearchButtons();
}
});
});
// Start observing the document body for changes
observer.observe(document.body, { childList: true, subtree: true });
// Initial check in case the page is already loaded
attachSearchButtons();
})();