-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCS.RIN.RU Enhanced.user.js
More file actions
1527 lines (1379 loc) · 70.1 KB
/
Copy pathCS.RIN.RU Enhanced.user.js
File metadata and controls
1527 lines (1379 loc) · 70.1 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-env jquery */
// ==UserScript==
// @name CS.RIN.RU Enhanced
// @name:fr CS.RIN.RU Amélioré
// @name:pt CS.RIN.RU Melhorado
// @namespace Royalgamer06
// @version 1.2.3
// @description Enhance your experience at CS.RIN.RU - Steam Underground Community.
// @description:fr Améliorez votre expérience sur CS.RIN.RU - Steam Underground Community.
// @description:pt Melhorar a sua experiência no CS.RIN.RU - Steam Underground Community.
// @author Royalgamer06 (modified by SubZeroPL)
// @match *://cs.rin.ru/forum/*
// @match *://csrinrutkb3tshptdctl5lyei4et35itl22qvk5ktdcat6aeavy6nhid.onion/forum/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @icon https://i.ibb.co/p1k6cq6/image.png
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_notification
// @grant GM_addElement
// @run-at document-idle
// @homepageURL https://github.com/SubZeroPL/cs-rin-ru-enhanced-mod
// @supportURL https://cs.rin.ru/forum/viewtopic.php?f=14&t=75717
// @updateURL https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/cs-rin-ru-enhanced-mod.user.js
// @downloadURL https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/cs-rin-ru-enhanced-mod.user.js
// ==/UserScript==
/*
Creator: Royalgamer06 (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=477885)
Contributor: SubZeroPL (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=505897) who has now taken over the project
Contributor: Redpoint (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=1365721) has created some functionality
Contributor: Altansar (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=1280185) has created some functionality
Contributor: odusi (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=582752) has created the original function for the special search. We have kindly given his permission to use his work
Contributor: Mandus (https://cs.rin.ru/forum/memberlist.php?mode=viewprofile&u=1487447) has created the original function to copy the link from a message
*/
const BRANCH = "master"
const CONFIG_PAGE_CSS = `https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/${BRANCH}/config.css`;
const CONFIG_PAGE_JS = `https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/${BRANCH}/config.js`;
const CONFIG_PAGE = `https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/${BRANCH}/config.html`
const AJAX_LOADER = `
<div style="margin-left: 50%;">
<img
id="ajaxload"
src="https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/loading.gif"
style="opacity: 0.5; position: fixed; width: 40px; height: 40px; z-index: 2147483647; display: none;" alt="Loading"/>
</div>`;
const FORUM_NAME = 'CS.RIN.RU - Steam Underground Community';
const navBarSize = "1.0em";
function getBaseUrl() {
let path = window.location.origin + window.location.pathname;
let base = path.slice(0, path.lastIndexOf('/') + 1);
return base ?? 'https://cs.rin.ru/forum/';
}
const FORUM_BASE_URL = getBaseUrl();
//Contains the list of friends
const FRIENDS_LIST = [];
const CONNECTED = document.querySelector("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(2)").lastElementChild.getAttribute("href").match("mode=login") == null
const USERNAME = $("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(2) > a:nth-child(2)")[0].textContent.slice(10, -2);
// Declare a promise to wait for the variable to be updated
let updatePromise = null;
//Retrieve friends list
async function retrievesFriendsLists() {
// Checks if the promise is already being executed
if (!updatePromise) {
// Create a new promise
updatePromise = new Promise(async (resolve, reject) => {
// Check if the friends list has already been updated
if (FRIENDS_LIST.length === 0) {
try {
// Performs the query to retrieve the list of friends
const response = await fetch(FORUM_BASE_URL + "ucp.php?i=zebra&mode=friends");
const text = await response.text();
// Parse the answer to extract the list of friends
let parser = new DOMParser();
let doc = parser.parseFromString(text, "text/html");
const friendsListContainer = doc.querySelector('#ucp > table > tbody > tr:nth-child(3) > td.row2 > select');
if (friendsListContainer) {
FRIENDS_LIST.push(...Array.from(friendsListContainer.children, node => node.innerText));
}
// Solve the promise
resolve();
} catch (error) {
// Reject the promise in case of error
reject(error);
}
} else {
// Resolves the promise if the list has already been updated
resolve();
}
});
}
// Waits for variable update
await updatePromise;
}
/*
Configuration array with default values.
*/
let specialSearchParameters = {
"searchTermsSpecificity": "any",
"searchSubforums": true,
"sortResultsBy": "t",
"sortOrderBy": "d",
"searchTopicLocation": "titleonly",
"showResultsAsPosts": false,
"limitToPrevious": 0,
"returnFirst": "300",
"showFriends": true
};
let options = {
"script_enabled": true,
"infinite_scrolling": true,
"mentioning": 1, //0=nothing, 1=the author, 2=author and the post
"steam_db_link": true,
"copy_link_button": true,
"dynamic_function": true,
"add_profile_button": true,
"colorize_new_messages": true,
"colorize_the_page": true,
"display_ajax_loader": true,
"custom_tags": true,
"add_small_shoutbox": true,
"add_users_tag": true,
"show_all_spoilers": false,
"add_link_quote": true,
"quick_reply": true,
"collapse_quotes": false,
"colorize_friends_me": 3, // 0=nothing, 1=your in red, 2=your friends in pink, 3=both
"change_topic_link": 0, // 0 = first post, 1 = unread post, 2 = last post
"topic_preview": false,
"topic_preview_option": 0, // 0 = first post, 1 = unread post, 2 = last post
"topic_preview_timeout": 5, // in seconds
"post_preview": false,
"profile_preview": false,
"special_search": true,
"special_search_parameter": specialSearchParameters,
"hide_scs": 0, // 0=not hide, 1=hide all, 2=hide only green, 3=show only red
"apply_in_scs": false,
"title_format": "%C %S - %T" // %C: CS.RIN.RU - Steam Underground Community •, %S: Section title (e.g. View topic), %T: Page title, %RT Page title without tags
};
/*
Color used in this script
*/
let color = {
"color_of_friends": '#f4169b', "color_of_me": '#ff4c4c'
};
/*
Functions that need to be connected must be added here and you must also add the need-connected="true" tag to them.
*/
function loadConfig() {
const savedOptions = GM_getValue("options", options);
options = {...options, ...savedOptions};
if (!CONNECTED) {
options.dynamic_function = false;
options.add_profile_button = false;
options.colorize_new_messages = false;
options.add_small_shoutbox = false;
options.colorize_friends_me = 0;
options.add_link_quote = false;
specialSearchParameters.showFriends = false;
}
}
loadConfig();
window.addEventListener("message", receiveConfigMessage, false);
function receiveConfigMessage(event) {
if (!event.data) return;
if (event.data.script_enabled === undefined) return;
options = event.data;
GM_setValue("options", options);
GM_notification("Configuration saved", "Info");
}
function loadConfigButton() {
GM_xmlhttpRequest({ // JS of config file
url: CONFIG_PAGE_JS, onerror: (r) => {
console.log("Error loading config page script: " + r);
GM_notification("Error loading config page script: " + r, "Error");
}, onload: (r) => {
const script = document.createElement('script');
script.textContent = r.responseText;
$("body").append(script);
}
});
GM_xmlhttpRequest({ // CSS of config file
url: CONFIG_PAGE_CSS, onerror: (r) => {
console.log("Error loading config page script: " + r);
GM_notification("Error loading config page script: " + r, "Error");
}, onload: (r) => {
const script = document.createElement('style');
script.textContent = r.responseText;
$("body").append(script);
}
});
GM_xmlhttpRequest({ // HTML of config file
url: CONFIG_PAGE, onerror: (r) => {
console.log("Error loading config page: " + r);
GM_notification("Error loading config page: " + r, "Error");
}, onload: (r) => {
$("body").append(r.responseText);
$("input#script_enabled")[0].checked = options.script_enabled;
$("input#infinite_scrolling")[0].checked = options.infinite_scrolling;
$("select#mentioning")[0].options.selectedIndex = options.mentioning;
$("input#steam_db_link")[0].checked = options.steam_db_link;
$("input#copy_link_button")[0].checked = options.copy_link_button;
$("input#dynamic_function")[0].checked = options.dynamic_function;
$("select#colorize_friends_me")[0].options.selectedIndex = options.colorize_friends_me;
$("input#add_profile_button")[0].checked = options.add_profile_button;
$("input#colorize_new_messages")[0].checked = options.colorize_new_messages;
$("input#colorize_the_page")[0].checked = options.colorize_the_page;
$("input#display_ajax_loader")[0].checked = options.display_ajax_loader;
$("input#custom_tags")[0].checked = options.custom_tags;
$("input#add_small_shoutbox")[0].checked = options.add_small_shoutbox;
$("input#add_users_tag")[0].checked = options.add_users_tag;
$("input#show_all_spoilers")[0].checked = options.show_all_spoilers;
$("input#add_link_quote")[0].checked = options.add_link_quote;
$("input#quick_reply")[0].checked = options.quick_reply;
$("input#collapse_quotes")[0].checked = options.collapse_quotes;
$("select#hide_scs")[0].options.selectedIndex = options.hide_scs;
$("input#apply_in_scs")[0].checked = options.apply_in_scs;
$("input#title_format")[0].value = options.title_format;
$("input#topic_preview")[0].checked = options.topic_preview;
$("select#topic_preview_option")[0].options.selectedIndex = options.topic_preview_option;
$("input#topic_preview_timeout")[0].value = options.topic_preview_timeout;
$("input#post_preview")[0].checked = options.post_preview;
$("input#profile_preview")[0].checked = options.profile_preview;
$("input#special_search")[0].checked = options.special_search;
$("select#change_topic_link")[0].options.selectedIndex = options.change_topic_link;
const specialSearchParametersJSON = options.special_search_parameter;
$("select#searchTermsSpecificity")[0].value = specialSearchParametersJSON.searchTermsSpecificity;
$("input#searchSubforums")[0].checked = specialSearchParametersJSON.searchSubforums;
$("select#searchTopicLocation")[0].value = specialSearchParametersJSON.searchTopicLocation;
$("select#sortResultsBy")[0].value = specialSearchParametersJSON.sortResultsBy;
$("select#sortOrderBy")[0].value = specialSearchParametersJSON.sortOrderBy;
$("input#showResultsAsPosts")[0].checked = specialSearchParametersJSON.showResultsAsPosts;
$("input#limitToPrevious")[0].value = specialSearchParametersJSON.limitToPrevious;
$("input#returnFirst")[0].value = specialSearchParametersJSON.returnFirst;
$("input#showFriends")[0].checked = specialSearchParametersJSON.showFriends;
if (!options.script_enabled) {
$("fieldset#config").hide();
}
}
});
}
loadConfigButton();
if (!options.script_enabled) return;
// Quick reply panel
const quickReplyPanel = document.getElementById("postform");
// Navigation bar
let navBar = $("[title='Click to jump to page…']").parent().parent().first()[0]; // Gets the first navigation bar
if (navBar) {
const div = document.createElement("div"); // Necessary for search.php
div.setAttribute("class", "gensmall"); // Necessary for search.php
div.setAttribute("name", "page_nav"); // Makes it easier for the GM_addStyle function
div.setAttribute("width", "500"); // Standardised width
div.innerHTML = navBar.innerHTML; // Copy the navigation bar
navBar.parentNode.replaceChild(div, navBar); // Replace the existing navigation bar with the modified one
const ancestor = $(div).closest("#pagecontent, #pageheader"); // #pagecontent for viewforum.php, #pageheader for viewtopic.php
if (ancestor.length) {
$("#pagecontent").before(div);
} else {
$("[method='post']:not(#search)").get(0).before(div); // For search.php, memberlist.php
}
let bgColour = getComputedStyle(document.querySelector("body")).getPropertyValue("background-color");
let matches = bgColour.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
const bgRgb = [parseInt(matches[1]), parseInt(matches[2]), parseInt(matches[3])]
let colour = bgRgb[0] + bgRgb[1] + bgRgb[2] > 600 ? "white" : "black";
GM_addStyle(`[name="page_nav"] {
position: sticky !important;
top: 0px;
width: 500px;
background: linear-gradient(90deg, ${colour} 90%, transparent 95%);
}`);
}
if (options.display_ajax_loader) {
$("body").prepend(AJAX_LOADER);
$.ajaxSetup({
async: true, beforeSend: function () {
if ($("#ajaxload")) $("#ajaxload").show();
}, complete: function () {
if ($("#ajaxload")) $("#ajaxload").hide();
}
});
}
/*
Originally made by RoyalGamer06
Infinite scroll in both directions made by Redpoint
Reply button added by Altansar
INFINITE SCROLLING
*/
if (options.infinite_scrolling && $("[title='Click to jump to page…']").length > 0) {
const styleElement = document.querySelector("style");
styleElement.textContent = "[name=\"page_nav\"] {font-size:" + navBarSize + ";}" //Increase size of the nav bar
const selectors = ["#pagecontent > table.tablebg > tbody > tr:has(.row4 > img:not([src*=global], [src*=announce], [src*=sticky]))", // viewforum.php
"#wrapcentre > form > table.tablebg > tbody > tr[valign='middle']", // search.php
"#pagecontent > .tablebg:not(:has(tbody > tr > .cat))", // viewtopic.php
"#wrapcentre > form > table.tablebg > tbody > tr:not(:has(.cat)):not(:first)", // search.php (user messages) and memberlist.php
"#pagecontent > form > table.tablebg > tbody > tr:not(:first)" // inbox
];
const selector = selectors.find(select => $(select).length !== 0);
let ajaxDone = true;
const navElem = $("[title='Click to jump to page…']").first().parent();
const initialPageElem = $(navElem).find("strong");
let scrollLength = 0; // How long the user has scrolled when at the top of the page
const scrollThreshold = 1000; // Approximately 10 clicks of the scroll wheel
let navElems = {}; // Dictionary for storing nav bar elements for each page (page number: {Html: HTML of that page's nav element})
navElems[$(navElem).find("strong").text()] = {Html: navElem.html()}; // Add the current nav element to the dictionary
if (URLContains("viewtopic.php")) {
if (initialPageElem.next().next().length !== 0) { // If we're not on the last page
$("[title='Subscribe topic']").first().parents().eq(7).after($(".cat:has(.btnlite)").first().parent().parent().parent());
$("[title='Reply to topic']").last().parents().eq(4).remove();
}
} else if (!URLContains("ucp.php")) {
$(selector).parent().prepend($(".cat:has(.btnlite)").parent());
}
$(selector).attr("page_number", $(navElem).find("strong").text()); // Add page number attribute to initial posts on the page
function infiniteScroll(e) {
// Update nav element
const posts = [...$(selector)]; // Get all posts on page
const topElement = posts.find(post => window.getComputedStyle(post).display !== "none" && post.getBoundingClientRect().top >= 0); // Get the first element at the top of the screen that is not hidden
let currentPageNumber = $(navElem).find("strong").text(); // Get the bolded number in the nav bar
if (topElement) {
currentPageNumber = $(topElement).attr("page_number"); // Get page number of the top element
$(navElem).html(navElems[currentPageNumber].Html); // Replace the nav element with the one stored in the dictionary
// Update number next to "post reply" button in topics
if (URLContains("viewtopic.php")) {
const pageIndicator = document.getElementsByClassName("nav")[0];
pageIndicator.querySelector("strong:nth-child(1)").innerHTML = `${currentPageNumber}`;
}
}
// Min and max page numbers that have already been visited
const navElemsKeys = Object.keys(navElems).map(Number);
let earliestPageNumber = Math.min(...navElemsKeys).toString();
let latestPageNumber = Math.max(...navElemsKeys).toString();
// Backward scroll
if ((window.scrollY || window.document.documentElement.scrollTop) === 0 && e.deltaY < 0) {
scrollLength += Math.abs(e.deltaY);
if (scrollLength >= scrollThreshold && currentPageNumber === earliestPageNumber && ajaxDone) {
ajaxDone = false;
let previousPageElem = $(navElem).find(`:contains('${earliestPageNumber}')`).first().prev().prev(); // Find the previous page
let previousPageLink = $(previousPageElem).attr("href"); // Get the link to the page
// If there is no suitable link then stop
if (!previousPageLink) {
ajaxDone = true;
return;
}
$.get(previousPageLink, function (data) {
let currentPage = $(selector); // Posts on current page
$($(selector)[0]).before($(selector, data).attr("page_number", $(previousPageElem).text())); // Add the new content to the front as well as page number
$(currentPage[0]).find("tbody:first").find("tr:first").remove(); // Remove element from current page - this element will be added back with the new content
let scrollPosition = $(currentPage[0]).offset().top + $(currentPage[0]).height() - $(window).height();
$("html, body").animate({scrollTop: scrollPosition}, 0); // Move to new content
const prevNavElemHTML = $("[title='Click to jump to page…']", data).first().parent().html();
navElems[$(previousPageElem).text()] = {Html: prevNavElemHTML};
functionsCalledByInfiniteScrolls(data); // Run functions
earliestPageNumber = $($.parseHTML(prevNavElemHTML)).find("strong").text();
ajaxDone = true;
});
scrollLength = 0; // Reset scrollLength
}
} else {
scrollLength = 0; // Reset scrollLength if not actively trying to go to previous page
}
// Forward scroll
if (window.innerHeight + window.scrollY + 1500 >= document.body.scrollHeight && currentPageNumber === latestPageNumber && ajaxDone) {
ajaxDone = false;
let nextPageElem = $(navElem).find(`:contains('${latestPageNumber}')`).next().next(); // Find the next page
let nextPageLink = $(nextPageElem).attr("href"); // Get the link to the page
// If there is no suitable link then stop
if (!nextPageLink) {
if (!document.querySelector("#pagecontent > table:last-child > tbody > tr > td > a > img") && !URLContains("ucp.php")) {
const originalElement = document.querySelector("#pagecontent > table:nth-child(1)");
const copiedElement = originalElement.cloneNode(true);
document.querySelector("#pagecontent").appendChild(copiedElement);
//Retrieve the correct nav
const element = document.getElementsByClassName("nav")[3];
// Replace the first number with the second in the HTML code
element.querySelector('strong:nth-child(1)').innerHTML = element.querySelector('strong:nth-child(2)').textContent;
}
ajaxDone = true;
return;
}
$.get(nextPageLink, function (data) {
let newPage = $(selector, data).attr("page_number", $(nextPageElem).text()); // Selected next page content
$(newPage[0]).find("tbody:first").find("tr:first").remove(); // Remove element from the new content
$(selector).last().after(newPage) // Add the new page content to the end
const nextNavElemHTML = $("[title='Click to jump to page…']", data).first().parent().html(); // Get the nav bar of the new page
navElems[$(nextPageElem).text()] = {Html: nextNavElemHTML}; // Store it for use when the user scrolls over the new content
functionsCalledByInfiniteScrolls(data); // Run functions
if ($($.parseHTML(nextNavElemHTML)).find("strong").text()) {
latestPageNumber = ($.parseHTML(nextNavElemHTML)).find("strong").text(); // Update position
}
ajaxDone = true;
});
}
}
window.addEventListener("wheel", infiniteScroll);
window.addEventListener("scroll", infiniteScroll);
}
function functionsCalledByInfiniteScrolls(data) {
dynamicFunction(data);
mentionify();
quotify();
tagify();
hideScs();
setupTopicPreview();
setupPostPreview();
setupProfilePreview();
addLink();
steamDBLink();
addUsersTag();
changeTopicLink();
colorizeFriendsMe();
showAllSpoilers();
collapseQuotes();
}
// CUSTOM TAGS
tagify();
hideScs();
// MENTIONING
if (URLContains("posting.php" && "do=mention") && options.mentioning) {
const p = URLParam("p");
const u = URLParam("u");
const a = URLParam("a");
let postBody = `@[url=${FORUM_BASE_URL}memberlist.php?mode=viewprofile&u=${u}]${decodeURI(a)}[/url], `;
if (options.mentioning === 2) { //Author and post
postBody += `Re: [url=${FORUM_BASE_URL}viewtopic.php?p=${p}#p${p}]Post[/url]. `;
}
$("[name=message]").val(postBody);
}
mentionify();
/*
Originally made by RoyalGamer06.
Changes made by Altansar to avoid ban ip
*/
let intervalID;
function allDynamicFunction() {
if (options.dynamic_function) { //If dynamic function is active
// set up event listener for visibility change
document.addEventListener("visibilitychange", function () {
if (document.visibilityState === "visible") { //If the page becomes visible
dynamicFunction();
startUpdating();
} else { //If the page is not visible
clearInterval(intervalID); //We stop the counter for the update
}
});
// run on initial pageload
if (document.visibilityState === "visible") { //If the page is visible
startUpdating();
}
}
}
allDynamicFunction();
function startUpdating() {
intervalID = setInterval(function () {
dynamicFunction();
}, 60000);
}
function dynamicFunction(data) {
if (data == null) {
$.get(location.href, function (data) { //Every 60 seconds we update time and user list
dynamicFunction(data);
});
}
//Call every 60seconds as well as when using infinite scroll
$("#datebar .gensmall+ .gensmall").html($("#datebar .gensmall+ .gensmall", data).html()); //Time
$("#wrapcentre > .tablebg").last().html($("#wrapcentre > .tablebg", data).last().html()); //Users
const html = $("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(1) > a:nth-child(2)", data).html();
if ($(html)[0].src.endsWith("theme/images/icon_mini_message.gif")) {
$("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(1) > a:nth-child(" + (2 + options.add_profile_button) + ")").html(html) // Message
}
changeColorOfNewMessage();//Colorize messages
colorizeFriendsMe();
if (URLContains("viewtopic.php")) { //Dynamics posts
/*
var actualPostsOnThePage = $("#pagecontent > .tablebg:not(:first, :last)").length;
var postsOnThePageAfterActualisation = $("#pagecontent > .tablebg:not(:first, :last)", data).length;
var differenceBetweenBoth=postsOnThePageAfterActualisation-actualPostsOnThePage;
//W.I.P
*/
//I don't know what I tried to do, but I don't think it's a good solution.
}
}
// FUNCTIONS
function mentionify() {
if ($(".postbody").length > 0 && URLContains("viewtopic.php") && options.mentioning >= 1 && document.querySelector('a[href^="./posting.php?mode=reply"] img')) {
if (!document.querySelector('a[href^="./posting.php?mode=reply"] img').alt.includes('locked')) {
const replyLink = $("[title='Reply to topic']").parent().attr("href");
$(".gensmall div+ div:not(:has([title='Reply with mentioning']))").each(function () {
const postElem = $(this).parents().eq(7);
const postID = $(postElem).find("a[name]").last().attr("name").slice(1);
const author = $(postElem).find(".postauthor").text();
const authorID = $(postElem).find("[title=Profile]").parent().attr("href").split("u=")[1];
if (!quickReplyPanel) {
$(this).append(`<a href='${replyLink}&do=mention&p=${postID}&u=${authorID}&a=${encodeURIComponent(author)}'>
<img src="https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/mention-image.png"
alt='Reply with mentioning' title='Reply with mentioning'>
</a>`);
} else {
$(this).append(`<a href='javascript:void(0);'>
<img src="https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/mention-image.png"
alt='Reply with mentioning' title='Reply with mentioning'>
</a>`);
const child = $(this).find("[title='Reply with mentioning']");
$(this).find('[title="Reply with mentioning"]').on("click", function () {
let postBody = `@[url=${FORUM_BASE_URL}memberlist.php?mode=viewprofile&u=${authorID}]${decodeURI(author)}[/url], `;
if (options.mentioning === 2) { //Author and post
postBody += `Re: [url=${FORUM_BASE_URL}viewtopic.php?p=${postID}#p${postID}]Post[/url]. `;
}
$("[name=message]")[0].value += postBody;
const mentioned = $('<span class="mentioned">Mentioned!</span>');
mentioned.css({
'position': 'absolute',
'top': child.offset().top - mentioned.outerHeight() - 20,
'left': child.offset().left + (child.outerWidth() / 2) - (mentioned.outerWidth() / 2) - 12
});
$('body').append(mentioned);
setTimeout(function () {
mentioned.fadeOut();
}, 2000);
});
}
});
}
}
}
function tagify() {
if (options.custom_tags) {
$(".titles, .topictitle").each(function () {
const titleElem = this;
const parentElem = titleElem.parentElement
if (titleElem.id !== "colorize") {
titleElem.id = "colorize";
const tags = $(titleElem).text().match(/\[([^\]]+)]/g);
if (tags) {
tags.forEach(function (tag) {
const color = colorize(tag, parentElem);
titleElem.innerHTML = titleElem.innerHTML.replace(tag, "<span style='color:" + color + ";'>[</span><span style='color:" + color + ";font-size: 0.9em;'>" + tag.replace(/[\[\]]/g, "") + "</span><span style='color:" + color + ";'>]</span>");
});
}
}
});
}
}
// 0=not hide, 1=hide all, 2=hide only green, 3=show only red
function hideScs() {
if (options.hide_scs > 0 && (options.apply_in_scs || $("a.titles").html() !== "Steam Content Sharing")) {
let regex;
switch (options.hide_scs) {
case 1:
regex = /topic_tags\/scs_/;
break;
case 2:
regex = /topic_tags\/scs_on/;
break;
case 3:
regex = /topic_tags\/scs_[oy][^f]/;
break;
}
$(".topictitle img").each(function () {
if (this.src.match(regex)) {
this.parentElement.parentElement.parentElement.style.display = "none";
}
});
}
}
function hexToRgb(hex) {
const r = parseInt(hex.substring(0, 2), 16);
const g = parseInt(hex.substring(2, 4), 16);
const b = parseInt(hex.substring(4, 6), 16);
return [r, g, b];
}
function colorize(str, parentElem) {
let lstr = str.toLowerCase();
let hash = 0;
for (let i = 0; i < lstr.length; i++) {
hash = lstr.charCodeAt(i) + ((hash << 5) - hash);
}
let color = Math.floor(Math.abs((Math.sin(hash) * 10000) % 1 * 16777216)).toString(16);
let rgb = hexToRgb(color);
while (!getComputedStyle(parentElem).getPropertyValue("background-color").match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)) {
parentElem = parentElem.parentElement
}
let bgColour = getComputedStyle(parentElem).getPropertyValue("background-color");
let matches = bgColour.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
const bgRgb = [parseInt(matches[1]), parseInt(matches[2]), parseInt(matches[3])]
while (Math.abs(rgb[0] + rgb[1] + rgb[2] - (bgRgb[0] + bgRgb[1] + bgRgb[2])) < 300) {
hash = (hash << 5) - hash;
color = Math.floor(Math.abs((Math.sin(hash) * 10000) % 1 * 16777216)).toString(16);
rgb = hexToRgb(color);
}
return '#' + color.padStart(6, '0');
}
function URLContains(match) {
return window.location.href.indexOf(match) > -1;
}
function URLParam(name) {
return (location.search.split(name + '=')[1] || '').split('&')[0];
}
/*
Made by SubZeroPL
%RT added by Altansar
Remade to apply to all pages by Redpoint
*/
function setupPageTitle() {
const currentTitle = document.title;
const cs = currentTitle.split("•")[0] + " •";
const remainder = currentTitle.substring(currentTitle.indexOf("•") + 1);
const fullTitle = remainder.split(/[-•]/);
let sectionTitle;
let pageTitle;
if (fullTitle.length === 1) {
sectionTitle = "";
pageTitle = $("a.titles").length > 0 ? $("a.titles").text() : fullTitle[0].trim();
} else {
sectionTitle = fullTitle[0].trim();
pageTitle = $("a.titles").length > 0 ? $("a.titles").text() : fullTitle[1].trim();
}
const pageTitleWithoutTags = pageTitle.replace(/\[[^\]]*]/g, '');
document.title = options.title_format
.replace("%C", cs)
.replace("%S", sectionTitle)
.replace("%T", pageTitle)
.replace("%RT", pageTitleWithoutTags);
}
setupPageTitle();
/*
Made by SubZeroPL
displays preview of first post from topic that mouse cursor points
*/
/*
* Displays a preview of the post.
* @param {HTMLElement} element - The element to attach the hover event listener to.
* @param {string} link - The link to the topic to be previewed.
* @param {function} getIndex - A predefined function that returns the correct index of the post given a list of posts.
* These are defined `setup{Type}Preview()` functions.
*/
function previewElement(element, link, getIndex) {
let tid, showPreview;
$(element).off("mouseover").on("mouseover", () => {
showPreview = true;
$("div#topic_preview").hide();
tid = setTimeout(() => {
if (!showPreview) return;
const previewWidth = window.innerWidth * 0.75;
const previewHeight = window.innerHeight * 0.75;
const x = (window.innerWidth / 2) - (previewWidth / 2);
const y = (window.innerHeight / 2) - (previewHeight / 2) + window.scrollY;
GM_xmlhttpRequest({
url: link, onerror: (r) => {
console.log("Error loading page: " + r);
}, onload: (r) => {
if (!showPreview) return;
const parser = new DOMParser();
const dom = parser.parseFromString(r.responseText, "text/html").body.children;
const posts = $(dom).find("div#pagecontent table.tablebg");
const body = posts[getIndex(posts, link)].outerHTML;
// Use custom parseHTML function instead of $.parseHTML
const bodyObj = parser.parseFromString(body, "text/html").body.children[0];
if ($("div#topic_preview").length > 0) {
const tip = $("div#topic_preview");
tip.html(bodyObj);
tip.css('left', `${x}px`);
tip.css('top', `${y}px`);
tip.css('width', `${previewWidth}px`);
tip.css('height', `${previewHeight}px`);
tip.show();
tip.scrollTop(0);
} else {
const tip = document.createElement('div');
tip.id = "topic_preview";
tip.appendChild(bodyObj);
tip.style.position = "absolute";
tip.style.top = `${y}px`;
tip.style.left = `${x}px`;
tip.style.width = `${previewWidth}px`;
tip.style.maxWidth = `${previewWidth}px`;
tip.style.height = `${previewHeight}px`;
tip.style.maxHeight = `${previewHeight}px`;
tip.style.overflow = "auto";
$("body").append(tip);
$(tip).on("mouseleave", () => {
$(tip).hide();
clearTimeout(tid);
});
}
addUsersTag();
steamDBLink();
}
});
}, options.topic_preview_timeout * 1000);
});
$(element).off("mouseleave").on("mouseleave", () => {
clearTimeout(tid);
showPreview = false;
});
}
function setupTopicPreview() {
if (!options.topic_preview) return;
$("a.topictitle").each((_, e) => {
const topic = $(e)[0];
const topicLink = topic.href.split("&view=unread")[0].split("&p=")[0];
let link = options.topic_preview_option === 0 ? topicLink :
options.topic_preview_option === 1 ? topicLink + "&view=unread#unread" :
options.topic_preview_option === 2 ? $(topic).parent().next().next().next().next().children().next().children().next().attr("href") :
'Invalid option';
const getIndex = () => options.topic_preview_option === 2 ? posts.length - 2 : 1;
previewElement(topic, link, getIndex);
});
}
setupTopicPreview();
function setupPostPreview() {
if (!options.post_preview) return;
$("a.postlink-local").each((_, e) => {
const post = $(e)[0]
const link = post.href;
if (!link.includes("viewtopic.php")) return;
const getIndex = (posts, link) => {
for (let i = 0; i < posts.length; i++) {
const postLink = $(posts[i]).find("a[href*='viewtopic.php']:not([class])")[0]
if (postLink.href === link) {
return i;
}
}
return -1;
}
previewElement(post, link, getIndex)
});
}
setupPostPreview()
function setupProfilePreview() {
if (!options.profile_preview) return;
$("a.postlink-local").each((_, e) => {
const profile = $(e)[0]
const link = profile.href;
if (!link.includes("memberlist.php")) return;
const getIndex = () => 0;
previewElement(profile, link, getIndex)
});
}
setupProfilePreview()
/*
Made by Redpoint
And adapted for cs.rin.ru enhanced by Altansar
*/
function addUsersTag() {
if (options.add_users_tag) {
const steamLink = $('a[href^="https://store.steampowered.com/app/"], a[href^="http://store.steampowered.com/app/"]').first()[0];
if (steamLink != null) {
const genreDescription = $(":contains('Genre(s):')").filter((i, e) => $(e).text() === "Genre(s):");
if (genreDescription.length > 0 && genreDescription.next().next().text() !== "User-defined Tag(s): ") { // If we are on the game presentation page
// Get the link to the Steam game page
const link = steamLink.href;
// Send a request to the Steam game page and bypass CSP
GM_xmlhttpRequest({
method: "GET", url: link, onload: function (response) {
// Parse the response as HTML
const parser = new DOMParser();
const doc = parser.parseFromString(response.responseText, "text/html");
// Get the genre tags from the response
const tags = doc.querySelectorAll("#glanceCtnResponsiveRight > div.glance_tags_ctn.popular_tags_ctn > div.glance_tags.popular_tags > a.app_tag");
// Extract the text content of each tag and join them with a comma and a space
const genres = Array.from(tags).map(tag => tag.textContent.trim()).join(", ");
if (genreDescription.next().next().text() === "User-defined Tag(s): ") {
return;
}
// Modify the original page by adding a new line with the genres
const br = $('span[style="font-weight: bold"]:contains("Genre(s):")').next()[0];
const span = document.createElement("span");
span.style.fontWeight = "bold";
span.textContent = "User-defined Tag(s): ";
const text = document.createTextNode(genres);
br.parentNode.insertBefore(document.createElement("br"), br);
br.parentNode.insertBefore(span, br);
br.parentNode.insertBefore(text, br);
}
});
}
}
}
}
addUsersTag()
/*
Originally made by Altansar
Completely remade by Redpoint
*/
function steamDBLink() {
if (!options.steam_db_link || this.value === "Show") {
return;
}
let postlinks = $(".postlink");
if (postlinks.length === 0) {
return;
}
for (let i = 0; i < postlinks.length; i++) {
let steamLink = postlinks[i].href;
if (steamLink.match("://store.steampowered.com/app")) {
let slash = steamLink.endsWith('/');
steamLink = slash ? steamLink.slice(0, -1) : steamLink;
let splits = steamLink.split("/");
if (splits[splits.length - 1].match(/^[0-9]+$/)) {
steamLink = splits[splits.length - 1];
} else if (splits[splits.length - 2].match(/^[0-9]+$/)) {
steamLink = splits[splits.length - 2];
}
let DBlink = `https://steamdb.info/app/${steamLink}${slash ? '/' : ''}`;
let j = i;
while ((j + 1 < postlinks.length) && (postlinks[j].getBoundingClientRect().y === postlinks[j + 1].getBoundingClientRect().y) && (postlinks[j].nextSibling !== null && postlinks[j].nextSibling.tagName !== "BR")) {
j++;
}
if ((j + 1 === postlinks.length) || !postlinks[j + 1].text.match(DBlink)) {
postlinks[j].insertAdjacentHTML("afterend", "<a href=" + DBlink + " class=\"postlink\" rel=\"nofollow\">" + DBlink + "</a>"); // Write the link (right part)
postlinks[j].insertAdjacentHTML("afterend", "<br><span style=\"font-weight: bold\"> <svg version=\"1.1\" width=\"1.3em\" height=\"1.3em\" viewBox=\"0 0 128 128\" fill=#bbbbbb class=\"octicon octicon-steamdb\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M63.9 0C30.5 0 3.1 11.9.1 27.1l35.6 6.7c2.9-.9 6.2-1.3 9.6-1.3l16.7-10c-.2-2.5 1.3-5.1 4.7-7.2 4.8-3.1 12.3-4.8 19.9-4.8 5.2-.1 10.5.7 15 2.2 11.2 3.8 13.7 11.1 5.7 16.3-5.1 3.3-13.3 5-21.4 4.8l-22 7.9c-.2 1.6-1.3 3.1-3.4 4.5-5.9 3.8-17.4 4.7-25.6 1.9-3.6-1.2-6-3-7-4.8L2.5 38.4c2.3 3.6 6 6.9 10.8 9.8C5 53 0 59 0 65.5c0 6.4 4.8 12.3 12.9 17.1C4.8 87.3 0 93.2 0 99.6 0 115.3 28.6 128 64 128c35.3 0 64-12.7 64-28.4 0-6.4-4.8-12.3-12.9-17 8.1-4.8 12.9-10.7 12.9-17.1 0-6.5-5-12.6-13.4-17.4 8.3-5.1 13.3-11.4 13.3-18.2 0-16.5-28.7-29.9-64-29.9zm22.8 14.2c-5.2.1-10.2 1.2-13.4 3.3-5.5 3.6-3.8 8.5 3.8 11.1 7.6 2.6 18.1 1.8 23.6-1.8s3.8-8.5-3.8-11c-3.1-1-6.7-1.5-10.2-1.5zm.3 1.7c7.4 0 13.3 2.8 13.3 6.2 0 3.4-5.9 6.2-13.3 6.2s-13.3-2.8-13.3-6.2c0-3.4 5.9-6.2 13.3-6.2zM45.3 34.4c-1.6.1-3.1.2-4.6.4l9.1 1.7a10.8 5 0 1 1-8.1 9.3l-8.9-1.7c1 .9 2.4 1.7 4.3 2.4 6.4 2.2 15.4 1.5 20-1.5s3.2-7.2-3.2-9.3c-2.6-.9-5.7-1.3-8.6-1.3zM109 51v9.3c0 11-20.2 19.9-45 19.9-24.9 0-45-8.9-45-19.9v-9.2c11.5 5.3 27.4 8.6 44.9 8.6 17.6 0 33.6-3.3 45.2-8.7zm0 34.6v8.8c0 11-20.2 19.9-45 19.9-24.9 0-45-8.9-45-19.9v-8.8c11.6 5.1 27.4 8.2 45 8.2s33.5-3.1 45-8.2z\"></path></svg> SteamDB:</span> "); // Write left part
}
}
}
}
steamDBLink();
/*
Originally made by mandus
Modified and adapted for cs.rin.ru enhanced by Altansar based on mandus and Royalgamer06 code
*/
function addLink() {
if ($(".postbody").length > 0 && URLContains("viewtopic.php") && options.copy_link_button) {
// const replyLink = $("[title='Reply to topic']").parent().attr("href");
$(".gensmall div+ div:not(:has([title='Copy the link into the clipboard']))").each(function () {
const postElem = $(this).parents().eq(7);
const postId = $(postElem).find("a[name]").attr("name").slice(1);
$(this).append(`<a href='javascript:void(0);'>
<img src="https://raw.githubusercontent.com/SubZeroPL/cs-rin-ru-enhanced-mod/master/link-image.png"
alt='Copy the link into the clipboard' title='Copy the link into the clipboard'>
<a>`);
const bar = this;
$(this).find('[title="Copy the link into the clipboard"]').on("click", function () {
const url = FORUM_BASE_URL + `viewtopic.php?p=${postId}#p${postId}`;
navigator.clipboard.writeText(url);
const copied = $('<span class="copied">Copied!</span>');
const child = $(bar).find("[title='Copy the link into the clipboard']");
copied.css({
'position': 'absolute',
'top': child.offset().top - copied.outerHeight() - 20,
'left': child.offset().left + (child.outerWidth() / 2) - (copied.outerWidth() / 2) - 12
});
$('body').append(copied);
setTimeout(function () {
copied.fadeOut();
}, 2000);
});
});
}
}
addLink();
/*
Originally made by Redpoint
And adapted for cs.rin.ru enhanced by Altansar
*/
function AddShoutbox() {
if (options.add_small_shoutbox && !URLContains("chat.php")) {
// Create a button to show/hide chat
let button = document.createElement("button");
button.innerHTML = "Show Chat";
//button.style.cssText = "position: fixed; bottom: 0%; right: 0%; width: 5%; height: 3%;";
button.style.cssText = "position: fixed; bottom: 0%; right: 0%; min-height: 40px; min-width: 50px; width: 5%; height: 3%; z-index: 9999;";
button.addEventListener("click", function () {
if (document.getElementById("chatDiv") === null) {
button.innerHTML = "Hide Chat";
createChatContainer();
fetchChat();
GM_setValue("chatActive", true)
} else {
document.getElementById("chatDiv").remove();
button.innerHTML = "Show Chat";
GM_setValue("chatActive", false)
}
});
document.addEventListener("visibilitychange", () => {
if (document.getElementById("chatDiv") !== null) {
const script = document.getElementById("chatDiv").children[1];
if (document.hidden) {
script.setAttribute("data-original-text", script.textContent);
script.textContent = "";
} else {
script.textContent = script.getAttribute("data-original-text");
script.removeAttribute('data-original-text');
}
}
});
document.body.appendChild(button);
const isChatActive = GM_getValue("chatActive", false);
if (isChatActive) { //open the chat if it was open when last used
button.click();
}
}
}
AddShoutbox();
/*
Made by Altansar
*/
function createChatContainer() {
// Create a container for the chat
let chatContainer = document.createElement("div");
chatContainer.style.cssText = "position: fixed; bottom: 0%; right: 0%; width: 25%; min-width: 425px; height: 70%; overflow-y: scroll; background-color:#1c1c1c; border:0.5em solid black";
chatContainer.id = "chatDiv";
document.body.appendChild(chatContainer);
//Loading text
const loading = document.createTextNode("Loading...");
const p = document.createElement("p");
p.appendChild(loading);
chatContainer.appendChild(p);
p.style.cssText = "position: absolute; left: 0; right: 0; top: 20%; transform: translateY(-50%); text-align: center; color: white; font-size: 500%;";