generic-skin 3.0.7 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,864 +1,862 @@
1
1
  const FNR = {
2
- execFn: (callback) => {
3
- document.addEventListener('forumReady', callback, false);
4
- },
5
- forum: {
6
- getColors: () => {
7
- return Object.values(forumColours)
8
- .map((item) => {
9
- return {
10
- name: item.code,
11
- hex: item.hex
12
- }
13
- });
14
- },
15
- getTopics: (array, limit) => {
16
- return new Promise((resolve, reject) => {
17
- const addContent = (elmt) => {
18
- const titleElmnt = $(elmt).find('.topictitle');
19
- const dateElmnt = $(elmt).children().last();
20
-
21
- finalArray.push({
22
- name: titleElmnt.text().trim(),
23
- url: Vue.filter('url-to-normal')(titleElmnt.attr('href')),
24
- lastpost: {
25
- url: Vue.filter('url-to-normal')(dateElmnt.children().last().attr('href')),
26
- date: dateElmnt.text().split('por')[0].trim(),
27
- who: {
28
- name: dateElmnt.find('strong a').length ? dateElmnt.find('strong a').text().trim() : 'Invitado',
29
- url: Vue.filter('url-to-normal')(dateElmnt.find('strong a').length ? dateElmnt.find('strong a').attr('href') : '/'),
30
- color: dateElmnt.find('strong a').length ? dateElmnt.find('strong a span').attr('style').split('color:')[1] : 'initial',
31
- },
32
- },
33
- forum: {
34
- name: $(elmt).find('.row2 + .row2:not(.centered) a').text().trim(),
35
- url: Vue.filter('url-to-normal')($(elmt).find('.row2 + .row2:not(.centered) a').attr('href')),
36
- },
37
- });
38
- };
39
-
40
- const getPage = (url) => {
41
- $.get(url, (data) => {
42
- $(data).find('.ipbform').find('tbody').find('tr').each(function() {
43
- if (finalArray.length < limit && array.indexOf(parseInt($(this).find('.row2 + .row2:not(.centered) a').attr('href').split('/f')[1].split('-')[0])) === -1) {
44
- addContent(this);
45
- }
46
- });
47
-
48
- if (finalArray.length === limit || !$(data).find('.pagination')[0].children.length || $(data).find('.pagination').children().last()[0].localName === 'b') {
49
- resolve(finalArray);
50
- } else {
51
- getPage($(data).find('.pagination').children().last().attr('href'));
52
- }
53
- });
54
- };
55
-
56
- let finalArray = [];
57
-
58
- getPage('/latest?change_version=invision');
59
- });
60
- },
61
- getMembers: (option) => {
62
- return new Promise((resolve, reject) => {
63
- let members = [];
64
-
65
- const getUserData = (user, color) => {
66
- return {
67
- user: $(user).find('.membername span').text().trim(),
68
- id: $(user).find('.popupmenu .popupmenu-item a').attr('href').split('?')[0],
69
- img: $(user).find('.mini-avatar img').attr('src'),
70
- color: color
71
- };
72
- };
73
-
74
- const getUsersPage = (page) => {
75
- let users = [];
76
-
77
- $(page).find('.member-list .member').each(function() {
78
- const group = FNR.utility.getGroup($(this).find('.membername span').attr('style').split('color:')[1]);
79
-
80
- if (option) {
81
- users.push(getUserData(this, group));
82
- } else {
83
- if (group !== 'unknown' && group !== forumConfig.skinOptions.adminGroup) {
84
- users.push(getUserData(this, group));
85
- }
86
- }
87
- });
88
-
89
- return users;
90
- };
91
-
92
- const getPage = (url) => {
93
- $.get(url, (data) => {
94
- const nextURL = $(data).find('.pagination img[alt="Siguiente"]').parent().attr('href') || false;
95
-
96
- members = members.concat(getUsersPage(data));
97
-
98
- if (nextURL) {
99
- getPage(nextURL);
100
- } else {
101
- resolve(members.sort((a, b) => {
102
- if (a.user < b.user) return -1;
103
- if (a.user > b.user) return 1;
104
- return 0;
105
- }));
106
- }
107
- });
108
- };
109
-
110
- getPage('/memberlist?change_version=invision');
111
- });
112
- },
113
- getGroups: (cache) => {
114
- const getData = () => {
115
- return new Promise((resolve, reject) => {
116
- $.get('/groups?change_version=invision', (data) => {
117
- let groups = [];
118
-
119
- $(data).find('.group_list > li').each(function() {
120
- groups.push({
121
- id: parseInt($(this).find('a').attr('href').split('/g')[1].split('-')[0]),
122
- name: $(this).find('a').text().trim(),
123
- color: $(this).find('a').css('color'),
124
- url: Vue.filter('url-to-normal')($(this).find('a').attr('href')),
125
- count: parseInt($(this).find('div > span').text()) - 1
126
- });
127
- });
128
-
129
- resolve(groups);
130
- });
131
- });
132
- };
133
-
134
- const readGroupsCache = () => {
135
- return new Promise((resolve, reject) => {
136
- FNR.cache.useData('groups', cache).then(
137
- (result) => {
138
- resolve(result);
139
- },
140
- (err) => {
141
- getData().then((data) => {
142
- FNR.cache.setData('groups', data);
143
-
144
- resolve(data);
145
- });
146
- }
147
- );
148
- });
149
- };
150
-
151
- return readGroupsCache();
152
- },
153
- getAffiliates: () => {
154
- return new Promise((resolve, reject) => {
155
- const tops = forumConfig.affiliatesMax;
156
-
157
- const data = Object.entries(forumAffiliates).map((item) => {
158
- let final = '';
159
-
160
- item[1].forEach((item) => {
161
- final += '<li><a href="' + item.url + '" title="' + item.title + '" target="_blank"><img src="' + item.img + '" alt="' + item.title + '"/></a></li>';
162
- });
163
-
164
- for (let i = 0; i < (tops[item[0]] - item[1].length); i++) {
165
- final += '<li><a href="/" title="' + forumData.name + '"><img src="' + forumDefaults.affiliates[item[0]] + '" alt="' + forumData.name + '"/></a></li>';
166
- }
167
-
168
- return final;
169
- });
170
-
171
- resolve({
172
- normal: data[0],
173
- elite: data[1],
174
- directory: data[2],
175
- sister: data[3],
176
- });
177
- });
178
- },
179
- },
180
- content: {
181
- isAutosave: () => {
182
- if (document.post === undefined) return false;
183
- else return _userdata !== undefined && document.post.mode.value === 'reply' && document.post.t !== undefined
184
- },
185
- getPost: (url) => {
186
- return new Promise((resolve, reject) => {
187
- $.get(Vue.filter('url-to-invision')(url), (data) => {
188
- const post = $(data).find("#p" + url.split("#")[1]);
189
-
190
- resolve({
191
- author: {
192
- text: post.find(".author a").text(),
193
- color: post.find(".author a span").css("color"),
194
- url: Vue.filter('url-to-normal')(post.find(".author a").attr("href")),
195
- },
196
- content: post.find(".post-entry > div").html(),
197
- date: post.find(".author").html().split("</a>")[1],
198
- });
199
- });
200
- });
201
- },
202
- genPost: (id, content) => {
203
- return new Promise((resolve, reject) => {
204
- let save = document.createElement('iframe');
205
-
206
- save.id = 'forum-save';
207
- save.src = '/post?t=' + id + '&mode=reply&change_version=invision';
208
- save.width = 0;
209
- save.height = 0;
210
- save.onload = () => {
211
- saveDOM.onload = () => {
212
- $('#forum-save').remove();
213
-
214
- console.clear();
215
-
216
- resolve(true);
217
- };
218
-
219
- $('#forum-save').contents().find('.subtitle:contains("Mensaje")').next().find('textarea').val(content);
220
- $('#forum-save').contents().find('.formbuttonrow.center input[value="Enviar"]').click();
221
- };
222
-
223
- document.querySelector('body > header').prepend(save);
224
-
225
- const saveDOM = document.getElementById('forum-save');
226
- });
227
- },
228
- genTopic: (id, name, content) => {
229
- return new Promise((resolve, reject) => {
230
- let save = document.createElement('iframe');
231
-
232
- save.id = 'forum-save';
233
- save.src = '/post?f=' + id + '&mode=newtopic&change_version=invision';
234
- save.width = 0;
235
- save.height = 0;
236
- save.onload = () => {
237
- saveDOM.onload = () => {
238
- $('#forum-save').remove();
239
-
240
- console.clear();
241
-
242
- resolve(true);
243
- };
244
-
245
- $('#forum-save').contents().find('dl dt:contains("Título del tema")').parent().find('input').val(name);
246
- $('#forum-save').contents().find('.subtitle:contains("Mensaje")').next().find('textarea').val(content);
247
- $('#forum-save').contents().find('.formbuttonrow.center input[value="Enviar"]').click();
248
- };
249
-
250
- document.querySelector('body > header').prepend(save);
251
-
252
- const saveDOM = document.getElementById('forum-save');
253
- });
254
- }
255
- },
256
- user: {
257
- getUrl: (name) => {
258
- let character =
259
- name !== undefined ? encodeURIComponent(name)
260
- .replace(/[!'()]/g, escape)
261
- .replace(/\*/g, "%2A") :
262
- _userdata.user_id;
263
-
264
- return "/profile?mode=viewprofile&u=" + character;
265
- },
266
- getLevel: () => {
267
- return new Promise((resolve, reject) => {
268
- if (_userdata === undefined) resolve('guest');
269
-
270
- switch (_userdata.user_level) {
271
- case 2:
272
- resolve('mod');
273
- case 1:
274
- resolve('admin');
275
- case 0:
276
- resolve('user');
277
- }
278
- });
279
- },
280
- getGroup: () => {
281
- return new Promise((resolve, reject) => {
282
- FNR.user.getLevel().then((status) => {
283
- if (status === 'guest') {
284
- resolve('unknown');
285
- } else {
286
- FNR.user.getProfile(_userdata.user_id, .25).then((data) => {
287
- resolve(data['colour']);
288
- });
289
- }
290
- });
291
- });
292
- },
293
- getProfile: (name, time) => {
294
- const character = name != undefined ? FNR.user.getUrl(name) : FNR.user.getUrl();
295
- const cache = time || 5;
296
-
297
- const processData = (content) => {
298
- if (content.find('a').length) return Vue.filter('url-to-normal')(content.find('a').attr('href'));
299
- else if (content.find('table').length) return content.find('table').html();
300
- else if (content.find('img').length) return content.find('img').attr('src');
301
- else if (content.find('textarea').length) return content.find('textarea').val();
302
- else if (content.find('span').length) return content.find('span').text().trim();
303
- else if (content.text().trim() === '-') return '';
304
- else return content.text();
305
- };
306
-
307
- const getData = () => {
308
- return new Promise((resolve, reject) => {
309
- $.get(character + '&change_version=invision', (data) => {
310
- let user = {};
311
-
312
- user['name'] = $(data).find('.maintitle h1 span').text();
313
- user['lastvisit'] = $(data).find('dt:contains("Última visita")').parent().find('dd').text();
314
- user['colour'] = FNR.utility.getGroup($(data).find('.maintitle h1 span').css('color').replace('rgb(', 'rgb_').replace(/, /g, '_').replace(')', ''));
315
- user['avatar'] = $(data).find('.real_avatar img').attr('src');
316
-
317
- user['links'] = {
318
- profile: '/u' + character.split('&u=')[1],
319
- mp: '/privmsg?mode=post&u=' + character.split('&u=')[1],
320
- };
321
-
322
- user['messages'] = {
323
- public: parseInt($(data).find('span:contains("Mensajes")').parent().parent().find('dd > div').text()) || 0,
324
- private: parseInt($(data).find('dt:contains("Mensajes privados")').parent().find('dd').text()) || 0
325
- };
326
-
327
- user['fields'] = {};
328
-
329
- $(data).find('dl[id^="field_id"]').each(function() {
330
- if ($(this).find('dt span').text() !== '') {
331
- if ($(this).find('dt span').text() === 'Mensajes') return;
332
-
333
- user.fields[FNR.utility.genSlug($(this).find('dt span').text())] = {
334
- name: $(this).find('dt span').text(),
335
- content: processData($(this).find('dd .field_uneditable'))
336
- }
337
- }
338
- });
339
-
340
- $(data).find('.ipbform2 > dl').each(function() {
341
- if ($(this).find('dt span').length && $(this).find('dt span').text() !== '') {
342
- if ($(this).find('dt span').text() === 'Mensajes') return;
343
-
344
- user.fields[FNR.utility.genSlug($(this).find('dt span').text())] = {
345
- name: $(this).find('dt span').text(),
346
- content: processData($(this).find('dd'))
347
- }
348
- }
349
- });
350
-
351
- user.fields['rango'] = {
352
- name: 'Rango',
353
- content: $(data).find('dt:contains("Rango:")').parent().find('dd').text()
354
- }
355
-
356
- resolve(user);
357
- });
358
- });
359
- };
360
-
361
- const readUserCache = (dat) => {
362
- const id = "userInfo" + dat;
363
-
364
- return new Promise((resolve, reject) => {
365
- FNR.cache.useData(id, cache).then(
366
- (result) => {
367
- resolve(result);
368
- },
369
- (err) => {
370
- getData().then((data) => {
371
- FNR.cache.setData(id, data);
372
-
373
- resolve(data);
374
- });
375
- }
376
- );
377
- });
378
- };
379
-
380
- return readUserCache(name);
381
- },
382
- changeAccount: (out, username, password) => {
383
- return new Promise((resolve, reject) => {
384
- let save = document.createElement('iframe');
385
-
386
- save.id = 'forum-save';
387
- save.src = out;
388
- save.width = 0;
389
- save.height = 0;
390
- save.onload = () => {
391
- save.onload = () => {
392
- save.onload = () => {
393
- console.clear();
394
-
395
- resolve(true);
396
- };
397
-
398
- $('#forum-save').contents().find('input[name="username"]').val(username);
399
- $('#forum-save').contents().find('input[name="password"]').val(password);
400
- $('#forum-save').contents().find('input[type="submit"][name="login"]').click();
401
- };
402
-
403
- saveDOM.src = '/login?change_version=invision';
404
- };
405
-
406
- document.querySelector('body > header').prepend(save);
407
-
408
- const saveDOM = document.getElementById('forum-save');
409
- });
410
- },
411
- profile: {
412
- getData: (array) => {
413
- return new Promise((resolve, reject) => {
414
- $.get('/profile?change_version=invision&mode=editprofile', (data) => {
415
- const fields = data;
416
-
417
- $.get('/profile?change_version=invision&mode=editprofile&page_profil=avatars', (data) => {
418
- const avatar = data;
419
-
420
- let result = [];
421
-
422
- [].forEach.call(array, (item) => {
423
- let value = '',
424
- options = [];
425
-
426
- switch (item.type) {
427
- case 'input':
428
- value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('input').val();
429
- break;
430
-
431
- case 'textarea':
432
- value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('textarea').val();
433
- break;
434
-
435
- case 'select':
436
- value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('select option:selected').attr('value');
437
-
438
- $(fields).find('dl:contains("' + item.name + '")').find('dd').find('select option').each(function() {
439
- if ($(this).attr('value') === '') return;
440
-
441
- options.push({
442
- name: $(this).text(),
443
- value: $(this).attr('value')
444
- });
445
- });
446
- break;
447
-
448
- case 'avatar':
449
- value = $(avatar).find('.box-content img').attr('src');
450
- break;
451
- }
452
-
453
- if (item.type === 'select' && value === undefined || item.type === 'select' && value === '') return;
454
-
455
- let final = {
456
- type: item.type,
457
- name: item.name,
458
- value: value
459
- };
460
-
461
- if (item.validation) {
462
- final.validation = item.validation;
463
- }
464
-
465
- if (options.length) {
466
- final.options = options;
467
- }
468
-
469
- result.push(final);
470
- });
471
-
472
- resolve(result);
473
- });
474
- });
475
- });
476
- },
477
- setData: (array) => {
478
- return new Promise((resolve, reject) => {
479
- const resolveSetter = () => {
480
- $('#forum-save').remove();
481
-
482
- console.clear();
483
-
484
- resolve(true);
485
- };
486
-
487
- let save = document.createElement('iframe');
488
-
489
- save.id = 'forum-save';
490
- save.src = '/profile?change_version=invision&mode=editprofile';
491
- save.width = 0;
492
- save.height = 0;
493
- save.onload = () => {
494
- let avatar = false;
495
-
496
- [].forEach.call(array, (item) => {
497
- switch (item.type) {
498
- case 'input':
499
- $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('input').first().val(item.value);
500
- break;
501
-
502
- case 'textarea':
503
- $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('textarea').val(item.value);
504
- break;
505
-
506
- case 'select':
507
- $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('select option[value="' + item.value + '"]').attr('selected', 'selected');
508
- break;
509
-
510
- case 'avatar':
511
- avatar = item.value;
512
- break;
513
- }
514
- });
515
-
516
- saveDOM.onload = () => {
517
- if (!avatar) {
518
- resolveSetter();
519
- } else {
520
- saveDOM.onload = () => {
521
- saveDOM.onload = () => {
522
- resolveSetter();
523
- }
524
-
525
- $('#forum-save').contents().find('input[name="avatarremoteurl"]').val(avatar);
526
- $('#forum-save').contents().find('input[type="submit"][value="Registrar"]').click();
527
- }
528
-
529
- saveDOM.src = '/profile?change_version=invision&mode=editprofile&page_profil=avatars';
530
- }
531
- };
532
-
533
- $('#forum-save').contents().find('input[type="submit"][value="Registrar"]').click();
534
- };
535
-
536
- document.querySelector('body > header').prepend(save);
537
-
538
- const saveDOM = document.getElementById('forum-save');
539
- });
540
- },
541
- getDrafts: () => {
542
- return new Promise((resolve, reject) => {
543
- $.get('/search?search_id=draftsearch&change_version=invision', (data) => {
544
- if (parseFloat($(data).find('.maintitle > h3').text()) !== 0) {
545
- let final = [];
546
-
547
- $(data).find('.ipbform .ipbtable tbody > tr').each(function() {
548
- const cells = $(this).find('td');
549
-
550
- final.push({
551
- topic: {
552
- name: cells[1].textContent.trim(),
553
- url: Vue.filter('url-to-normal')(cells[1].querySelector('a').href)
554
- },
555
- info: {
556
- location: cells[2].textContent.trim(),
557
- date: cells[3].textContent.trim()
558
- },
559
- modify: Vue.filter('url-to-normal')(cells[4].querySelector('a').href)
560
- });
561
- });
562
-
563
- resolve(final);
564
- } else {
565
- resolve(false);
566
- }
567
- });
568
- });
569
- }
570
- }
571
- },
572
- cache: {
573
- getData: (id) => {
574
- if (localStorage.getItem(forumData.prefix + '_' + id) === null) return false;
575
- else return JSON.parse(localStorage.getItem(forumData.prefix + '_' + id)).content;
576
- },
577
- setData: (id, data, time) => {
578
- let cur_date = time === -1 ? 'undefined' : new Date().getTime();
579
-
580
- localStorage.setItem(
581
- forumData.prefix + '_' + id,
582
- JSON.stringify({
583
- cached_at: cur_date,
584
- content: data,
585
- })
586
- );
587
- },
588
- delData: (id) => {
589
- if (localStorage.getItem(forumData.prefix + '_' + id) === null) return false;
590
- else return localStorage.removeItem(forumData.prefix + '_' + id);
591
- },
592
- useData: (id, time) => {
593
- return new Promise((resolve, reject) => {
594
- let item = localStorage.getItem(forumData.prefix + '_' + id),
595
- cur_date = new Date(),
596
- timeMil = time == -1 ? 'undefined' : time * 86400000;
597
-
598
- if ((item != null && time == -1) || (item != null && parseInt(JSON.parse(item).cached_at) + timeMil > cur_date.getTime())) {
599
- resolve(JSON.parse(item).content);
600
- } else {
601
- reject(false);
602
- }
603
- });
604
- },
605
- },
606
- utility: {
607
- genSlug: (text, alt) => {
608
- const slug = (Q) => {
609
- const R = '\xE0\xE1\xE4\xE2\xE8\xE9\xEB\xEA\xEC\xED\xEF\xEE\xF2\xF3\xF6\xF4\xF9\xFA\xFC\xFB\xF1\xE7\xB7/_,:;';
610
- Q = Q.trim().toLowerCase();
611
- for (var T = 0, U = R.length; T < U; T++) Q = Q.replace(new RegExp(R.charAt(T), 'g'), 'aaaaeeeeiiiioooouuuunc------'.charAt(T));
612
- return Q.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-');
613
- };
614
-
615
- const replace = alt || '_';
616
-
617
- return slug(text).replace(/-/g, replace);
618
- },
619
- genArray: (string) => {
620
- return JSON.parse(string.replace(/`/g, '"'));
621
- },
622
- genValidation: (array) => {
623
- let final = '';
624
-
625
- [].forEach.call(array, (item) => {
626
- switch (item.validation) {
627
- case 'hex':
628
- if (!item.value.match(/^#[a-f0-9]{6}$/i)) {
629
- final += '<li>El campo de ' + item.name.toLowerCase() + ' debe incluir un código de color hexadecimal.</li>';
630
- }
631
- break;
632
-
633
- case 'img':
634
- if (!item.value.match(/(jpg|jpeg|png)$/i)) {
635
- final += '<li>El campo de ' + item.name.toLowerCase() + ' debe ser el enlace a una imagen (formato png, jpg o jpeg).</li>';
636
- }
637
- break;
638
- }
639
- });
640
-
641
- return final;
642
- },
643
- getGroup: (color) => {
644
- const returnHexVer = (code) => {
645
- let status = 'unknown';
646
-
647
- Object.values(forumColours).map((item) => {
648
- if (item.hex === code.toLowerCase()) status = FNR.utility.genSlug(item.code);
649
- });
650
-
651
- return status;
652
- };
653
-
654
- const returnIdVer = (code) => {
655
- let status = 'unknown';
656
-
657
- Object.values(forumColours).map((item) => {
658
- if (item.id === code) status = FNR.utility.genSlug(item.code);
659
- });
660
-
661
- return status;
662
- };
663
-
664
- if (color === undefined) return 'unknown';
665
- else if (color.indexOf('#') > -1) return returnHexVer(color);
666
- else if (color.indexOf('id_') > -1) return returnIdVer(parseFloat(color.split('_')[1]));
667
- else if (forumColours[color] === undefined) return 'unknown';
668
- else return FNR.utility.genSlug(forumColours[color].code);
669
- }
670
- },
671
- html: {
672
- genModal: (title, content, buttons) => {
673
- if (title === '' || title === undefined || title === null) return;
674
- if (content === '' || content === undefined || content === null) return;
675
-
676
- let modal = document.createElement('div');
677
-
678
- modal.id = 'forum-modal';
679
-
680
- document.body.appendChild(modal);
681
-
682
- let final = '';
683
-
684
- final += '<div id="' + FNR.utility.genSlug(title, '-') + '" class="modal-element">';
685
- final += '<div class="modal-title">';
686
- final += '<h3>' + title + '</h3>';
687
- final += '<a onclick="document.getElementById(`forum-modal`).remove()">';
688
- final += '<i class="fas fa-times"></i>';
689
- final += '</a>';
690
- final += '</div>';
691
- final += '<div class="modal-content">';
692
- final += '<div class="is-content">';
693
- final += content.replace(/\n/g, '<br>');
694
- final += '</div>';
695
-
696
- if (buttons !== '' && buttons !== undefined && buttons !== null) {
697
- final += '<div class="modal-buttons">';
698
- final += buttons;
699
- final += '</div>';
700
- }
701
-
702
- final += '</div>';
703
- final += '</div>';
704
-
705
- final += '<div class="is-bgmodal bg-active" onclick="document.getElementById(`forum-modal`).remove()"></div>';
706
-
707
- document.getElementById('forum-modal').innerHTML = final;
708
- },
709
- genPrompt: (title, content, placeholder, text) => {
710
- if (title === '' || title === undefined || title === null) return;
711
- if (content === '' || content === undefined || content === null) return;
712
-
713
- return new Promise((resolve, reject) => {
714
- FNR.html.genModal(title, '<p>' + content + '</p><p><input id="modal-prompt" type="text" placeholder="' + placeholder + '" value="' + text + '"></p>', '<button id="modal-button-enter" class="button1 btn-main">Confirmar</button><button id="modal-button-cancel" class="button1">Cancelar</button>');
715
-
716
- document.querySelector('#modal-button-enter').onclick = () => {
717
- const result = document.querySelector('#modal-prompt').value;
718
-
719
- if (result === '') {
720
- resolve(false);
721
- } else {
722
- resolve(result);
723
- }
724
-
725
- document.getElementById(`forum-modal`).remove();
726
- };
727
-
728
- document.querySelector('#modal-button-cancel').onclick = () => {
729
- reject(false);
730
- document.getElementById(`forum-modal`).remove();
731
- };
732
-
733
- document.querySelector('.modal-title a').onclick = () => {
734
- reject(false);
735
- document.getElementById(`forum-modal`).remove();
736
- };
737
-
738
- document.querySelector('.is-bgmodal.bg-active').onclick = () => {
739
- reject(false);
740
- document.getElementById(`forum-modal`).remove();
741
- };
742
- });
743
- },
744
- genNotification: (title, content, icon, url) => {
745
- if (title === '' || title === undefined || title === null) return;
746
- if (content === '' || content === undefined || content === null) return;
747
- if (content.length > 50) return;
748
- if (icon === '' || icon === undefined || icon === null) return;
749
-
750
- if (document.querySelectorAll('forum-notification').length) {
751
- document.getElementById('forum-notification').remove();
752
- clearTimeout();
753
- }
754
-
755
- let notification = document.createElement('div');
756
-
757
- notification.id = 'forum-notification';
758
-
759
- document.body.appendChild(notification);
760
-
761
- let final = '';
762
-
763
- if (url === '' || url === undefined || url === null) {
764
- final += '<div id="' + FNR.utility.genSlug(title, '-') + '" class="notification-element" onclick="document.querySelector(`#forum-notification`).classList.remove(`notification-show`)" >';
765
- } else {
766
- final += '<a href="' + url + '" target="_blank" id="' + FNR.utility.genSlug(title, '-') + '" class="notification-element" onclick="document.querySelector(`#forum-notification`).classList.remove(`notification-show`)" >';
767
- }
768
-
769
- final += '<div class="notification-icon">';
770
- final += '<i class="' + icon + '"></i>';
771
- final += '</div>';
772
- final += '<div class="notification-content">';
773
- final += '<h3>' + title + '</h3>';
774
- final += '<p>' + content + '</p>';
775
- final += '</div>';
776
- final += '<div class="notification-controls">';
777
- final += '<i class="fas fa-times"></i>';
778
- final += '</div>';
779
-
780
- if (url === '' || url === undefined || url === null) {
781
- final += '</div>';
782
- } else {
783
- final += '</a>';
784
- }
785
-
786
- document.getElementById('forum-notification').innerHTML = final;
787
-
788
- setTimeout(() => {
789
- document.getElementById(`forum-notification`).classList.add('notification-show');
790
- }, 500);
791
-
792
- setTimeout(() => {
793
- document.getElementById(`forum-notification`).classList.remove('notification-show');
794
- }, 8000);
795
-
796
- setTimeout(() => {
797
- document.getElementById(`forum-notification`).remove();
798
- }, 10000);
799
- }
800
- },
801
- behaviour: {
802
- genWiki: () => {
803
- if (document.querySelector('.wiki-cascade')) {
804
- [].forEach.call(document.getElementsByClassName('wiki-cascade'), (item) => {
805
- item.onclick = () => {
806
- const element = item.parentElement.parentElement;
807
-
808
- if (element.classList.contains('is-active')) {
809
- element.classList.remove('is-active');
810
- } else {
811
- element.classList.add('is-active');
812
- }
813
- };
814
- });
815
- }
816
-
817
- if (document.querySelector('.wiki-controls .router-link-active')) {
818
- [].forEach.call(document.querySelectorAll('.wiki-controls .router-link-active'), (item) => {
819
- if (!item.parentElement.parentElement.parentElement.parentElement.parentElement.classList.contains('wiki-index')) {
820
- const setActive = (element, isFirst) => {
821
- let parentElement = element.parentElement.parentElement;
822
-
823
- if (isFirst) {
824
- parentElement = parentElement.parentElement.parentElement;
825
- }
826
-
827
- parentElement.classList.add('is-active');
828
- parentElement.classList.add('is-selected');
829
-
830
- if (!parentElement.parentElement.parentElement.parentElement.classList.contains('wiki-index')) {
831
- setActive(parentElement, false);
832
- }
833
- };
834
-
835
- setActive(item, true);
836
- }
837
- });
838
- }
839
-
840
- if (document.querySelector('aside.wiki-index > .select-container > select')) {
841
- document.querySelector('aside.wiki-index > .select-container > select').onchange = () => {
842
- router.push(document.querySelector('aside.wiki-index > .select-container > select').value);
843
- };
844
- }
845
- },
846
- genDropeable: () => {
847
- if (document.querySelector('.is-dropeable')) {
848
- [].forEach.call(document.getElementsByClassName('is-dropeable'), (item) => {
849
- item.onclick = () => {
850
- if (!item.classList.contains('is-active')) {
851
- [].forEach.call(document.getElementsByClassName('is-dropeable'), (drops) => {
852
- drops.classList.remove('is-active');
853
- });
854
-
855
- item.classList.add('is-active');
856
- } else {
857
- item.classList.remove('is-active');
858
- }
859
- };
860
- });
861
- }
862
- }
863
- }
2
+ execFn: (callback) => {
3
+ document.addEventListener('forumReady', callback, false);
4
+ },
5
+ forum: {
6
+ getColors: () => {
7
+ return Object.values(forumColours)
8
+ .map((item) => {
9
+ return {
10
+ name: item.code,
11
+ hex: item.hex
12
+ }
13
+ });
14
+ },
15
+ getTopics: (array, limit) => {
16
+ return new Promise((resolve, reject) => {
17
+ const addContent = (elmt) => {
18
+ const titleElmnt = $(elmt).find('.topictitle');
19
+ const dateElmnt = $(elmt).children().last();
20
+
21
+ finalArray.push({
22
+ name: titleElmnt.text().trim(),
23
+ url: Vue.filter('url-to-normal')(titleElmnt.attr('href')),
24
+ lastpost: {
25
+ url: Vue.filter('url-to-normal')(dateElmnt.children().last().attr('href')),
26
+ date: dateElmnt.text().split('por')[0].trim(),
27
+ who: {
28
+ name: dateElmnt.find('strong a').length ? dateElmnt.find('strong a').text().trim() : 'Invitado',
29
+ url: Vue.filter('url-to-normal')(dateElmnt.find('strong a').length ? dateElmnt.find('strong a').attr('href') : '/'),
30
+ color: dateElmnt.find('strong a').length ? dateElmnt.find('strong a span').attr('style').split('color:')[1] : 'initial',
31
+ },
32
+ },
33
+ forum: {
34
+ name: $(elmt).find('.row2 + .row2:not(.centered) a').text().trim(),
35
+ url: Vue.filter('url-to-normal')($(elmt).find('.row2 + .row2:not(.centered) a').attr('href')),
36
+ },
37
+ });
38
+ };
39
+
40
+ const getPage = (url) => {
41
+ $.get(url, (data) => {
42
+ $(data).find('.ipbform').find('tbody').find('tr').each(function() {
43
+ if (finalArray.length < limit && array.indexOf(parseInt($(this).find('.row2 + .row2:not(.centered) a').attr('href').split('/f')[1].split('-')[0])) === -1) {
44
+ addContent(this);
45
+ }
46
+ });
47
+
48
+ if (finalArray.length === limit || !$(data).find('.pagination')[0].children.length || $(data).find('.pagination').children().last()[0].localName === 'b') {
49
+ resolve(finalArray);
50
+ } else {
51
+ getPage($(data).find('.pagination').children().last().attr('href'));
52
+ }
53
+ });
54
+ };
55
+
56
+ let finalArray = [];
57
+
58
+ getPage('/latest?change_version=invision');
59
+ });
60
+ },
61
+ getMembers: (option) => {
62
+ return new Promise((resolve, reject) => {
63
+ let members = [];
64
+
65
+ const getUserData = (user, color) => {
66
+ return {
67
+ user: $(user).find('.membername span').text().trim(),
68
+ id: $(user).find('.popupmenu .popupmenu-item a').attr('href').split('?')[0],
69
+ img: $(user).find('.mini-avatar img').attr('src'),
70
+ color: color
71
+ };
72
+ };
73
+
74
+ const getUsersPage = (page) => {
75
+ let users = [];
76
+
77
+ $(page).find('.member-list .member').each(function() {
78
+ const group = FNR.utility.getGroup($(this).find('.membername span').attr('style').split('color:')[1]);
79
+
80
+ if (option) {
81
+ users.push(getUserData(this, group));
82
+ } else {
83
+ if (group !== 'unknown' && group !== forumConfig.skinOptions.adminGroup) {
84
+ users.push(getUserData(this, group));
85
+ }
86
+ }
87
+ });
88
+
89
+ return users;
90
+ };
91
+
92
+ const getPage = (url) => {
93
+ $.get(url, (data) => {
94
+ const nextURL = $(data).find('.pagination img[alt="Siguiente"]').parent().attr('href') || false;
95
+
96
+ members = members.concat(getUsersPage(data));
97
+
98
+ if (nextURL) {
99
+ getPage(nextURL);
100
+ } else {
101
+ resolve(members.sort((a, b) => {
102
+ if (a.user < b.user) return -1;
103
+ if (a.user > b.user) return 1;
104
+ return 0;
105
+ }));
106
+ }
107
+ });
108
+ };
109
+
110
+ getPage('/memberlist?change_version=invision');
111
+ });
112
+ },
113
+ getGroups: (cache) => {
114
+ const getData = () => {
115
+ return new Promise((resolve, reject) => {
116
+ $.get('/groups?change_version=invision', (data) => {
117
+ let groups = [];
118
+
119
+ $(data).find('.group_list > li').each(function() {
120
+ groups.push({
121
+ id: parseInt($(this).find('a').attr('href').split('/g')[1].split('-')[0]),
122
+ name: $(this).find('a').text().trim(),
123
+ color: $(this).find('a').css('color'),
124
+ url: Vue.filter('url-to-normal')($(this).find('a').attr('href')),
125
+ count: parseInt($(this).find('div > span').text()) - 1
126
+ });
127
+ });
128
+
129
+ resolve(groups);
130
+ });
131
+ });
132
+ };
133
+
134
+ const readGroupsCache = () => {
135
+ return new Promise((resolve, reject) => {
136
+ FNR.cache.useData('groups', cache).then(
137
+ (result) => {
138
+ resolve(result);
139
+ },
140
+ (err) => {
141
+ getData().then((data) => {
142
+ FNR.cache.setData('groups', data);
143
+
144
+ resolve(data);
145
+ });
146
+ }
147
+ );
148
+ });
149
+ };
150
+
151
+ return readGroupsCache();
152
+ },
153
+ getAffiliates: () => {
154
+ return new Promise((resolve, reject) => {
155
+ const tops = forumConfig.affiliatesMax;
156
+
157
+ const data = Object.entries(forumAffiliates).map((item) => {
158
+ let final = '';
159
+
160
+ item[1].forEach((item) => {
161
+ final += '<li><a href="' + item.url + '" title="' + item.title + '" target="_blank"><img src="' + item.img + '" alt="' + item.title + '"/></a></li>';
162
+ });
163
+
164
+ for (let i = 0; i < (tops[item[0]] - item[1].length); i++) {
165
+ final += '<li><a href="/" title="' + forumData.name + '"><img src="' + forumDefaults.affiliates[item[0]] + '" alt="' + forumData.name + '"/></a></li>';
166
+ }
167
+
168
+ return final;
169
+ });
170
+
171
+ resolve({
172
+ normal: data[0],
173
+ elite: data[1],
174
+ directory: data[2],
175
+ sister: data[3],
176
+ });
177
+ });
178
+ },
179
+ },
180
+ content: {
181
+ isAutosave: () => {
182
+ if (document.post === undefined) return false;
183
+ else return _userdata.user_id !== -1 && document.post.mode.value === 'reply' && document.post.t !== undefined
184
+ },
185
+ getPost: (url) => {
186
+ return new Promise((resolve, reject) => {
187
+ $.get(Vue.filter('url-to-invision')(url), (data) => {
188
+ const post = $(data).find("#p" + url.split("#")[1]);
189
+
190
+ resolve({
191
+ author: {
192
+ text: post.find(".author a").text(),
193
+ color: post.find(".author a span").css("color"),
194
+ url: Vue.filter('url-to-normal')(post.find(".author a").attr("href")),
195
+ },
196
+ content: post.find(".post-entry > div").html(),
197
+ date: post.find(".author").html().split("</a>")[1],
198
+ });
199
+ });
200
+ });
201
+ },
202
+ genPost: (id, content) => {
203
+ return new Promise((resolve, reject) => {
204
+ let save = document.createElement('iframe');
205
+
206
+ save.id = 'forum-save';
207
+ save.src = '/post?t=' + id + '&mode=reply&change_version=invision';
208
+ save.width = 0;
209
+ save.height = 0;
210
+ save.onload = () => {
211
+ saveDOM.onload = () => {
212
+ $('#forum-save').remove();
213
+
214
+ console.clear();
215
+
216
+ resolve(true);
217
+ };
218
+
219
+ $('#forum-save').contents().find('.subtitle:contains("Mensaje")').next().find('textarea').val(content);
220
+ $('#forum-save').contents().find('.formbuttonrow.center input[value="Enviar"]').click();
221
+ };
222
+
223
+ document.querySelector('body > header').prepend(save);
224
+
225
+ const saveDOM = document.getElementById('forum-save');
226
+ });
227
+ },
228
+ genTopic: (id, name, content) => {
229
+ return new Promise((resolve, reject) => {
230
+ let save = document.createElement('iframe');
231
+
232
+ save.id = 'forum-save';
233
+ save.src = '/post?f=' + id + '&mode=newtopic&change_version=invision';
234
+ save.width = 0;
235
+ save.height = 0;
236
+ save.onload = () => {
237
+ saveDOM.onload = () => {
238
+ $('#forum-save').remove();
239
+
240
+ console.clear();
241
+
242
+ resolve(true);
243
+ };
244
+
245
+ $('#forum-save').contents().find('dl dt:contains("Título del tema")').parent().find('input').val(name);
246
+ $('#forum-save').contents().find('.subtitle:contains("Mensaje")').next().find('textarea').val(content);
247
+ $('#forum-save').contents().find('.formbuttonrow.center input[value="Enviar"]').click();
248
+ };
249
+
250
+ document.querySelector('body > header').prepend(save);
251
+
252
+ const saveDOM = document.getElementById('forum-save');
253
+ });
254
+ }
255
+ },
256
+ user: {
257
+ getUrl: (name) => {
258
+ let character =
259
+ name !== undefined ? encodeURIComponent(name)
260
+ .replace(/[!'()]/g, escape)
261
+ .replace(/\*/g, "%2A") :
262
+ _userdata.user_id;
263
+
264
+ return "/profile?mode=viewprofile&u=" + character;
265
+ },
266
+ getLevel: () => {
267
+ return new Promise((resolve, reject) => {
268
+ switch (_userdata.user_level) {
269
+ case 2:
270
+ resolve('mod');
271
+ case 1:
272
+ resolve('admin');
273
+ case 0:
274
+ return -1 == _userdata.user_id ? resolve('guest') : resolve('user');
275
+ }
276
+ });
277
+ },
278
+ getGroup: () => {
279
+ return new Promise((resolve, reject) => {
280
+ FNR.user.getLevel().then((status) => {
281
+ if (status === 'guest') {
282
+ resolve('unknown');
283
+ } else {
284
+ FNR.user.getProfile(_userdata.user_id, .25).then((data) => {
285
+ resolve(data['colour']);
286
+ });
287
+ }
288
+ });
289
+ });
290
+ },
291
+ getProfile: (name, time) => {
292
+ const character = name != undefined ? FNR.user.getUrl(name) : FNR.user.getUrl();
293
+ const cache = time || 5;
294
+
295
+ const processData = (content) => {
296
+ if (content.find('a').length) return Vue.filter('url-to-normal')(content.find('a').attr('href'));
297
+ else if (content.find('table').length) return content.find('table').html();
298
+ else if (content.find('img').length) return content.find('img').attr('src');
299
+ else if (content.find('textarea').length) return content.find('textarea').val();
300
+ else if (content.find('span').length) return content.find('span').text().trim();
301
+ else if (content.text().trim() === '-') return '';
302
+ else return content.text();
303
+ };
304
+
305
+ const getData = () => {
306
+ return new Promise((resolve, reject) => {
307
+ $.get(character + '&change_version=invision', (data) => {
308
+ let user = {};
309
+
310
+ user['name'] = $(data).find('.maintitle h1 span').text();
311
+ user['lastvisit'] = $(data).find('dt:contains("Última visita")').parent().find('dd').text();
312
+ user['colour'] = FNR.utility.getGroup($(data).find('.maintitle h1 span').css('color').replace('rgb(', 'rgb_').replace(/, /g, '_').replace(')', ''));
313
+ user['avatar'] = $(data).find('.real_avatar img').attr('src');
314
+
315
+ user['links'] = {
316
+ profile: '/u' + character.split('&u=')[1],
317
+ mp: '/privmsg?mode=post&u=' + character.split('&u=')[1],
318
+ };
319
+
320
+ user['messages'] = {
321
+ public: parseInt($(data).find('span:contains("Mensajes")').parent().parent().find('dd > div').text()) || 0,
322
+ private: parseInt($(data).find('dt:contains("Mensajes privados")').parent().find('dd').text()) || 0
323
+ };
324
+
325
+ user['fields'] = {};
326
+
327
+ $(data).find('dl[id^="field_id"]').each(function() {
328
+ if ($(this).find('dt span').text() !== '') {
329
+ if ($(this).find('dt span').text() === 'Mensajes') return;
330
+
331
+ user.fields[FNR.utility.genSlug($(this).find('dt span').text())] = {
332
+ name: $(this).find('dt span').text(),
333
+ content: processData($(this).find('dd .field_uneditable'))
334
+ }
335
+ }
336
+ });
337
+
338
+ $(data).find('.ipbform2 > dl').each(function() {
339
+ if ($(this).find('dt span').length && $(this).find('dt span').text() !== '') {
340
+ if ($(this).find('dt span').text() === 'Mensajes') return;
341
+
342
+ user.fields[FNR.utility.genSlug($(this).find('dt span').text())] = {
343
+ name: $(this).find('dt span').text(),
344
+ content: processData($(this).find('dd'))
345
+ }
346
+ }
347
+ });
348
+
349
+ user.fields['rango'] = {
350
+ name: 'Rango',
351
+ content: $(data).find('dt:contains("Rango:")').parent().find('dd').text()
352
+ }
353
+
354
+ resolve(user);
355
+ });
356
+ });
357
+ };
358
+
359
+ const readUserCache = (dat) => {
360
+ const id = "userInfo" + dat;
361
+
362
+ return new Promise((resolve, reject) => {
363
+ FNR.cache.useData(id, cache).then(
364
+ (result) => {
365
+ resolve(result);
366
+ },
367
+ (err) => {
368
+ getData().then((data) => {
369
+ FNR.cache.setData(id, data);
370
+
371
+ resolve(data);
372
+ });
373
+ }
374
+ );
375
+ });
376
+ };
377
+
378
+ return readUserCache(name);
379
+ },
380
+ changeAccount: (out, username, password) => {
381
+ return new Promise((resolve, reject) => {
382
+ let save = document.createElement('iframe');
383
+
384
+ save.id = 'forum-save';
385
+ save.src = out;
386
+ save.width = 0;
387
+ save.height = 0;
388
+ save.onload = () => {
389
+ save.onload = () => {
390
+ save.onload = () => {
391
+ console.clear();
392
+
393
+ resolve(true);
394
+ };
395
+
396
+ $('#forum-save').contents().find('input[name="username"]').val(username);
397
+ $('#forum-save').contents().find('input[name="password"]').val(password);
398
+ $('#forum-save').contents().find('input[type="submit"][name="login"]').click();
399
+ };
400
+
401
+ saveDOM.src = '/login?change_version=invision';
402
+ };
403
+
404
+ document.querySelector('body > header').prepend(save);
405
+
406
+ const saveDOM = document.getElementById('forum-save');
407
+ });
408
+ },
409
+ profile: {
410
+ getData: (array) => {
411
+ return new Promise((resolve, reject) => {
412
+ $.get('/profile?change_version=invision&mode=editprofile', (data) => {
413
+ const fields = data;
414
+
415
+ $.get('/profile?change_version=invision&mode=editprofile&page_profil=avatars', (data) => {
416
+ const avatar = data;
417
+
418
+ let result = [];
419
+
420
+ [].forEach.call(array, (item) => {
421
+ let value = '',
422
+ options = [];
423
+
424
+ switch (item.type) {
425
+ case 'input':
426
+ value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('input').val();
427
+ break;
428
+
429
+ case 'textarea':
430
+ value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('textarea').val();
431
+ break;
432
+
433
+ case 'select':
434
+ value = $(fields).find('dl:contains("' + item.name + '")').find('dd').find('select option:selected').attr('value');
435
+
436
+ $(fields).find('dl:contains("' + item.name + '")').find('dd').find('select option').each(function() {
437
+ if ($(this).attr('value') === '') return;
438
+
439
+ options.push({
440
+ name: $(this).text(),
441
+ value: $(this).attr('value')
442
+ });
443
+ });
444
+ break;
445
+
446
+ case 'avatar':
447
+ value = $(avatar).find('.box-content img').attr('src');
448
+ break;
449
+ }
450
+
451
+ if (item.type === 'select' && value === undefined || item.type === 'select' && value === '') return;
452
+
453
+ let final = {
454
+ type: item.type,
455
+ name: item.name,
456
+ value: value
457
+ };
458
+
459
+ if (item.validation) {
460
+ final.validation = item.validation;
461
+ }
462
+
463
+ if (options.length) {
464
+ final.options = options;
465
+ }
466
+
467
+ result.push(final);
468
+ });
469
+
470
+ resolve(result);
471
+ });
472
+ });
473
+ });
474
+ },
475
+ setData: (array) => {
476
+ return new Promise((resolve, reject) => {
477
+ const resolveSetter = () => {
478
+ $('#forum-save').remove();
479
+
480
+ console.clear();
481
+
482
+ resolve(true);
483
+ };
484
+
485
+ let save = document.createElement('iframe');
486
+
487
+ save.id = 'forum-save';
488
+ save.src = '/profile?change_version=invision&mode=editprofile';
489
+ save.width = 0;
490
+ save.height = 0;
491
+ save.onload = () => {
492
+ let avatar = false;
493
+
494
+ [].forEach.call(array, (item) => {
495
+ switch (item.type) {
496
+ case 'input':
497
+ $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('input').first().val(item.value);
498
+ break;
499
+
500
+ case 'textarea':
501
+ $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('textarea').val(item.value);
502
+ break;
503
+
504
+ case 'select':
505
+ $('#forum-save').contents().find('dl:contains("' + item.name + '")').find('dd').find('select option[value="' + item.value + '"]').attr('selected', 'selected');
506
+ break;
507
+
508
+ case 'avatar':
509
+ avatar = item.value;
510
+ break;
511
+ }
512
+ });
513
+
514
+ saveDOM.onload = () => {
515
+ if (!avatar) {
516
+ resolveSetter();
517
+ } else {
518
+ saveDOM.onload = () => {
519
+ saveDOM.onload = () => {
520
+ resolveSetter();
521
+ }
522
+
523
+ $('#forum-save').contents().find('input[name="avatarremoteurl"]').val(avatar);
524
+ $('#forum-save').contents().find('input[type="submit"][value="Registrar"]').click();
525
+ }
526
+
527
+ saveDOM.src = '/profile?change_version=invision&mode=editprofile&page_profil=avatars';
528
+ }
529
+ };
530
+
531
+ $('#forum-save').contents().find('input[type="submit"][value="Registrar"]').click();
532
+ };
533
+
534
+ document.querySelector('body > header').prepend(save);
535
+
536
+ const saveDOM = document.getElementById('forum-save');
537
+ });
538
+ },
539
+ getDrafts: () => {
540
+ return new Promise((resolve, reject) => {
541
+ $.get('/search?search_id=draftsearch&change_version=invision', (data) => {
542
+ if (parseFloat($(data).find('.maintitle > h3').text()) !== 0) {
543
+ let final = [];
544
+
545
+ $(data).find('.ipbform .ipbtable tbody > tr').each(function() {
546
+ const cells = $(this).find('td');
547
+
548
+ final.push({
549
+ topic: {
550
+ name: cells[1].textContent.trim(),
551
+ url: Vue.filter('url-to-normal')(cells[1].querySelector('a').href)
552
+ },
553
+ info: {
554
+ location: cells[2].textContent.trim(),
555
+ date: cells[3].textContent.trim()
556
+ },
557
+ modify: Vue.filter('url-to-normal')(cells[4].querySelector('a').href)
558
+ });
559
+ });
560
+
561
+ resolve(final);
562
+ } else {
563
+ resolve(false);
564
+ }
565
+ });
566
+ });
567
+ }
568
+ }
569
+ },
570
+ cache: {
571
+ getData: (id) => {
572
+ if (localStorage.getItem(forumData.prefix + '_' + id) === null) return false;
573
+ else return JSON.parse(localStorage.getItem(forumData.prefix + '_' + id)).content;
574
+ },
575
+ setData: (id, data, time) => {
576
+ let cur_date = time === -1 ? 'undefined' : new Date().getTime();
577
+
578
+ localStorage.setItem(
579
+ forumData.prefix + '_' + id,
580
+ JSON.stringify({
581
+ cached_at: cur_date,
582
+ content: data,
583
+ })
584
+ );
585
+ },
586
+ delData: (id) => {
587
+ if (localStorage.getItem(forumData.prefix + '_' + id) === null) return false;
588
+ else return localStorage.removeItem(forumData.prefix + '_' + id);
589
+ },
590
+ useData: (id, time) => {
591
+ return new Promise((resolve, reject) => {
592
+ let item = localStorage.getItem(forumData.prefix + '_' + id),
593
+ cur_date = new Date(),
594
+ timeMil = time == -1 ? 'undefined' : time * 86400000;
595
+
596
+ if ((item != null && time == -1) || (item != null && parseInt(JSON.parse(item).cached_at) + timeMil > cur_date.getTime())) {
597
+ resolve(JSON.parse(item).content);
598
+ } else {
599
+ reject(false);
600
+ }
601
+ });
602
+ },
603
+ },
604
+ utility: {
605
+ genSlug: (text, alt) => {
606
+ const slug = (Q) => {
607
+ const R = '\xE0\xE1\xE4\xE2\xE8\xE9\xEB\xEA\xEC\xED\xEF\xEE\xF2\xF3\xF6\xF4\xF9\xFA\xFC\xFB\xF1\xE7\xB7/_,:;';
608
+ Q = Q.trim().toLowerCase();
609
+ for (var T = 0, U = R.length; T < U; T++) Q = Q.replace(new RegExp(R.charAt(T), 'g'), 'aaaaeeeeiiiioooouuuunc------'.charAt(T));
610
+ return Q.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-');
611
+ };
612
+
613
+ const replace = alt || '_';
614
+
615
+ return slug(text).replace(/-/g, replace);
616
+ },
617
+ genArray: (string) => {
618
+ return JSON.parse(string.replace(/`/g, '"'));
619
+ },
620
+ genValidation: (array) => {
621
+ let final = '';
622
+
623
+ [].forEach.call(array, (item) => {
624
+ switch (item.validation) {
625
+ case 'hex':
626
+ if (!item.value.match(/^#[a-f0-9]{6}$/i)) {
627
+ final += '<li>El campo de ' + item.name.toLowerCase() + ' debe incluir un código de color hexadecimal.</li>';
628
+ }
629
+ break;
630
+
631
+ case 'img':
632
+ if (!item.value.match(/(jpg|jpeg|png)$/i)) {
633
+ final += '<li>El campo de ' + item.name.toLowerCase() + ' debe ser el enlace a una imagen (formato png, jpg o jpeg).</li>';
634
+ }
635
+ break;
636
+ }
637
+ });
638
+
639
+ return final;
640
+ },
641
+ getGroup: (color) => {
642
+ const returnHexVer = (code) => {
643
+ let status = 'unknown';
644
+
645
+ Object.values(forumColours).map((item) => {
646
+ if (item.hex === code.toLowerCase()) status = FNR.utility.genSlug(item.code);
647
+ });
648
+
649
+ return status;
650
+ };
651
+
652
+ const returnIdVer = (code) => {
653
+ let status = 'unknown';
654
+
655
+ Object.values(forumColours).map((item) => {
656
+ if (item.id === code) status = FNR.utility.genSlug(item.code);
657
+ });
658
+
659
+ return status;
660
+ };
661
+
662
+ if (color === undefined) return 'unknown';
663
+ else if (color.indexOf('#') > -1) return returnHexVer(color);
664
+ else if (color.indexOf('id_') > -1) return returnIdVer(parseFloat(color.split('_')[1]));
665
+ else if (forumColours[color] === undefined) return 'unknown';
666
+ else return FNR.utility.genSlug(forumColours[color].code);
667
+ }
668
+ },
669
+ html: {
670
+ genModal: (title, content, buttons) => {
671
+ if (title === '' || title === undefined || title === null) return;
672
+ if (content === '' || content === undefined || content === null) return;
673
+
674
+ let modal = document.createElement('div');
675
+
676
+ modal.id = 'forum-modal';
677
+
678
+ document.body.appendChild(modal);
679
+
680
+ let final = '';
681
+
682
+ final += '<div id="' + FNR.utility.genSlug(title, '-') + '" class="modal-element">';
683
+ final += '<div class="modal-title">';
684
+ final += '<h3>' + title + '</h3>';
685
+ final += '<a onclick="document.getElementById(`forum-modal`).remove()">';
686
+ final += '<i class="fas fa-times"></i>';
687
+ final += '</a>';
688
+ final += '</div>';
689
+ final += '<div class="modal-content">';
690
+ final += '<div class="is-content">';
691
+ final += content.replace(/\n/g, '<br>');
692
+ final += '</div>';
693
+
694
+ if (buttons !== '' && buttons !== undefined && buttons !== null) {
695
+ final += '<div class="modal-buttons">';
696
+ final += buttons;
697
+ final += '</div>';
698
+ }
699
+
700
+ final += '</div>';
701
+ final += '</div>';
702
+
703
+ final += '<div class="is-bgmodal bg-active" onclick="document.getElementById(`forum-modal`).remove()"></div>';
704
+
705
+ document.getElementById('forum-modal').innerHTML = final;
706
+ },
707
+ genPrompt: (title, content, placeholder, text) => {
708
+ if (title === '' || title === undefined || title === null) return;
709
+ if (content === '' || content === undefined || content === null) return;
710
+
711
+ return new Promise((resolve, reject) => {
712
+ FNR.html.genModal(title, '<p>' + content + '</p><p><input id="modal-prompt" type="text" placeholder="' + placeholder + '" value="' + text + '"></p>', '<button id="modal-button-enter" class="button1 btn-main">Confirmar</button><button id="modal-button-cancel" class="button1">Cancelar</button>');
713
+
714
+ document.querySelector('#modal-button-enter').onclick = () => {
715
+ const result = document.querySelector('#modal-prompt').value;
716
+
717
+ if (result === '') {
718
+ resolve(false);
719
+ } else {
720
+ resolve(result);
721
+ }
722
+
723
+ document.getElementById(`forum-modal`).remove();
724
+ };
725
+
726
+ document.querySelector('#modal-button-cancel').onclick = () => {
727
+ reject(false);
728
+ document.getElementById(`forum-modal`).remove();
729
+ };
730
+
731
+ document.querySelector('.modal-title a').onclick = () => {
732
+ reject(false);
733
+ document.getElementById(`forum-modal`).remove();
734
+ };
735
+
736
+ document.querySelector('.is-bgmodal.bg-active').onclick = () => {
737
+ reject(false);
738
+ document.getElementById(`forum-modal`).remove();
739
+ };
740
+ });
741
+ },
742
+ genNotification: (title, content, icon, url) => {
743
+ if (title === '' || title === undefined || title === null) return;
744
+ if (content === '' || content === undefined || content === null) return;
745
+ if (content.length > 50) return;
746
+ if (icon === '' || icon === undefined || icon === null) return;
747
+
748
+ if (document.querySelectorAll('forum-notification').length) {
749
+ document.getElementById('forum-notification').remove();
750
+ clearTimeout();
751
+ }
752
+
753
+ let notification = document.createElement('div');
754
+
755
+ notification.id = 'forum-notification';
756
+
757
+ document.body.appendChild(notification);
758
+
759
+ let final = '';
760
+
761
+ if (url === '' || url === undefined || url === null) {
762
+ final += '<div id="' + FNR.utility.genSlug(title, '-') + '" class="notification-element" onclick="document.querySelector(`#forum-notification`).classList.remove(`notification-show`)" >';
763
+ } else {
764
+ final += '<a href="' + url + '" target="_blank" id="' + FNR.utility.genSlug(title, '-') + '" class="notification-element" onclick="document.querySelector(`#forum-notification`).classList.remove(`notification-show`)" >';
765
+ }
766
+
767
+ final += '<div class="notification-icon">';
768
+ final += '<i class="' + icon + '"></i>';
769
+ final += '</div>';
770
+ final += '<div class="notification-content">';
771
+ final += '<h3>' + title + '</h3>';
772
+ final += '<p>' + content + '</p>';
773
+ final += '</div>';
774
+ final += '<div class="notification-controls">';
775
+ final += '<i class="fas fa-times"></i>';
776
+ final += '</div>';
777
+
778
+ if (url === '' || url === undefined || url === null) {
779
+ final += '</div>';
780
+ } else {
781
+ final += '</a>';
782
+ }
783
+
784
+ document.getElementById('forum-notification').innerHTML = final;
785
+
786
+ setTimeout(() => {
787
+ document.getElementById(`forum-notification`).classList.add('notification-show');
788
+ }, 500);
789
+
790
+ setTimeout(() => {
791
+ document.getElementById(`forum-notification`).classList.remove('notification-show');
792
+ }, 8000);
793
+
794
+ setTimeout(() => {
795
+ document.getElementById(`forum-notification`).remove();
796
+ }, 10000);
797
+ }
798
+ },
799
+ behaviour: {
800
+ genWiki: () => {
801
+ if (document.querySelector('.wiki-cascade')) {
802
+ [].forEach.call(document.getElementsByClassName('wiki-cascade'), (item) => {
803
+ item.onclick = () => {
804
+ const element = item.parentElement.parentElement;
805
+
806
+ if (element.classList.contains('is-active')) {
807
+ element.classList.remove('is-active');
808
+ } else {
809
+ element.classList.add('is-active');
810
+ }
811
+ };
812
+ });
813
+ }
814
+
815
+ if (document.querySelector('.wiki-controls .router-link-active')) {
816
+ [].forEach.call(document.querySelectorAll('.wiki-controls .router-link-active'), (item) => {
817
+ if (!item.parentElement.parentElement.parentElement.parentElement.parentElement.classList.contains('wiki-index')) {
818
+ const setActive = (element, isFirst) => {
819
+ let parentElement = element.parentElement.parentElement;
820
+
821
+ if (isFirst) {
822
+ parentElement = parentElement.parentElement.parentElement;
823
+ }
824
+
825
+ parentElement.classList.add('is-active');
826
+ parentElement.classList.add('is-selected');
827
+
828
+ if (!parentElement.parentElement.parentElement.parentElement.classList.contains('wiki-index')) {
829
+ setActive(parentElement, false);
830
+ }
831
+ };
832
+
833
+ setActive(item, true);
834
+ }
835
+ });
836
+ }
837
+
838
+ if (document.querySelector('aside.wiki-index > .select-container > select')) {
839
+ document.querySelector('aside.wiki-index > .select-container > select').onchange = () => {
840
+ router.push(document.querySelector('aside.wiki-index > .select-container > select').value);
841
+ };
842
+ }
843
+ },
844
+ genDropeable: () => {
845
+ if (document.querySelector('.is-dropeable')) {
846
+ [].forEach.call(document.getElementsByClassName('is-dropeable'), (item) => {
847
+ item.onclick = () => {
848
+ if (!item.classList.contains('is-active')) {
849
+ [].forEach.call(document.getElementsByClassName('is-dropeable'), (drops) => {
850
+ drops.classList.remove('is-active');
851
+ });
852
+
853
+ item.classList.add('is-active');
854
+ } else {
855
+ item.classList.remove('is-active');
856
+ }
857
+ };
858
+ });
859
+ }
860
+ }
861
+ }
864
862
  };