forked from Tiny-Giant/myuserscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReviewEnhancements.user.js
128 lines (86 loc) · 3.33 KB
/
ReviewEnhancements.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
// ==UserScript==
// @name Review Enhancements
// @namespace http://github.com/Tiny-Giant
// @version 1.0.0.4
// @description The review queues are abstractions with some limitations. This script removes those limitations on questions
// @author @TinyGiant
// @include /https?:\/\/(meta\.|www\.)?stackoverflow.com\/review\/(?!custom).*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
StackExchange.using("inlineEditing", function () {
StackExchange.inlineEditing.init();
});
let initQuestion = (post) => {
let xhr = new XMLHttpRequest();
xhr.addEventListener('load', event => {
if(xhr.status !== 200) {
console.log(xhr.status, xhr.statusText, xhr.responseText);
return;
}
StackExchange.question.init({
votesCast: JSON.parse(xhr.responseText),
canViewVoteCounts: true,
questionId: post
});
let commentLinks = document.querySelectorAll('.js-show-link.comments-link');
for(let i in Object.keys(commentLinks)) commentLinks[i].click();
}, false);
xhr.open('GET', '/posts/' + post.dataset.questionid + '/votes');
xhr.send();
}
let postQueue = [], fetching = false;
let fetchPost = () => {
fetching = true;
let post = postQueue.shift();
let xhr = new XMLHttpRequest();
xhr.addEventListener('load', event => {
if(xhr.status !== 200) {
console.log(xhr.status, xhr.statusText, xhr.responseText);
return;
}
let parent = post.parentNode;
let osnippets = post.querySelectorAll('.snippet');
post.outerHTML = xhr.responseText;
post = parent.querySelector('.question, .answer');
let nsnippets = post.querySelectorAll('.snippet');
for(let i in Object.keys(nsnippets)) {
nsnippets[i].parentNode.insertBefore(osnippets[i], nsnippets[i]);
nsnippets[i].remove();
}
if(/downvoted-answer/.test(post.className)) post.classList.remove('downvoted-answer');
/*let hidden = post.querySelectorAll('.snippet');
for(let i in Object.keys(hidden)) {
hidden[i].dataset.hide = 'true';
}*/
if (/question/.test(post.className)) initQuestion(post);
fetching = false;
}, false);
xhr.open('GET', '/posts/ajax-load-realtime/' + (post.dataset.questionid || post.dataset.answerid));
xhr.send();
}
let queuePost = (post) => {
if (!post) return;
postQueue.push(post);
if(fetching) {
let fetchWait = setInterval(() => {
if(fetching) return;
clearInterval(fetchWait);
fetchPost();
}, 100);
} else fetchPost();
}
$(document).ajaxComplete((one, two, three) => {
if(!/next\-task|task\-reviewed/.test(three.url)) return;
let task = JSON.parse(two.responseText);
console.log('TASK', task);
if(!task || task.isAudit) return;
let question = document.querySelector('.question');
if (!question) return;
let answers = document.querySelectorAll('.answer');
for(let i in Object.keys(answers)) queuePost(answers[i]);
queuePost(question);
let reviewable = document.querySelectorAll('.reviewable-post');
for(let i in Object.keys(reviewable)) reviewable[i].parentNode.setAttribute('style', '');
});