-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
165 lines (148 loc) · 5.99 KB
/
config.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
/* eslint-env jquery */
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();
const RELOAD = 0;
const WARNING = 1;
const CONNECTED = document.querySelector("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(2) > a:nth-child(2)").text !== ' Login';
const WARNING_MSG = `
You need to be <a href='${FORUM_BASE_URL}ucp.php?mode=login' target='blank' class='forum_link'>logged in to the forum</a> to use the greyed-out functions.<br>
If you don't have an account yet, you need to <a href='${FORUM_BASE_URL}ucp.php?mode=register' target='blank' class='forum_link'>register</a>.
`;
/*
will match one and only one of the string 'true','1', or 'on' regardless
of capitalization and regardless off surrounding white-space.
*/
function strToBool(s) {
let regex = /^\s*(true|1|on)\s*$/i;
return regex.test(s);
}
function showMessage(id, text) {
const container = $("#messages")[0];
if ($(`div#msg${id}`).length === 0) {
const msg = document.createElement('div');
msg.id = `msg${id}`;
msg.className = 'message';
$(msg).html(text);
container.appendChild(msg);
}
$(container).show();
}
function hideMessage(id) {
$(`div#msg${id}`).remove();
if ($(".message").length === 0) {
$("#messages").hide();
}
}
function showConfigPage() {
$("#configButton").hide();
$("#wholeWindow").show();
$("[data-originalValue]").each((i, e) => {
switch (e.type) {
case 'checkbox':
e.setAttribute("data-originalValue", e.checked);
break;
case 'select-one':
case 'text':
case 'number':
e.setAttribute("data-originalValue", e.value);
break;
}
});
if (!CONNECTED) {
document.querySelectorAll('[need-connected="true"]').forEach(checkbox => {
checkbox.disabled = true;
});
showMessage(WARNING, WARNING_MSG)
}
$("[data-originalValue]").change((e) => {
let changed = false;
$("[data-originalValue]").each((i, e) => {
switch (e.type) {
case 'checkbox':
changed = changed || (e.checked !== strToBool(e.getAttribute("data-originalValue")));
break;
case 'select-one':
case 'text':
case 'number':
changed = changed || (e.value !== e.getAttribute("data-originalValue"));
break;
}
});
if (changed) {
// Display a warning if something changed in configuration
showMessage(RELOAD, "Clicking OK will reload current page");
} else {
hideMessage(RELOAD);
}
});
}
function sendConfig() {
if ($("#messages").is(":visible")) {
const special_search = {
"searchTermsSpecificity": $("#searchTermsSpecificity")[0].value,
"searchSubforums": $("#searchSubforums")[0].checked,
"sortResultsBy": $("#sortResultsBy")[0].value,
"sortOrderBy": $("#sortOrderBy")[0].value,
"searchTopicLocation": $("#searchTopicLocation")[0].value,
"showResultsAsPosts": $("#showResultsAsPosts")[0].checked,
"limitToPrevious": Number($("#limitToPrevious")[0].value),
"returnFirst": Number($("#returnFirst")[0].value),
"showFriends": $("#showFriends")[0].checked
};
const data = {
"script_enabled": $("#script_enabled")[0].checked,
"infinite_scrolling": $("#infinite_scrolling")[0].checked,
"mentioning": Number($("#mentioning")[0].value),
"steam_db_link": $("#steam_db_link")[0].checked,
"copy_link_button": $("#copy_link_button")[0].checked,
"dynamic_function": $("#dynamic_function")[0].checked,
"add_profile_button": $("#add_profile_button")[0].checked,
"colorize_new_messages": $("#colorize_new_messages")[0].checked,
"colorize_the_page": $("#colorize_the_page")[0].checked,
"display_ajax_loader": $("#display_ajax_loader")[0].checked,
"custom_tags": $("#custom_tags")[0].checked,
"add_link_quote": $("#add_link_quote")[0].checked,
"add_small_shoutbox": $("#add_small_shoutbox")[0].checked,
"add_users_tag": $("#add_users_tag")[0].checked,
"show_all_spoilers": $("#show_all_spoilers")[0].checked,
"quick_reply": $("#quick_reply")[0].checked,
"collapse_quotes": $("#collapse_quotes")[0].checked,
"colorize_friends_me": Number($("#colorize_friends_me")[0].value),
"change_topic_link": Number($("#change_topic_link")[0].value),
"topic_preview": $("#topic_preview")[0].checked,
"topic_preview_option": Number($("#topic_preview_option")[0].value),
"topic_preview_timeout": Number($("#topic_preview_timeout")[0].value),
"post_preview": $("#post_preview")[0].checked,
"profile_preview": $("#profile_preview")[0].checked,
"special_search": $("#special_search")[0].checked,
"special_search_parameter": special_search,
"hide_scs": Number($("#hide_scs")[0].value),
"apply_in_scs": $("#apply_in_scs")[0].checked,
"title_format": $("#title_format")[0].value
};
window.postMessage(data, "/");
window.location.reload();
}
configWindowClose();
}
function configWindowClose() {
$("#wholeWindow").hide();
$("#configButton").show();
}
function enableScript() {
if ($("input#script_enabled")[0].checked) {
$("fieldset#config").fadeIn();
} else {
$("fieldset#config").fadeOut();
}
}
function openForum() {
window.open("https://cs.rin.ru/forum/viewtopic.php?f=14&t=75717", "blank");
}
function toggleParams() {
$('#params').toggle();
}