-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhfr_citation_rap_mod_r21.user.js
More file actions
347 lines (336 loc) · 17 KB
/
Copy pathhfr_citation_rap_mod_r21.user.js
File metadata and controls
347 lines (336 loc) · 17 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// ==UserScript==
// @name [HFR] citation rapide mod_r21
// @version 2.0.5
// @namespace http://toyonos.info
// @description Rajoute le systeme de citation dans la zone de réponse rapide via un double clic sur les icônes correspondantes
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEX%2F%2F%2F8AAADxjxvylSrzmzf5wYLzmjb%2F9er%2F%2Fv70nj32q1b5woT70qT82rT827b%2F%2B%2FjxkSHykybykyfylCjylCnzmDDzmjX0nTv1o0b1qFH2qVL2qlT3tGn4tmz4uHD4uXL5vHf83Lf83Lj937394MH%2B587%2B69f%2F8%2BX%2F8%2Bf%2F9On%2F9uz%2F%2BPH%2F%2BvT%2F%2FPmRE1AgAAAAwElEQVR42s1SyRbCIAysA7W2tdZ93%2Ff1%2F39PEtqDEt6rXnQOEMhAMkmC4E9QY9j9da1OkP%2BtTiBo1caOjGisDLRDANCk%2FVIHwwkBZGReh9avnGj2%2FWFg%2Feg5hD1bLZTwqdgU%2FlTSdrqZJWN%2FKImPOnGjiBJKhYqMvikxtlhLNTuz%2FgkxjmJRRza5mbcXpbz4zldLJ0lVEBY5nRL4CJx%2FMEfXE4L9j4Qr%2BZakpiandMpX6FO7%2FaPxxUTJI%2FsJ4cd4AoSOBgZnPvgtAAAAAElFTkSuQmCC
// @include https://forum.hardware.fr/*
// @exclude https://forum.hardware.fr/message.php*
// @author toyonos
// @modifications correction d'un bug de compatibilité avec firefox depuis la version 8 (par fred82) et ajout du ctrl-clic sur le bouton quote simple
// @modtype correction de bug
// @updateURL https://raw.githubusercontent.com/roger21/hfr/master/hfr_citation_rap_mod_r21.user.js
// @installURL https://raw.githubusercontent.com/roger21/hfr/master/hfr_citation_rap_mod_r21.user.js
// @downloadURL https://raw.githubusercontent.com/roger21/hfr/master/hfr_citation_rap_mod_r21.user.js
// @supportURL https://forum.hardware.fr/hfr/Discussions/Viepratique/sujet_116015_1.htm
// @homepageURL http://roger21.free.fr/hfr/
// @noframes
// @grant GM_info
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_setValue
// @grant GM_getResourceText
// @grant GM_getResourceURL
// @grant GM_addStyle
// @grant GM_log
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// ==/UserScript==
// modifications roger21 $Rev: 1590 $
// historique :
// 2.0.5 (13/02/2020) :
// - utilisation d'une url en data pour l'icône du script et changement d'hébergeur (free.fr -> github.com)
// 2.0.4 (02/10/2019) :
// - suppression de la directive "@inject-into" (mauvaise solution, changer solution)
// 2.0.3 (18/09/2019) :
// - ajout de la directive "@inject-into content" pour isoler le script sous violentmonkey
// 2.0.2 (20/01/2018) :
// - correction d'un bug ch/tm et nettoyage des alertes de syntaxe de tm
// 2.0.1 (28/11/2017) :
// - passage au https
// 2.0.0 (07/08/2016) :
// - suppression de commetaires et de lignes vides
// - léger restylage de bouts de code
// - remplacement des ' par des " (pasque !)
// - reformatage du code (Online JavaScript beautifier : ->
// "2 spaces, unlimited newlines, do not wrap, braces with" et rien coché)
// - nouveau numéro de version : 0.1.4.7 -> 2.0.0
// - nouveau nom : [HFR] Citation dans la reponse rapide -> [HFR] citation rapide mod_r21
// 0.1.4.7 (24/07/2016) :
// - ajout de la gestion du ctrl-clic sur le bouton "quote simple" pour make install
// - modification de l'année dans les dates de l'historique : passage de 2 a 4 chiffres
// 0.1.4.6 (22/11/2015) :
// - suppression du module d'auto-update (code mort)
// 0.1.4.5 (07/03/2015) :
// - ajout de la metadata @noframes (interdit l'execution du script dans une frame pour plus de sécurité)
// 0.1.4.4 (04/04/2014) :
// - ajout de metadata pour la publication (@author, @modifications, @modtype)
// - ajout d'une icone au script
// - ajout des dates dans l'historique
// 0.1.4.3 (18/03/2014) :
// - maj des metadata @grant et indentation des metadata
// 0.1.4.2 (14/09/2012) :
// - ajout des metadata @grant
// 0.1.4.1 (28/11/2011) :
// - compatibilité avec firefox 8 : ajout des toString() sur les getSelection() (par fred82)
// - désactivation du message d'erreur XML dans la toyolib
// - ajout d'un .1 sur le numero de version
// - désactivation de l'auto-update pour conserver les modifs
var getElementByXpath = function(path, element) {
var arr = Array();
var xpr = document.evaluate(path, element, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var item = xpr.iterateNext();
while(item) {
arr.push(item);
item = xpr.iterateNext();
}
return arr;
};
RegExp.escape = function(text) {
if(!arguments.callee.sRE) {
var specials = ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\"];
arguments.callee.sRE = new RegExp("(\\" + specials.join("|\\") + ")", "g");
}
return text.replace(arguments.callee.sRE, "\\$1");
};
var trim = function(myString) {
return myString.replace(/^\s+/g, "").replace(/\s+$/g, "");
};
var root = document.getElementById("mesdiscussions");
var delay = 300;
getElementByXpath("//table//tr[starts-with(@class, \"message\")]//a[starts-with(@href, \"/message.php\" )]", root).filter(function(link) {
return link.firstChild.alt == "answer";
}).forEach(function(link) {
link.setAttribute("onclick", "return false;");
var timerQuote;
var firstClickQuoteTime = null;
link.addEventListener("click", function(event) {
if(firstClickQuoteTime !== null && new Date().getTime() - firstClickQuoteTime < delay) {
clearTimeout(timerQuote);
firstClickQuoteTime = null;
toyoAjaxLib.loadDoc(this.href, "get", null, function(pageContent) {
var quote = html_entity_decode(pageContent.match(/<textarea.*name="content_form".*>([^þ]*)<\/textarea>/).pop());
var selection = RegExp.escape(trim(document.getSelection().toString()));
var regexpExists = new RegExp(selection);
var regexpDebut = new RegExp("\\[quotemsg=[0-9]+,[0-9]+,[0-9]+\\]\\s*" + selection);
var regexpFin = new RegExp(selection + "\\s*\\[/quotemsg\\]");
if(document.getSelection().toString() && regexpExists.test(quote)) {
document.getElementById("content_form").value = quote.match(/\[quotemsg=[0-9]+,[0-9]+,[0-9]+\]/).pop();
if(!regexpDebut.test(quote)) document.getElementById("content_form").value += "[…] ";
document.getElementById("content_form").value += document.getSelection().toString();
if(!regexpFin.test(quote)) document.getElementById("content_form").value += " […]";
document.getElementById("content_form").value += "[/quotemsg]\n";
} else {
document.getElementById("content_form").value = quote;
}
document.getElementById("content_form").focus();
});
} else {
firstClickQuoteTime = new Date().getTime();
if(event.ctrlKey) {
timerQuote = setTimeout(GM_openInTab, delay, this.href);
} else {
timerQuote = setTimeout("document.location = '" + this.href + "';", delay);
}
}
}, false);
});
getElementByXpath("//table//tr[starts-with(@class, \"message\")]//a[starts-with(@href, \"/message.php\" )]", root).filter(function(link) {
return link.firstChild.alt == "answer +";
}).forEach(function(link) {
var saveOnClick = link.getAttribute("onclick").replace(/return false;/, "");
link.setAttribute("onclick", "return false;");
var timerMultiQuote;
var firstClickMultiQuoteTime = null;
link.addEventListener("click", function(event) {
if(firstClickMultiQuoteTime !== null && new Date().getTime() - firstClickMultiQuoteTime < delay) {
clearTimeout(timerMultiQuote);
firstClickMultiQuoteTime = null;
toyoAjaxLib.loadDoc(this.href, "get", null, function(pageContent) {
var quote = html_entity_decode(pageContent.match(/<textarea.*name="content_form".*>([^þ]*)<\/textarea>/).pop());
var selection = RegExp.escape(trim(document.getSelection().toString()));
var regexpExists = new RegExp(selection);
var regexpDebut = new RegExp("\\[quotemsg=[0-9]+,[0-9]+,[0-9]+\\]\\s*" + selection);
var regexpFin = new RegExp(selection + "\\s*\\[/quotemsg\\]");
if(document.getSelection().toString() && regexpExists.test(quote)) {
document.getElementById("content_form").value += quote.match(/\[quotemsg=[0-9]+,[0-9]+,[0-9]+\]/).pop();
if(!regexpDebut.test(quote)) document.getElementById("content_form").value += "[…] ";
document.getElementById("content_form").value += document.getSelection().toString();
if(!regexpFin.test(quote)) document.getElementById("content_form").value += " […]";
document.getElementById("content_form").value += "[/quotemsg]\n";
} else {
document.getElementById("content_form").value += quote;
}
});
} else {
firstClickMultiQuoteTime = new Date().getTime();
timerMultiQuote = setTimeout(saveOnClick, delay);
}
}, false);
});
var toyoAjaxLib = (function() {
function loadPage(url, method, t_arguments, responseHandler) {
var req;
method = method.toUpperCase();
if(method === "GET" && t_arguments !== null) url += "?" + t_arguments;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange(req, responseHandler);
req.open(method, url, true);
if(method == "POST") req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
t_arguments = method == "POST" ? t_arguments : null;
req.send(t_arguments);
} else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if(req) {
req.onreadystatechange = processReqChange(req, responseHandler);
req.open(method, url, true);
if(method == "POST") req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if(method == "POST") req.send(t_arguments);
else req.send();
}
}
}
function processReqChange(req, responseHandler) {
return function() {
try {
if(req.readyState == 4) {
if(req.status == 200) {
var content = req.responseXML !== null && req.responseXML.documentElement !== null ? req.responseXML.documentElement : req.responseText;
if(responseHandler !== null) responseHandler(content);
} else {
//alert("There was a problem retrieving the XML data:\n" +
//req.statusText);
}
}
} catch(e) {}
};
}
return {
"loadDoc": function(url, method, t_arguments, responseHandler) {
try {
loadPage(url, method, t_arguments, responseHandler);
} catch(e) {
var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
alert("Unable to get data:\n" + msg);
return;
}
}
};
})();
var html_entity_decode = function(texte) {
texte = texte.replace(/&#(\d+);/g, function() {
return String.fromCharCode(RegExp.$1);
});
texte = texte.replace(/"/g, "\""); // 34 22
texte = texte.replace(/&/g, "&"); // 38 26
texte = texte.replace(/'/g, "'"); // 39 27
texte = texte.replace(/</g, "<"); // 60 3C
texte = texte.replace(/>/g, ">"); // 62 3E
texte = texte.replace(/ˆ/g, "^"); // 94 5E
texte = texte.replace(/‘/g, "‘"); // 145 91
texte = texte.replace(/’/g, "’"); // 146 92
texte = texte.replace(/“/g, "“"); // 147 93
texte = texte.replace(/”/g, "”"); // 148 94
texte = texte.replace(/•/g, "•"); // 149 95
texte = texte.replace(/–/g, "–"); // 150 96
texte = texte.replace(/—/g, "—"); // 151 97
texte = texte.replace(/˜/g, "˜"); // 152 98
texte = texte.replace(/™/g, "™"); // 153 99
texte = texte.replace(/š/g, "š"); // 154 9A
texte = texte.replace(/›/g, "›"); // 155 9B
texte = texte.replace(/œ/g, "œ"); // 156 9C
texte = texte.replace(/ť/g, ""); // 157 9D
texte = texte.replace(/ž/g, "ž"); // 158 9E
texte = texte.replace(/Ÿ/g, "Ÿ"); // 159 9F
texte = texte.replace(/ /g, " "); // 160 A0
texte = texte.replace(/¡/g, "¡"); // 161 A1
texte = texte.replace(/¢/g, "¢"); // 162 A2
texte = texte.replace(/£/g, "£"); // 163 A3
texte = texte.replace(/¤/g, " "); // 164 A4
texte = texte.replace(/¥/g, "¥"); // 165 A5
texte = texte.replace(/¦/g, "¦"); // 166 A6
texte = texte.replace(/§/g, "§"); // 167 A7
texte = texte.replace(/¨/g, "¨"); // 168 A8
texte = texte.replace(/©/g, "©"); // 169 A9
texte = texte.replace(/ª/g, "ª"); // 170 AA
texte = texte.replace(/«/g, "«"); // 171 AB
texte = texte.replace(/¬/g, "¬"); // 172 AC
texte = texte.replace(/­/g, ""); // 173 AD
texte = texte.replace(/®/g, "®"); // 174 AE
texte = texte.replace(/¯/g, "¯"); // 175 AF
texte = texte.replace(/°/g, "°"); // 176 B0
texte = texte.replace(/±/g, "±"); // 177 B1
texte = texte.replace(/²/g, "²"); // 178 B2
texte = texte.replace(/³/g, "³"); // 179 B3
texte = texte.replace(/´/g, "´"); // 180 B4
texte = texte.replace(/µ/g, "µ"); // 181 B5
texte = texte.replace(/¶/g, "¶"); // 182 B6
texte = texte.replace(/·/g, "·"); // 183 B7
texte = texte.replace(/¸/g, "¸"); // 184 B8
texte = texte.replace(/¹/g, "¹"); // 185 B9
texte = texte.replace(/º/g, "º"); // 186 BA
texte = texte.replace(/»/g, "»"); // 187 BB
texte = texte.replace(/¼/g, "¼"); // 188 BC
texte = texte.replace(/½/g, "½"); // 189 BD
texte = texte.replace(/¾/g, "¾"); // 190 BE
texte = texte.replace(/¿/g, "¿"); // 191 BF
texte = texte.replace(/À/g, "À"); // 192 C0
texte = texte.replace(/Á/g, "Á"); // 193 C1
texte = texte.replace(/Â/g, "Â"); // 194 C2
texte = texte.replace(/Ã/g, "Ã"); // 195 C3
texte = texte.replace(/Ä/g, "Ä"); // 196 C4
texte = texte.replace(/Å/g, "Å"); // 197 C5
texte = texte.replace(/Æ/g, "Æ"); // 198 C6
texte = texte.replace(/Ç/g, "Ç"); // 199 C7
texte = texte.replace(/È/g, "È"); // 200 C8
texte = texte.replace(/É/g, "É"); // 201 C9
texte = texte.replace(/Ê/g, "Ê"); // 202 CA
texte = texte.replace(/Ë/g, "Ë"); // 203 CB
texte = texte.replace(/Ì/g, "Ì"); // 204 CC
texte = texte.replace(/Í/g, "Í"); // 205 CD
texte = texte.replace(/Î/g, "Î"); // 206 CE
texte = texte.replace(/Ï/g, "Ï"); // 207 CF
texte = texte.replace(/Ð/g, "Ð"); // 208 D0
texte = texte.replace(/Ñ/g, "Ñ"); // 209 D1
texte = texte.replace(/Ò/g, "Ò"); // 210 D2
texte = texte.replace(/Ó/g, "Ó"); // 211 D3
texte = texte.replace(/Ô/g, "Ô"); // 212 D4
texte = texte.replace(/Õ/g, "Õ"); // 213 D5
texte = texte.replace(/Ö/g, "Ö"); // 214 D6
texte = texte.replace(/×/g, "×"); // 215 D7
texte = texte.replace(/Ø/g, "Ø"); // 216 D8
texte = texte.replace(/Ù/g, "Ù"); // 217 D9
texte = texte.replace(/Ú/g, "Ú"); // 218 DA
texte = texte.replace(/Û/g, "Û"); // 219 DB
texte = texte.replace(/Ü/g, "Ü"); // 220 DC
texte = texte.replace(/Ý/g, "Ý"); // 221 DD
texte = texte.replace(/Þ/g, "Þ"); // 222 DE
texte = texte.replace(/ß/g, "ß"); // 223 DF
texte = texte.replace(/à/g, "à"); // 224 E0
texte = texte.replace(/á/g, "á"); // 225 E1
texte = texte.replace(/â/g, "â"); // 226 E2
texte = texte.replace(/ã/g, "ã"); // 227 E3
texte = texte.replace(/ä/g, "ä"); // 228 E4
texte = texte.replace(/å/g, "å"); // 229 E5
texte = texte.replace(/æ/g, "æ"); // 230 E6
texte = texte.replace(/ç/g, "ç"); // 231 E7
texte = texte.replace(/è/g, "è"); // 232 E8
texte = texte.replace(/é/g, "é"); // 233 E9
texte = texte.replace(/ê/g, "ê"); // 234 EA
texte = texte.replace(/ë/g, "ë"); // 235 EB
texte = texte.replace(/ì/g, "ì"); // 236 EC
texte = texte.replace(/í/g, "í"); // 237 ED
texte = texte.replace(/î/g, "î"); // 238 EE
texte = texte.replace(/ï/g, "ï"); // 239 EF
texte = texte.replace(/ð/g, "ð"); // 240 F0
texte = texte.replace(/ñ/g, "ñ"); // 241 F1
texte = texte.replace(/ò/g, "ò"); // 242 F2
texte = texte.replace(/ó/g, "ó"); // 243 F3
texte = texte.replace(/ô/g, "ô"); // 244 F4
texte = texte.replace(/õ/g, "õ"); // 245 F5
texte = texte.replace(/ö/g, "ö"); // 246 F6
texte = texte.replace(/÷/g, "÷"); // 247 F7
texte = texte.replace(/ø/g, "ø"); // 248 F8
texte = texte.replace(/ù/g, "ù"); // 249 F9
texte = texte.replace(/ú/g, "ú"); // 250 FA
texte = texte.replace(/û/g, "û"); // 251 FB
texte = texte.replace(/ü/g, "ü"); // 252 FC
texte = texte.replace(/ý/g, "ý"); // 253 FD
texte = texte.replace(/þ/g, "þ"); // 254 FE
texte = texte.replace(/ÿ/g, "ÿ"); // 255 FF
return texte;
};