Project

General

Profile

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

hydrilla-fixes-bundle / src / tp-link-com-fix-downloads / tp-driver.js @ f938b039

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

    
46
/*
47
 * Use with:
48
 * * https://www.tp-link.com/us/support/**
49
 * * https://www.tp-link.com/au/support/**
50
 * * etc...
51
 */
52

    
53
/* show drivers by default (TODO: make it so you click the "Driver" button to
54
	reveal, and also let people click the "Setup Video" and "FAQ" buttons) */
55
if (document.getElementById("content_Driver")) {
56
	document.getElementById("content_Driver").style.display = "initial";
57
}
58

    
59
/* TODO: Show FAQ sections here (https://www.tp-link.com/us/support/faq/46/),
60
	using the selector `#article .faq-slide + div` and setting the display to
61
	not "none" (probably "initial" (actually "inherit" might be better than
62
	"initial" generally, idk))) */
63

    
64
// show support version selection drop down menus (example: https://www.tp-link.com/us/support/download/tl-wn725n/)
65
if (document.getElementsByClassName("select-version")[0]) {
66
	const dropdown = document.getElementsByClassName("select-version")[0].getElementsByTagName("dd")[0].getElementsByTagName("ul")[0];
67
	document.getElementsByClassName("select-version")[0].getElementsByTagName("dd")[0].addEventListener("click", function() {
68
		if (dropdown.style.getPropertyValue("display") == "inherit") {
69
			dropdown.style.setProperty("display", "none");
70
		} else {
71
			dropdown.style.setProperty("display", "inherit");
72
		}
73
	});
74
}
75

    
76
/* Enable drop-down lists. */
77
let first_item = null;
78

    
79
let viewed_item = null;
80

    
81
function change_item_visibility(item, visible) {
82
    const icon     = item.querySelector("h2 i");
83
    const item_box = item.querySelector(".item-box");
84

    
85
    if (icon === null || item_box === null)
86
	return;
87

    
88
    icon.classList[visible ? "add" : "remove"]("tp-active");
89

    
90
    item_box.style.display = visible ? "block" : "none";
91
}
92

    
93
function toggle_item(item) {
94
    if (item === viewed_item) {
95
	change_item_visibility(item, false);
96

    
97
	viewed_item = null;
98
    } else {
99
	if (viewed_item !== null)
100
	    change_item_visibility(viewed_item, false);
101

    
102
	change_item_visibility(item, true);
103

    
104
	viewed_item = item;
105
    }
106
}
107

    
108
for (const list_item of document.querySelectorAll("#list .item")) {
109
    first_item = first_item || list_item;
110

    
111
    const heading = list_item.querySelector("h2");
112
    if (heading !== null)
113
	heading.addEventListener("click", () => toggle_item(list_item));
114
}
115

    
116
if (first_item !== null)
117
    toggle_item(first_item);
(2-2/2)