· 9 years ago · Jan 03, 2017, 08:44 PM
1// ==UserScript==
2// @name Quick Rep
3// @author xadamxk
4// @namespace https://github.com/xadamxk/HF-Scripts
5// @version 2.0.7
6// @run-at document-start
7// @description Makes giving reputation on HF easier.
8// @require https://code.jquery.com/jquery-3.1.1.js
9// @match *://hackforums.net/showthread.php?tid=*
10// @match *://hackforums.net/private.php?action=read&pmid=*
11// @match *://hackforums.net/usercp.php
12// @copyright 2016+
13// @updateURL https://github.com/xadamxk/HF-Userscripts/raw/master/Quick%20Rep/Quick%20Rep.user.js
14// @downloadURL https://github.com/xadamxk/HF-Userscripts/raw/master/Quick%20Rep/Quick%20Rep.user.js
15// @iconURL https://raw.githubusercontent.com/xadamxk/HF-Userscripts/master/scripticon.jpg
16// ==/UserScript==
17// ------------------------------ Change Log ----------------------------
18// version 2.0.7: Bug fix: document-start
19// version 2.0.6: Fixed auto-update
20// version 2.0.5: Bug fix - fixed 2.0.1 hot fix - added method to get primaryUsergroup
21// version 2.0.4: Bug fix - Fixed logic behind finding recipient's UID and storing it.
22// version 2.0.3: Bug fix - Removing multiple reps from queue didn't work without reloading (hotfix) - reload page
23// version 2.0.2: Bug fix - adding rep via UserCP even if no reps to give
24// version 2.0.1: Bug fix - empty selection box when maxed reps for day (hot fix) - hardcode
25// - No default usergroup could be defined without access to give rep page.
26// version 2.0.0: Implemented Rep Queue
27// - Restructured code
28// - and more...
29// version 1.2.2: Some very small changes.
30// version 1.2.1: - Added logic for conflicting scripts - relating to default response on posts.
31// - Cleaned some code up
32// version 1.2.0: Added notifications support
33// version 1.1.3: Variable error fix, string changes, and bug fixes
34// version 1.1.2: Changed an error string
35// version 1.1.1: Added support for PM's - Yani
36// version 1.0.5: Added support for the classic userbit - Yani
37// version 1.0.4: Edited 1.0.3 change so canned comment was more neutral
38// version 1.0.3: Added default response if comment was empty - Mr Whiskey
39// version 1.0.2: Bug fix for min rep comment requirements
40// version 1.0.1: Bug fix for certain browsers
41// version 1.0.0: Initial Release
42// ------------------------------ Dev Notes -----------------------------
43// The bugs are almost dead
44// Figure out 2.0.3 hot fix - why $ event listener only triggers once?
45// ------------------------------ SETTINGS ------------------------------
46// Label for button (visible from /showthread.php?)
47var repButtonLabel = "Rep"; // Default: "Rep")
48// Enables/Disables basic form of quick rep
49// basicquickRep = true : Opens a new window for giving rep
50// Screenshot: https://github.com/xadamxk/HF-Userscripts/blob/master/Quick%20Rep/Capture02.png?raw=true
51// basicquickRep = false : Integrates rep menu into post bit
52// Screenshot: https://github.com/xadamxk/HF-Userscripts/blob/master/Quick%20Rep/Capture01.png?raw=true
53var basicQuickRep = false; // (Default: false)
54// Rep comment box width
55var repCommentWidth = "60%"; // (Default: "60%")
56// Notification Dismissal Time
57var notificationTimeout = 15000; // (Default: 15000)
58// Auto Trigger Rep Queue - otherwise only triggers when out of reps
59var queueRep = false; // (Default: false)
60// Debug: Show console.log statements for debugging purposes
61var debug = false; // (Default: false)
62// ------------------------------ ON PAGE LOAD ------------------------------
63// Global Vars
64var uidArray = [];
65var ajaxSuccess = false;
66var errorFound = false;
67var my_key, my_uid, my_pid, my_rid, my_repOptions, my_comments, repIndex;
68var repComment, repLink, recipientUsername, recipientUID;
69var queuedUID, queuedAmt, queuedReason;
70
71const repLimit = "You have already given as many reputation ratings as you are allowed to for today";
72const repSelf = "You cannot add to your own reputation";
73const repSelfResp = "You can't rep yourself dumb dumb :P";
74
75if (window.location.href.includes("hackforums.net/showthread.php?tid=") ||
76 window.location.href.includes("hackforums.net/private.php?action=read&pmid=")){
77 // Each post bit on page
78 $(".bitButton[title='Trust Scan']").each(function (index, element) {
79 var tsButton = $(element);
80 var postMessage = tsButton.parents("table.tborder");
81 // Grab UID & create button
82 uidArray[index] = parseInt(tsButton.attr("href").split("uid=")[1]);
83 tsButton.parent().append($("<a>").text(repButtonLabel).attr("id", "repButton"+index).attr("href", "#").addClass("bitButton"));
84 // Standard Quick Rep
85 if (basicQuickRep)
86 $("body").on("click", "#repButton"+index, function() {MyBB.reputation(uidArray[index]);});
87 // Integrated Quick Rep
88 else{
89 $("body").on("click", "#repButton"+index, function(e) {
90 e.preventDefault();
91 // ajax call on button click
92 $.ajax({
93 url: "https://hackforums.net/reputation.php?action=add&uid="+uidArray[index],
94 cache: false,
95 success: function(response) {
96 // Check for errors
97 // No errors
98 var errorBlock = $(response).find("blockquote").html();
99 var permError = "Permission Error: ";
100 if (errorBlock === undefined){
101 if (debug)
102 console.log("No permission errors!");
103 }
104 // Rep Limit
105 else if (errorBlock.includes(repLimit)){
106 // Rep Queue logic
107 my_key = $(response).find('[name=my_post_key]').val();
108 // UID
109 my_uid = $(response).find('[name=uid]').val();
110 // PID
111 my_pid = $(response).find('[name=pid]').val();
112 // RID
113 my_rid = $(response).find('[name=rid]').val();
114 // Select vals
115 my_repOptions = $(response).find('[name=reputation]').children();
116 // Comments
117 my_comments = $(response).find('[name=comments]').val();
118 queueRep = true;
119 }
120 // Self rep
121 else if (errorBlock.includes(repSelf)){
122 errorFound = true;
123 window.alert(permError + repSelfResp);
124 return;
125 }
126 // Require Upgrade, Rep Disabled, Other?
127 else {
128 errorFound = true;
129 window.alert(permError + errorBlock);
130 return;
131 }
132 // No Rep Permission Errors
133 if(!errorFound){
134 // Grab rep index
135 repIndex = $(response).find("#reputation :selected").index();
136 // Magical string of justice: $(response).children(3).children().children().children().children().siblings(6)
137 // Post Key
138 my_key = $(response).find('[name=my_post_key]').val();
139 // UID
140 my_uid = $(response).find('[name=uid]').val();
141 // PID
142 my_pid = $(response).find('[name=pid]').val();
143 // RID
144 my_rid = $(response).find('[name=rid]').val();
145 // Select vals
146 my_repOptions = $(response).find('[name=reputation]').children();
147 // Comments
148 my_comments = $(response).find('[name=comments]').val();
149 if (debug){
150 console.log("my_key: "+my_key);
151 console.log("my_uid: "+my_uid);
152 console.log("my_pid: "+my_pid);
153 console.log("my_rid: "+my_rid);
154 console.log("my_repOptions(below): "+my_repOptions);
155 console.log(my_repOptions);
156 console.log("my_comments: "+my_comments);
157 }
158 ajaxSuccess = true;
159 }
160 // Shouldn't run if error, but just incase...
161 if (!errorFound){
162 // Textbox doesn't exist yet
163 if ($(postMessage).find('[id=repComment'+index+']').length === 0){
164 // Append rep reasoning textbox
165 $(postMessage).find("#repButton"+index).after($("<input type='text'>").attr("id", "repComment"+index).val(my_comments)
166 .css("padding","3px 6px")
167 .css("text-shadow","1px 1px 0px #000;")
168 .css("background-color","#072948")
169 .css("margin-left", "5px")
170 .css("width", repCommentWidth)
171 .css("background", "white")
172 .css("box-shadow", "0 1px 0 0 #0F5799")
173 .css("font-family", "arial")
174 .css("font-size", "14px")
175 .css("border", "1px solid #000")
176 .css("margin", "5px")
177 .css("color", "black")
178 ); //.css("", "")
179 }
180 // Textbox already exists
181 else
182 $(postMessage).find("#repComment"+index).remove();
183
184 // Selectbox doesn't exist
185 if ($(postMessage).find('[id=repSelect'+index+']').length === 0){
186 // Append Rep selection
187 $(postMessage).find("#repComment"+index).after($("<select>").attr("id", "repSelect"+index).css("margin-right", "5px").addClass("button"));
188 // Out of reps - rep queue
189 if (queueRep){
190 // Append rep options based on primary usergroup
191 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1") === "")
192 getPrimaryUserGroup();
193 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1") == "Uber"){
194 $("#repSelect"+index).append( $('<option></option>').val(3).html("Positive(+3)"));
195 $("#repSelect"+index).append( $('<option></option>').val(2).html("Positive(+2)"));
196 $("#repSelect"+index).append( $('<option></option>').val(1).html("Positive(+1)"));
197 $("#repSelect"+index).append( $('<option></option>').val(0).html("Neutral"));
198 $("#repSelect"+index).append( $('<option></option>').val(-1).html("Negative(-1)"));
199 $("#repSelect"+index).append( $('<option></option>').val(-2).html("Negative(-2)"));
200 $("#repSelect"+index).append( $('<option></option>').val(-3).html("Negative(-3)"));
201 }
202 else if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1") == "Leet"){
203 $("#repSelect"+index).append( $('<option></option>').val(1).html("Positive(+1)"));
204 $("#repSelect"+index).append( $('<option></option>').val(0).html("Neutral"));
205 }
206 else if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1") == "Normal"){
207 window.alert("Permissions Error! Normal members do not have access to the reputation system!");
208 return;
209 }
210 }
211 // Have more available reps
212 else{
213 // Append rep options from give rep page
214 $(my_repOptions).each(function (subindex, subelement) {
215 $("#repSelect"+index).append( $('<option></option>').val($(subelement).val()).html($(subelement).text()));
216 });
217 // Set selected index
218 $("#repSelect"+index)[0].selectedIndex = repIndex;
219 }
220 }
221 // Selectbox already exists
222 else
223 $(postMessage).find("#repSelect"+index).remove();
224
225 // Post button doesn't exist
226 if ($(postMessage).find('[id=repPost'+index+']').length === 0){
227 // Append Rep User button
228 var repUserStr = "Rep User";
229 if (queueRep)
230 repUserStr = "Queue Rep";
231 $(postMessage).find("#repSelect"+index).after($("<button>").text(repUserStr).attr("id", "repPost"+index).addClass("button"));
232 // Click event for button
233 $("body").on("click", "#repPost"+index, function() {
234 // Check if PM or thread
235 var default_comment; // If rep comment is empty
236 var next_loc; // Address to load on success
237 recipientUsername = $(postMessage).find('.post_author strong .largetext a span').text();
238 recipientUID = $(postMessage).find('.post_author strong .largetext a').attr('href');
239 // Remove everything but digit
240 for (i=0; i < recipientUID.length; i++)
241 recipientUID = recipientUID.replace(/\D+/g, '');
242 if(window.location.pathname == '/private.php'){
243 next_loc = window.location.href;
244 default_comment = 'Regarding your PM.';
245 } else {
246 // Cycle through attributes, look for '#' in matching html (counters against other scripts)
247 for (i = 0; i < $(postMessage).find(".smalltext strong a").length; i++){
248 if($(postMessage).find(".smalltext strong a")[i].text.includes("#"))
249 next_loc = "https://hackforums.net/"+$(postMessage).find(".smalltext strong a:eq("+i+")").attr('href');
250 }
251 default_comment = "Regarding Thread: " + next_loc;
252 }
253 var queueString;
254 // Rep comment is empty - use appropriate default
255 if ($("#repComment"+index).val().length === 0){
256 // Queue Rep - Default
257 if (queueRep){
258 // Queue string
259 queueString = recipientUID+"||"+recipientUsername+"||"+$("#repSelect"+index).val()+"||"+default_comment+"|||";
260 // Make cookie if doesn't already exist
261 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") === undefined)
262 document.cookie = 'RepQueueCookie=';
263 // Add queueString to cookie
264 document.cookie = 'RepQueueCookie=' + document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") + queueString;
265 // Notification
266 repComment = $("#repSelect"+index+" option:selected").text() + "\nRep Reasoning: "+ default_comment;
267 notififyMe("Rep Queued!",repComment, next_loc);
268 }
269 else{
270 // Make $.Post Request
271 giveRep(index, next_loc, $("#repSelect"+index+" option:selected").text(), $("#repSelect"+index+" option:selected").val(), default_comment);
272 }
273 // Remove rep elements
274 hideRepElements(postMessage,index);
275 }
276 // Custom comment but too short
277 else if ($("#repComment"+index).val().length < 11 && $("#repComment"+index).val().length > 0)
278 window.alert("Rep comments must be atleast 10 chars.");
279
280 // Input over 10 chars
281 else{
282 // Queue Rep - Custom
283 if (queueRep){
284 var newComment = $("#repComment"+index).val();
285 // If rep reasoning contains '|' seperator, remove all
286 newComment = $("#repComment"+index).val();
287 do{newComment = newComment.replace('|','');}
288 while (newComment.includes('|'));
289 // Queue string
290 queueString = recipientUID+"||"+recipientUsername+"||"+$("#repSelect"+index).val()+"||"+newComment+"|||";
291 // Make cookie if doesn't already exist
292 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") === undefined)
293 document.cookie = 'RepQueueCookie=';
294 // Add queueString to cookie
295 document.cookie = 'RepQueueCookie=' + document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") + queueString;
296 // Notification
297 repComment = $("#repSelect"+index+" option:selected").text() + "\nRep Reasoning: "+ $("#repComment"+index).val();
298 notififyMe("Rep Queued!",repComment, next_loc);
299 }
300 else{
301 // Make $.Post Request
302 giveRep(index, next_loc,$("#repSelect"+index+" option:selected").text() ,$("#repSelect"+index+" option:selected").val(), $("#repComment"+index).val());
303 }
304 // Remove rep elements
305 hideRepElements(postMessage,index);
306 }
307 });
308 }
309 // Post button already exists
310 else
311 $(postMessage).find("#repPost"+index).remove();
312 } // no errors
313 }// success
314 }); // ajax
315 }); // Rep Button onClick
316 } // else
317 }); // each post
318} // url is thread or pm
319// UserCP
320else{
321 // Build rep queue table
322 buildQueueTable();
323 // Update primary usergroup
324 getPrimaryUserGroup();
325}
326
327// remove entry from cookie
328function removeEntry(queueIndex){
329 // Queued array
330 var queuedRep = document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1").split('|||');
331 // Precaution incase they delete cookie - should never run
332 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") === undefined)
333 window.alert("No reps queued.");
334
335 var newQueueString = "";
336 // Loop each queued rep from cookie
337 for (i = 0; i < queuedRep.length-1;i++){
338 // Don't add selected index
339 if(i != queueIndex){
340 newQueueString = newQueueString + queuedRep[i] + "|||";
341 }
342 }
343 // Add queueString back to cookie
344 document.cookie = 'RepQueueCookie=' + newQueueString;
345 location.reload();
346 // Remove Entry
347 //$("#repQueueTable").remove();
348 // Rebuild table
349 //buildQueueTable();
350}
351
352function buildQueueTable(){
353 // IP Table
354 var ipTable = $("strong:contains('IP Login History')").parent().parent().parent().parent();
355 // Insert table w/tbody before IP Table
356 ipTable.before(($("<table>").attr('id', 'repQueueTable').attr('border', 0).attr('cellspacing', 1)
357 .attr('cellpadding',4).attr('colspan',6).addClass('tborder')).append('<tbody>').attr('colspan',6));
358 // Insert thead (title, thread hyperlink)
359 $('#repQueueTable').append($('<tr>').append($('<td>').addClass('thead').attr('colspan',6).append($('<strong>').text('Rep Queue'))
360 .append($('<a>').attr('href','https://hackforums.net/showthread.php?tid=5498344')
361 .append($('<strong>').text('Quick Rep Userscript').addClass('float_right')))));
362 // Spacing after table
363 $('#repQueueTable').after($('<br>'));
364 // Precaution incase they delete cookie
365 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1") === undefined)
366 document.cookie = 'RepQueueCookie=';
367 // Array of queue'd reps
368 var queuedRep = document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueCookie\s*\=\s*([^;]*).*$)|^.*$/, "$1").split('|||');
369 var infoString = queuedRep.length > 1 ? "These are the reps you have queued ("+(queuedRep.length-1)+")." : "No reps queued.";
370 // Info row
371 $('#repQueueTable').append($('<tr>').append($('<td>').attr('colspan',6).addClass('tcat smalltext').append(infoString)));
372 // Header row
373 $('#repQueueTable').append($('<tr>')
374 .append($('<td>').append($('<strong>').text('User').addClass('smalltext')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','125'))
375 .append($('<td>').append($('<strong>').text('Amount').addClass('smalltext')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','75'))
376 .append($('<td>').append($('<strong>').text('Reasoning').addClass('smalltext')).addClass('tcat').attr('colspan',2).attr('align','center'))
377 .append($('<td>').append($('<strong>').text('Submit').addClass('smalltext')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','100'))
378 .append($('<td>').append($('<strong>').text('Remove').addClass('smalltext')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','100'))
379 );
380 // Add cookie values
381 queuedUID = new Array(queuedRep.length);
382 queuedAmt = new Array(queuedRep.length);
383 queuedReason = new Array(queuedRep.length);
384 for (i = 0; i < queuedRep.length-1; i++){
385 queuedUID[i] = queuedRep[i].split('||')[0];
386 queuedAmt[i] = queuedRep[i].split('||')[2];
387 queuedReason[i] = queuedRep[i].split('||')[3];
388 // Each queue'd rep (snippet above basically)
389 $('#repQueueTable').append($('<tr>')
390 .append($('<td>').addClass('tcat').attr('colspan',1).attr('align','center').attr('width','125').append($('<a>').text(queuedRep[i].split('||')[1]).attr("href","/member.php?action=profile&uid="+queuedRep[i].split('||')[0])))
391 .append($('<td>').append(queuedRep[i].split('||')[2]).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','75'))
392 .append($('<td>').append(queuedRep[i].split('||')[3]).addClass('tcat').attr('colspan',2).attr('align','left'))
393 .append($('<td>').append($('<button>').addClass('button').val(i).text('Rep').addClass('repQueueAdd')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','100'))
394 .append($('<td>').append($('<button>').addClass('button').val(i).text('Remove').addClass('repQueueRemove')).addClass('tcat').attr('colspan',1).attr('align','center').attr('width','100'))
395 );
396 }
397}
398
399// $.Post Reputation call
400function giveRep(index, loc, selectTxt, selectVal, reason){
401 //window.alert(loc +','+selectTxt+','+selectVal+','+reason);
402 $.post("/reputation.php",
403 {
404 "my_post_key": my_key,
405 "action" : "do_add",
406 "uid": my_uid,
407 "pid": my_pid,
408 "rid": my_rid,
409 "reputation": selectVal,
410 "comments": reason
411 },
412 function(data,status){
413 // Success prompt- notification
414 repComment = selectTxt + "\nRep Reasoning: "+ reason;
415 notififyMe("Rep Added Successfully!",repComment, loc);
416 });
417}
418
419// Hide elements
420function hideRepElements(element,index){
421 $(element).find("#repComment"+index).remove();
422 $(element).find("#repSelect"+index).remove();
423 $(element).find("#repPost"+index).remove();
424}
425
426// Notifications
427function notififyMe(repTitle, repComment, repLink){
428 if (Notification.permission !== "granted"){
429 Notification.requestPermission().then(function() {
430 if (Notification.permission !== "granted"){
431 window.alert("Quick Rep Userscript: Please allow desktop notifications!");
432 } else{
433 notififyMe(repComment, repLink);
434 }
435 });
436 }
437 else {
438 var notification = new Notification(repTitle, {
439 icon: 'https://raw.githubusercontent.com/xadamxk/HF-Userscripts/master/Quick%20Rep/NotificationIcon.png',
440 body: repComment,
441 });
442
443 notification.onclick = function () {
444 window.location.href = repLink;
445 notification.close();
446 };
447 setTimeout(function() { notification.close(); }, notificationTimeout);
448 }
449}
450// Event listener for submit
451$("button.repQueueAdd").click(function(){
452 submitRepQuest($(this).val());
453});
454
455// Event listener for remove
456$("button.repQueueRemove").click(function(){
457 var confirm = window.confirm('Are you sure you want to remove this queued rep?');
458 if (confirm)
459 removeEntry($(this).val());
460});
461
462// Add button on UserCP
463function submitRepQuest(index){
464 $.ajax({
465 url: "https://hackforums.net/reputation.php?action=add&uid="+queuedUID[index].toString(),
466 cache: false,
467 success: function(response) {
468 // Post Key
469 my_key = $(response).find('[name=my_post_key]').val();
470 // UID
471 my_uid = $(response).find('[name=uid]').val();
472 // PID
473 my_pid = $(response).find('[name=pid]').val();
474 // RID
475 my_rid = $(response).find('[name=rid]').val();
476 // Check for errors
477 // No errors
478 var errorBlock = $(response).find("blockquote").html();
479 var permError = "Permission Error: ";
480 if (errorBlock === undefined){
481 if (debug)
482 console.log("No permission errors!");
483 }
484 // Rep Limit
485 else if (errorBlock.includes(repLimit)){
486 errorFound = true;
487 window.alert(permError+repLimit);
488 }
489 // Self rep
490 else if (errorBlock.includes(repSelf)){
491 window.alert(permError + repSelfResp);
492 }
493 // Require Upgrade, Rep Disabled, Other?
494 else {
495 errorFound = true;
496 window.alert(permError + errorBlock);
497 }
498 // No errors
499 if (!errorFound){
500 // Rep label logic
501 var queuedAmtStr = "";
502 if (queuedAmt[index].includes('-'))
503 queuedAmtStr = "Negative ("+queuedAmt[index]+")";
504 else if (queuedAmt[index] == "0")
505 queuedAmtStr = "Neutral (0)";
506 else
507 queuedAmtStr = "Positive (+"+queuedAmt[index]+")";
508 // Submit Rep
509 giveRep(index, "https://hackforums.net/usercp.php", queuedAmtStr, queuedAmt[index], queuedReason[index]);
510 // Remove element from cookie
511 removeEntry(index);
512 }
513 }
514 });// Ajax
515}
516
517// Update primary usergroup
518function getPrimaryUserGroup(){
519 var primaryUserGroupStr = "Primary User Group:";
520 var primaryUserGroupParent;
521 if (window.location.href.includes("/usercp.php")){
522 primaryUserGroupParent = $("strong:contains('Primary User Group')").parent().text();
523 }
524 else{
525 $.ajax({
526 url: "https://hackforums.net/usercp.php",
527 cache: false,
528 async: false,
529 success: function(response) {
530 primaryUserGroupParent = $(response).find("strong:contains('Primary User Group')").parent().text();
531 }
532 });
533 }
534 // String we want from UserCP
535 var desiredString = primaryUserGroupParent.substr(primaryUserGroupParent.indexOf(primaryUserGroupStr) + primaryUserGroupStr.length);
536 // Create if it doesn't exist
537 if (document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1") === undefined)
538 document.cookie = 'RepQueueUsergroup=';
539 // Ub3r
540 if (desiredString.includes("HF Ub3r"))
541 document.cookie = 'RepQueueUsergroup=' + "Uber";
542 // L33t
543 else if (desiredString.includes("HF l33t"))
544 document.cookie = 'RepQueueUsergroup=' + "Leet";
545 // Everything else
546 else
547 document.cookie = 'RepQueueCookie=' + "Normal";
548 // Debug default usergroup
549 if (debug){console.log("Default usergroup: "+document.cookie.replace(/(?:(?:^|.*;\s*)RepQueueUsergroup\s*\=\s*([^;]*).*$)|^.*$/, "$1"));}
550}