forked from Tiny-Giant/myuserscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVotesPageEnhancements.user.js
107 lines (83 loc) · 3.4 KB
/
VotesPageEnhancements.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
// ==UserScript==
// @name Votes Page Enhancer
// @namespace http://tampermonkey.net/
// @version 1.0.0.2
// @description Loads posts in their natural form on the votes pages for users.
// @author @Tiny-Giant
// @include /https?:\/\/(meta\.|www\.)?stackoverflow\.com/users/.*?tab\=votes.*/
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
let style = document.createElement('style');
style.textContent = '.actual-edit-overlay { display: none !important; }';
document.body.appendChild(style);
StackExchange.using("inlineEditing", function () {
StackExchange.inlineEditing.init();
});
let css = [
'.question, .answer {',
' width: 730px !important',
'}',
'.votecell {',
' vertical-align: top !important;',
'}',
'h1, h2, h3, h4, h5, h6 {',
' font-weight: normal',
'}'
].join('\n');
if (false);
else if ("undefined" != typeof GM_addStyle) GM_addStyle(css);
else if ("undefined" != typeof PRO_addStyle) PRO_addStyle(css);
else if ("undefined" != typeof addStyle) addStyle(css);
else (document.body || document.getElementsByTagName("body")[0]).appendChild(document.createElement("style").appendChild(document.createTextNode(css)).parentNode);
let initPost = (post, html, container, loader, parent) => {
let xhr = new XMLHttpRequest();
xhr.addEventListener('load', event => {
if(xhr.status !== 200) {
console.log(xhr.status, xhr.statusText, xhr.responseText);
return;
}
let question = (/\d+/.exec(document.querySelector('#enable-load-body-' + post).querySelector('a[href]'))||[false])[0];
let osnippets = container.querySelectorAll('.snippet');
container.innerHTML = html;
let nsnippets = container.querySelectorAll('.snippet');
loader.remove();
parent.appendChild(container);
StackExchange.question.init({
votesCast: JSON.parse(xhr.responseText),
canViewVoteCounts: true,
questionId: question
});
container.querySelector('.js-show-link.comments-link').click();
for(let i in Object.keys(nsnippets)) {
nsnippets[i].parentNode.insertBefore(osnippets[i], nsnippets[i]);
nsnippets[i].remove();
}
}, false);
xhr.open('GET', '/posts/' + post + '/votes');
xhr.send();
}
let fetchPost = post => {
let container = document.querySelector('#enable-load-body-' + post).parentNode.nextElementSibling.querySelector('.body-container');
let parent = container.parentNode;
container.remove();
let loader = parent.appendChild(document.createElement('td'));
loader.className = 'body-container';
loader.style.height = 'auto';
loader.innerHTML = '<img class="ajax-loader" src="/content/img/progress-dots.gif" title="loading..." alt="loading...">';
let xhr = new XMLHttpRequest();
xhr.addEventListener('load', event => {
if(xhr.status !== 200) {
console.log(xhr.status, xhr.statusText, xhr.responseText);
return;
}
initPost(post, xhr.responseText, container, loader, parent);
}, false);
xhr.open('GET', '/posts/ajax-load-realtime/' + post);
xhr.send();
}
$(document).ajaxComplete((event, request, settings) => {
let post = (/posts\/(\d+)\/body/.exec(settings.url)||[0,0])[1];
if (post) fetchPost(post);
});