-
Notifications
You must be signed in to change notification settings - Fork 34
/
10kToolsHelper.user.js
135 lines (113 loc) · 3.98 KB
/
10kToolsHelper.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// ==UserScript==
// @name 10k Tools Helper
// @description Expand all sections, and adds additional post type filters
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 3.2.13
//
// @match https://*.stackoverflow.com/tools*
// @match https://*.serverfault.com/tools*
// @match https://*.superuser.com/tools*
// @match https://*.askubuntu.com/tools*
// @match https://*.mathoverflow.net/tools*
// @match https://*.stackapps.com/tools*
// @match https://*.stackexchange.com/tools*
// @match https://stackoverflowteams.com/c/*/tools*
//
// @exclude https://api.stackexchange.com/*
// @exclude https://data.stackexchange.com/*
// @exclude https://contests.stackoverflow.com/*
// @exclude https://winterbash*.stackexchange.com/*
// @exclude *chat.*
// @exclude *blog.*
// @exclude */tour
//
// @require https://raw.githubusercontent.com/samliew/SO-mod-userscripts/master/lib/se-ajax-common.js
// @require https://raw.githubusercontent.com/samliew/SO-mod-userscripts/master/lib/common.js
// ==/UserScript==
/* globals StackExchange */
/// <reference types="./globals" />
'use strict';
const currentTab = document.querySelector('.tools-rev .js-filter-btn .youarehere');
const currentTabName = currentTab.dataset.value;
const callbackWhenPageLoaded = () => {
if (currentTabName === 'stats') {
// Unused
}
else if (currentTabName === 'migrated') {
// Unused
}
else if (currentTabName === 'close') {
// Unused
}
else if (currentTabName === 'delete') {
// Add question and answer filters
const buttonWrapper = makeElemFromHtml(`
<div class="modtools-filters-wrapper d-flex ai-center">Quick filters:
<div class="modtools-filters flex--item fw-nowrap ml12 d-flex s-btn-group js-filter-btn">
<button type="button" class="flex--item s-btn s-btn__muted s-btn__outlined" data-filter="q">Questions</button>
<button type="button" class="flex--item s-btn s-btn__muted s-btn__outlined" data-filter="a">Answers</button>
</div>
<div>`);
document.querySelector('.tools-index-subtabs').appendChild(buttonWrapper);
// Get all items, and add post type data attribute
const items = document.querySelectorAll('.summary-table tr');
items.forEach(tr => tr.dataset.postType = tr.querySelectorAll('.question-hyperlink').length ? 'q' : 'a');
// On click, toggle items
buttonWrapper.addEventListener('click', function (evt) {
if (!evt.target.matches('button[data-filter]')) return;
evt.target.classList.toggle('is-selected');
const selectedButtons = buttonWrapper.querySelectorAll('button[data-filter].is-selected');
// If both selected or unselected, show all
if (selectedButtons.length != 1) {
items.forEach(el => el.classList.remove('d-none'));
}
// Show only selected post type
else {
const activeFilter = selectedButtons[0].dataset.filter;
items.forEach(el => el.classList.toggle('d-none', el.dataset.postType != activeFilter));
}
});
}
};
// Append styles
addStylesheet(`
/* General 10k tools UI improvements */
.island div[data-mode="newTags"] table.summary-table.no-collapse tr {
display: flex;
flex-wrap: wrap;
}
.summary-table tr td {
vertical-align: middle;
}
.summary-table tr a {
word-break: break-word;
}
.summary-table tr a.question-hyperlink {
font-size: var(--fs-body2);
}
.summary-table tr a.question-hyperlink:before {
content: 'Q: ';
}
.summary-table tr a.answer-hyperlink:before {
/* content: 'A: '; */
}
/* Show all collapsed items */
.summary-table tr.collapsing {
display: table-row;
}
.expander-arrow-small-hide,
.summary-table tr.d-none {
display: none !important;
}
/* Delete tabs filters */
.modtools-filters-wrapper {
}
.modtools-filters-wrapper .modtools-filters {
}
`); // end stylesheet
// On script run
(function init() {
// Once on page load only
$(document).one('ajaxStop', callbackWhenPageLoaded);
})();