-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathso-hide-answers.user.js
99 lines (87 loc) · 3.42 KB
/
so-hide-answers.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
// ==UserScript==
// @name Hide Stack Exchange answers
// @description add a checkbox to every answer collapsing that answer, and to the entre block, hiding the block.
// @match http://stackoverflow.com/*
// @match http://serverfault.com/*
// @match http://meta.stackoverflow.com/*
// @match http://askubuntu.com/*
// @match http://stackapps.com/*
// @match http://answers.onstartups.com/*
// @match http://mathoverflow.com/*
// @match http://superuser.com/*
// @version 1.0
// ==/UserScript==
(function(){
var ANSWER_CB_TEXT = "collapse"
var ANSWERS_CB_TEXT = "hide all answers"
var w = (typeof unsafeWindow !== "undefined") ? unsafeWindow : window;
var $ = w.$
$(".answer").each(repaintAnswer);
$(document).ajaxSuccess(function(_,_,options){
var match = options.url.match(/ajax-load-realtime\/([\d;]+)/);
if(!match) return;
var ids = match[1].split(";");
for(var i = 0; i < ids.length; i++){
var answer = document.getElementById("answer-" + ids[i]);
if(answer) repaintAnswer.call(answer);
}
})
w.styleCode = (function(styleCode){
return function(){
styleCode.apply(this, arguments);
$(".answer").each(repaintAnswer);
}
})(w.styleCode);
addGlobalHide();
addCss();
///
function repaintAnswer(){
var $answer = $(this)
if($answer.has(".answer-collapse").length) return;
$answer.addClass("answer-expanded").removeClass("answer-collapsed")
.find(".post-menu").append($("<span>", {"class": "lsep", text: "|"}))
.append(
$("<input>", {type:'checkbox', "class": "answer-collapse", change: function(){
var whStart = this.offsetTop - window.scrollY;
if(this.checked){
$answer.addClass("answer-collapsed").removeClass("answer-expanded");
}else{
$answer.addClass("answer-expanded").removeClass("answer-collapsed");
}
var whEnd = this.offsetTop - window.scrollY;
window.scrollBy(0, whEnd - whStart);
}})
).append($("<span>", {text: ANSWER_CB_TEXT}))
}
function addGlobalHide(){
$answers = $("#answers");
$("#post-form").before(
$("<input>", {type: "checkbox", id: "answers-collapse", change: function(){
var whStart = this.offsetTop - window.scrollY;
if(this.checked){
$answers.addClass("answers-collapsed").removeClass("answers-expanded");
}else{
$answers.addClass("answers-expanded").removeClass("answers-collapsed");
}
var whEnd = this.offsetTop - window.scrollY;
window.scrollBy(0, whEnd - whStart);
}})
).before($("<span>", {text: ANSWERS_CB_TEXT}));
}
function addCss(){
$(document.head).append($("<style>", {text:
".answer-collapsed .vote, "+
".answer-collapsed .post-text "+
"{height:0; padding:0; overflow:hidden} "+ //so that the width still applies
".post-menu .answer-collapse {margin: 5px; position:relative; top:3px} "+
".answer-collapsed {padding: 0} "+
".answer-collapsed .post-menu > a, "+
".answer-collapsed .post-menu > a + .lsep {display:none} "+
".answer-collapsed > table > tbody > tr:nth-child(2) {display:none} "+
"#answers-collapse {margin-right: 5px; margin-top: 20px} "+
".answers-collapsed .answer, "+
".answers-collapsed #tabs {display: none} "
}));
$("#post-form .space").removeClass("space");
}
})();