-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquora-only-answers.ts
61 lines (56 loc) · 1.62 KB
/
quora-only-answers.ts
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
// ==UserScript==
// @name quora-only-answers
// @namespace chester.me
// @match https://www.quora.com/*
// @match https://pt.quora.com/*
// @grant none
// @version 1.1
// @author @chesterbr
// @supportURL https://github.com/chesterbr/quora-only-answers/issues
// @license MIT
// @description Changes the filter drop-down in Quora questions from "All related (n)" to "Answers (n)", avoiding the annoying "related" questions/answers.
// @noframes
// ==/UserScript==
function clickDropdown() {
var dropdownCandidates = Array.from(document.querySelectorAll("button"))
for (var dropdown of dropdownCandidates) {
if (
dropdown.innerText.startsWith("All related (") ||
dropdown.innerText.startsWith("Todos relacionados (")
) {
dropdown.click()
return true
}
}
return false
}
function clickAnswers() {
if (!attemptToClickAnswers()) {
window.setTimeout(clickAnswers, 100)
}
}
const MAX_ATTEMPTS = 50
var attemptCount = 0
function attemptToClickAnswers() {
var menuItems = Array.from(document.querySelectorAll("div"))
for (var menuItem of menuItems) {
if (
menuItem.innerText.startsWith("Answer (") ||
menuItem.innerText.startsWith("Answers (") ||
menuItem.innerText.startsWith("Resposta (") ||
menuItem.innerText.startsWith("Respostas (")
) {
window.setTimeout(() => {
menuItem.click()
}, 100)
return true
}
}
// Menu item did not render yet; keep trying until we reach the limit
attemptCount++
return attemptCount > MAX_ATTEMPTS
}
/////// Main entry point
if (clickDropdown()) {
clickAnswers()
}