-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrangling-home-filter-redux.user.js
98 lines (80 loc) · 4.11 KB
/
wrangling-home-filter-redux.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
// ==UserScript==
// @name AO3: [Wrangling] Wrangling Home Filter Redux
// @description A variation on the Wrangling Home Filter script that lets you filter by cowrangled or solo-wrangled fandoms.
// @version 1.0.2
// @updateURL https://raw.githubusercontent.com/kaerstyne/ao3-wrangling-scripts/master/wrangling-home-filter-redux.user.js
// @downloadURL https://raw.githubusercontent.com/kaerstyne/ao3-wrangling-scripts/master/wrangling-home-filter-redux.user.js
// @author kaerstyne
// @namespace https://github.com/kaerstyne/ao3-wrangling-scripts
// @license GPL-3.0 <https://www.gnu.org/licenses/gpl.html>
// @match *://*.archiveofourown.org/tag_wranglers/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @grant none
// ==/UserScript==
// SETTINGS //
// Add a list of your cowrangled fandoms below! Replace the example fandoms with your own.
// Put each fandom on a separate line.
// Use the EXACT NAME of the fandom as it appears on your wrangling page.
var cowrangled = `
Dangan Ronpa - All Media Types
Homestuck
Star Wars - All Media Types
`;
// END OF SETTINGS //
var cowrangled_list = cowrangled.trim().split("\n");
(function($) {
var all_fandoms = $(".assigned tbody tr");
// check if user has applied alternating row colors to the table
let alternating_rows = false;
if (all_fandoms.eq(0).css("background-color") !== all_fandoms.eq(1).css("background-color")) {
alternating_rows = [
all_fandoms.children("th[scope='row']").eq(0).css("background-color"), // odd fandom name columns
all_fandoms.eq(0).css("background-color"), // odd tag columns
all_fandoms.children("th[scope='row']").eq(1).css("background-color"), // even fandom name columns
all_fandoms.eq(1).css("background-color") // even tag columns
];
}
// label fandoms with shared and unwrangled status
all_fandoms.each(function() {
var fandom_name = $(this).find("th").text();
var unwrangled_counts = $(this).find("td").slice(3, 6).text();
if (cowrangled_list.includes(fandom_name)) {
$(this).addClass("shared-fandom");
} else {
$(this).addClass("solo-fandom");
}
if (unwrangled_counts == " ") {
$(this).addClass("no-unwrangled");
}
});
// add toggle menu
$("#user-page table").before("<p id='filter-fandoms'>Filter fandoms: " +
"<a id='shared-unwrangled'>[ shared unwrangled ]</a> " +
"<a id='solo-unwrangled'>[ solo unwrangled ]</a> " +
"<a id='all-unwrangled'>[ all unwrangled ]</a> " +
"<a id='all-fandoms'>[ all fandoms ]</a>" +
"</p>");
// add toggle functions
function add_toggle(toggle_class, ...classes_to_hide) {
$(toggle_class).click(function() {
all_fandoms.show();
classes_to_hide.forEach(function(class_to_hide) {
$(class_to_hide).hide();
});
// reapply alternating colors if applicable
if (alternating_rows) {
// fun fact, in jQuery the indexes are 0-based so the even/odd designations are backwards from vanilla CSS
all_fandoms.children("th[scope='row']:visible:even").css("background-color", alternating_rows[0]);
all_fandoms.filter(":visible:even").css("background-color", alternating_rows[1]);
all_fandoms.children("th[scope='row']:visible:odd").css("background-color", alternating_rows[2]);
all_fandoms.filter(":visible:odd").css("background-color", alternating_rows[3]);
}
$("#filter-fandoms").find("a").css("font-weight", "normal");
$(this).css("font-weight", "bold");
});
}
add_toggle("#shared-unwrangled", ".solo-fandom", ".no-unwrangled");
add_toggle("#solo-unwrangled", ".shared-fandom", ".no-unwrangled");
add_toggle("#all-unwrangled", ".no-unwrangled");
add_toggle("#all-fandoms");
})(jQuery);