-
Notifications
You must be signed in to change notification settings - Fork 2
/
pokemondb-default-version.user.js
101 lines (96 loc) · 2.44 KB
/
pokemondb-default-version.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
96
97
98
99
100
101
// ==UserScript==
// @name PokemonDB Default Version
// @namespace https://greasyfork.org/users/649
// @version 2.1.5
// @description Auto selects the chosen version in the Moves section on PokemonDB
// @author Adrien Pyke
// @match *://pokemondb.net/pokedex/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @require https://cdn.jsdelivr.net/gh/kufii/My-UserScripts@22210afba13acf7303fc91590b8265faf3c7eda7/libs/gm_config.js
// ==/UserScript==
(() => {
'use strict';
const Config = GM_config([
{
key: 1,
label: 'Gen 1',
type: 'dropdown',
showBlank: true,
values: ['Red/Blue', 'Yellow']
},
{
key: 2,
label: 'Gen 2',
type: 'dropdown',
showBlank: true,
values: ['Gold/Silver', 'Crystal']
},
{
key: 3,
label: 'Gen 3',
type: 'dropdown',
showBlank: true,
values: ['Ruby/Sapphire', 'FireRed/LeafGreen', 'Emerald']
},
{
key: 4,
label: 'Gen 4',
type: 'dropdown',
showBlank: true,
values: ['Diamond/Pearl', 'Platinum', 'HeartGold/SoulSilver']
},
{
key: 5,
label: 'Gen 5',
type: 'dropdown',
showBlank: true,
values: ['Black/White', 'Black 2/White 2']
},
{
key: 6,
label: 'Gen 6',
type: 'dropdown',
showBlank: true,
values: ['X/Y', 'Omega Ruby/Alpha Sapphire']
},
{
key: 7,
label: 'Gen 7',
type: 'dropdown',
showBlank: true,
values: [
'Sun/Moon',
'Ultra Sun/Ultra Moon',
"Let's Go Pikachu/Let's Go Eevee"
]
}
]);
GM_registerMenuCommand('Select default PokemonDB versions', Config.setup);
const match = location.href.match(
/^https?:\/\/pokemondb\.net\/pokedex\/.*?\/moves\/(\d+)/iu
);
const currentGen = match ? match[1] : 7;
const defaultVersion = Config.load()[currentGen];
const tabs = Array.from(
document.querySelectorAll('.tabs-tab-list > a.tabs-tab')
);
if (defaultVersion) {
const [tab] = tabs.filter(tab => tab.textContent === defaultVersion);
if (tab) {
tab.click();
}
}
let changing = false;
tabs.forEach(tab =>
tab.addEventListener('click', () => {
if (changing) return;
changing = true;
tabs
.filter(tabB => tabB.textContent === tab.textContent)
.forEach(tabB => tabB.click());
changing = false;
})
);
})();