Project

General

Profile

Download (4.13 KB) Statistics
| Branch: | Revision:

hydrilla-fixes-bundle / src / nintendo-com-fix-support / nintendo.js @ 6735fa55

1
/**
2
 * SPDX-License-Identifier: LicenseRef-GPL-3.0-or-later-WITH-js-exceptions
3
 *
4
 * Make Nintendo Support reasonably consumable when its JS is blocked.
5
 *
6
 * Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * As additional permission under GNU GPL version 3 section 7, you
19
 * may distribute forms of that code without the copy of the GNU
20
 * GPL normally required by section 4, provided you include this
21
 * license notice and, in case of non-source distribution, a URL
22
 * through which recipients can access the Corresponding Source.
23
 * If you modify file(s) with this exception, you may extend this
24
 * exception to your version of the file(s), but you are not
25
 * obligated to do so. If you do not wish to do so, delete this
26
 * exception statement from your version.
27
 *
28
 * As a special exception to the GPL, any HTML file which merely
29
 * makes function calls to this code, and for that purpose
30
 * includes it by reference shall be deemed a separate work for
31
 * copyright law purposes. If you modify this code, you may extend
32
 * this exception to your version of the code, but you are not
33
 * obligated to do so. If you do not wish to do so, delete this
34
 * exception statement from your version.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
38
 *
39
 *
40
 * I, Wojtek Kosior, thereby promise not to sue for violation of this file's
41
 * license. Although I request that you do not make use of this code in a
42
 * proprietary program, I am not going to enforce this in court.
43
 */
44

    
45
/* Use with: https://*.nintendo.com/app/*** */
46

    
47
/* Show the main text. */
48
document.documentElement.classList.remove("no-js");
49

    
50
/* Fix menu bar (TODO: also fix the hamburger version for smaller screens). */
51
const title_bar = document.querySelector(".title-bar");
52
if (title_bar !== null)
53
    title_bar.style.display = "none";
54

    
55
const top_menu = document.querySelector(".top-bar-left>.menu");
56
if (top_menu !== null) {
57
    top_menu.classList.add("dropdown");
58
    top_menu.classList.remove("accordion-menu");
59
}
60

    
61
function show_submenu(submenu) {
62
    submenu.classList.add("js-dropdown-active");
63
}
64

    
65
function hide_submenu(submenu) {
66
    submenu.classList.remove("js-dropdown-active");
67
}
68

    
69
for (const submenu_parent of
70
     document.getElementsByClassName("rn_ProductCategoryItem")) {
71
    submenu_parent.classList.add("is-dropdown-submenu-parent");
72
    submenu_parent.classList.add("opens-right");
73

    
74
    const submenu = submenu_parent.querySelector(".rn_SubItemList");
75
    if (submenu === null)
76
	continue;
77

    
78
    submenu.classList.add("submenu");
79
    submenu.classList.add("is-dropdown-submenu");
80
    submenu.classList.add("first-sub");
81

    
82
    submenu_parent.addEventListener("mouseenter", () => show_submenu(submenu));
83
    submenu_parent.addEventListener("mouseleave", () => hide_submenu(submenu));
84
}
85

    
86
/* Fix search. */
87
const search_input = document.getElementById("rn_KeywordText_5_Text");
88

    
89
function on_search_submit(event) {
90
    event.preventDefault();
91

    
92
    if (!search_input.value)
93
	return;
94

    
95
    const encoded = encodeURIComponent(search_input.value);
96
    window.location.pathname = `/app/answers/list/kw/${encoded}/search/1`;
97
}
98

    
99
if (search_input !== null && search_input.form !== null)
100
    search_input.form.addEventListener("submit", on_search_submit);
101

    
102
/* Fix navigation to other pages of search results. */
103
for (const results_page_link of
104
     document.querySelectorAll('[href^="/app/answers/list/page/"]')) {
105
    const page_nr = /[0-9]*$/.exec(results_page_link.href);
106
    const current_path = window.location.pathname;
107
    results_page_link.href = current_path
108
	.replace("list/kw", "list/st/5/kw")
109
	.replace(/(search|page)\/[0-9]*$/, `page/${page_nr}`);
110
}
(2-2/2)