-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxenforo-popular.js
76 lines (69 loc) · 2.95 KB
/
xenforo-popular.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
// ==UserScript==
// @author dylanarmstrong
// @description Hide unpopular stories for easier browsing of recent
// @grant none
// @match https://forums.spacebattles.com/forums/creative-writing-archives.40/*
// @match https://forums.spacebattles.com/forums/creative-writing.18/*
// @match https://forums.spacebattles.com/forums/original-fiction.48/*
// @match https://forums.spacebattles.com/forums/roleplaying-quests-story-debates.60/*
// @match https://forums.spacebattles.com/forums/the-index.63/*
// @match https://forums.spacebattles.com/forums/worm.115/*
// @match https://forums.sufficientvelocity.com/forums/archive.31/*
// @match https://forums.sufficientvelocity.com/forums/quests-archive.17/*
// @match https://forums.sufficientvelocity.com/forums/quests.29/*
// @match https://forums.sufficientvelocity.com/forums/unlisted-fiction.15/*
// @match https://forums.sufficientvelocity.com/forums/user-fiction.2/*
// @match https://forums.sufficientvelocity.com/forums/weird-history.95/*
// @match https://forums.sufficientvelocity.com/forums/worm.94/*
// @name xenforo-popular
// @namespace https://github.com/dylanarmstrong/userscripts/
// @supportURL https://github.com/dylanarmstrong/userscripts/issues
// @updateURL https://raw.githubusercontent.com/dylanarmstrong/userscripts/master/xenforo-popular.js
// @version 6
// ==/UserScript==
/**
* Hides unpopular stories on spacebattles / sufficient velocity
*
* TODO: It says xenforo.. but it only works for 2 sites, add alternatehistory
*/
(function() {
'use strict';
const viewLimit = 50000;
const replyLimit = 100;
const hidden = [];
const viewEach = (element) => {
const textContent = element.textContent.trim().toLowerCase();
const k = textContent.endsWith('k') ? 1000 : 1;
const m = textContent.endsWith('m') ? 1000 * 1000 : 1;
const viewCount = Number(textContent.replace(/[,km]/g, '')) * k * m;
if (viewCount < viewLimit) {
hidden.push(element);
}
};
const replyEach = (element) => {
const textContent = element.textContent.trim().toLowerCase();
const k = textContent.endsWith('k') ? 1000 : 1;
const m = textContent.endsWith('m') ? 1000 * 1000 : 1;
const replyCount = Number(textContent.replace(/[,km]/g, '')) * k * m;
if (replyCount > replyLimit) {
if (hidden.includes(element)) {
hidden.remove(element);
}
}
};
let elements =
document
.querySelectorAll('.structItem-cell.structItem-cell--meta dl:nth-child(2) dd');
elements.forEach(viewEach);
elements =
document
.querySelectorAll('.structItem-cell.structItem-cell--meta dl:nth-child(1) dd');
elements.forEach(replyEach);
for (let i = 0, len = hidden.length; i < len; i++) {
const element = hidden[i];
const p = element.parentNode.parentNode.parentNode;
if (p && p.parentNode) {
p.parentNode.removeChild(p);
}
}
})();