-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dumbing_of_Age_comment_helper.user.js
165 lines (141 loc) · 5.86 KB
/
Dumbing_of_Age_comment_helper.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// ==UserScript==
// @name Dumbing of Age comment helper
// @namespace trlkly
// @include http://www.dumbingofage.com/*
// @version 2.3
// @run-at document-start
// @grant GM_registerMenuCommand
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// ==/UserScript==
var ignoreList // = "name|name|name" //if you lack GM_registerMenu
var chromeOverride;
//console.log ('script fired')
if (typeof GM_registerMenuCommand != 'undefined') {
var getIgnoreList = function() {
var input = window.prompt('Enter ignore list, e.g. name|name|name\n' +
'(Refresh page to activate)',
(chromeOverride ? '$override||' : '') + ignoreList);
if (input !== null) { GM_setValue('ignoreList', input); return input; }
return ignoreList;
};
ignoreList = GM_getValue('ignoreList', '');
GM_registerMenuCommand('Edit Ignore List (DofA helper)', function (){
ignoreList = getIgnoreList();
});
//console.log ('script fired')
}
//innerText polyfill
if ( (!('innerText' in document.createElement('a'))) && ('getSelection' in window) ) {
HTMLElement.prototype.__defineGetter__("innerText", function() {
var selection = window.getSelection(),
ranges = [],
str;
// Save existing selections.
for (var i = 0; i < selection.rangeCount; i++) {
ranges[i] = selection.getRangeAt(i);
}
// Deselect everything.
selection.removeAllRanges();
// Select `el` and all child nodes.
// 'this' is the element .innerText got called on
selection.selectAllChildren(this);
// Get the string representation of the selected nodes.
str = selection.toString();
// Deselect everything. Again.
selection.removeAllRanges();
// Restore all formerly existing selections.
for (var i = 0; i < ranges.length; i++) {
selection.addRange(ranges[i]);
}
// Oh look, this is what we wanted.
// String representation of the element, close to as rendered.
return str;
});
HTMLElement.prototype.__defineSetter__("innerText", function(str) {
this.innerHTML = str.replace(/\n/g, "<br />");
});
}
//Style changes
/*jshint esnext:true*/
var style = document.createElement('style'); style.textContent = `
.comment-permalink { display: initial !important; }
textarea#comment { width: 98.5%; }
#sidebar-left { padding-right: 0px; }
.narrowcolumn { padding: 0; width: 510px; }
textarea { resize: vertical !important; }
`; document.head.appendChild(style);
window.addEventListener('DOMContentLoaded', function() {
//parse "override" option
if (ignoreList && ignoreList.split('||')[0] == "$override") {
chromeOverride = true;
ignoreList = ignoreList.split('||')[1];
}
//autoexpanding text box
var te = document.getElementById('comment');
if (!window.chrome || chromeOverride) {
te.style.display = 'none';
te.id = 'textcomment';
var ce = document.createElement('div');
ce.contentEditable = true;
ce.id = 'comment';
ce.innerText = te.value;
te.parentElement.insertBefore(ce, te);
ce.style.cssText = 'min-height: 5em; resize: vertical; overflow: auto; ';
ce.style.cssText += 'white-space: pre-wrap; word-wrap: break-word;';
var cf = document.getElementById('commentform');
cf.addEventListener('submit', function() {
document.getElementById('textcomment').value =
document.getElementById('comment').innerText;
return true;
});
//converting back to resizable if you manually resize it back
/*ce.addEventListener('click', function(){
console.log ('click event fired')
if (!ce.childNodes[0] || !ce.childNodes[0].innerText) {
var ceInnerText = ce.innerText;
ce.innerHTML = '<div> </div>';
ce.childNodes[0].innerText = ceInnerText;
}
var ceHeight = ce.style.height.split('px')[0] * 1 || 100000;
var ceMinHeight = getComputedStyle(ce).minHeight.split('px')[0] * 1;
var ceScrollHeight = ce.childNodes[0].scrollHeight;
if (Math.abs(ceHeight - ceScrollHeight) < 6 ||
(ceScrollHeight <= ceHeight && ceHeight <= ceMinHeight + 6)) {
ce.style.height = null;
console.log('ceHeight=' + ceHeight + ' ceMinHeight=' + ceMinHeight +
' ceScrollHeight=' + ceScrollHeight);
}
});/**/
//cf.action = 'http://www.htmlcodetutorial.com/cgi-bin/mycgi.pl';
} else { //fallback to large textbox for chrome while the expander is slow
te.style.height = document.documentElement.clientHeight - 32 + 'px';
}
//remove posts (and threads) from people on your ignore list
if (ignoreList) {
var cites = document.getElementsByTagName('cite');
for (var x = 0; x < cites.length; x++) {
if (cites[x].innerText.search(new RegExp('^' + ignoreList + '$', 'gi')) != -1) {
cites[x].parentNode.parentNode.parentNode.style.display = 'none';
}
}
}
});
/*IDEAS
//for Chrome workarounds (which I may never try)
For Chrome, use an iframe, and set iframe.contentWindow.document.body.innerHTML=cf.innerHTML
and bring over the CSS to style it. Have it take up the minimal amount of space at the start,
but, if someone clicks inside of it, then it resizes itself to take up one entire screen.
Or, a lesser solution, when you click inside the comment box, just resize it to be the screen
height, minus the space needed for the post button. Make the post button a fixed div that stays
at the bottom of the page as long as any element in the form is active.
//other
maybe add autosize button that will remove the user-defined size (and shrink or
grow the textarea on Chrome).
add another post button in chrome--one on top the textbox
see if there's a way to detect when the comment box is active, and hide the rightmost
column, allowing for a larger comment box.
Add a mazimize comments button, both at the top and above the comment box. It would
hide the other two columns and set the width of the middle column to auto.
'*/