summaryrefslogtreecommitdiffstats
path: root/assets/js/community.js
blob: 32fe4ebc316a53eb870621b70b6132c8feec713b (plain)
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
'use strict';
var community_data = JSON.parse(document.getElementById('community_data').textContent);

function hide_youtube_replies(event) {
    var target = event.target;

    var sub_text = target.getAttribute('data-inner-text');
    var inner_text = target.getAttribute('data-sub-text');

    var body = target.parentNode.parentNode.children[1];
    body.style.display = 'none';

    target.innerHTML = sub_text;
    target.onclick = show_youtube_replies;
    target.setAttribute('data-inner-text', inner_text);
    target.setAttribute('data-sub-text', sub_text);
}

function show_youtube_replies(event) {
    var target = event.target;

    var sub_text = target.getAttribute('data-inner-text');
    var inner_text = target.getAttribute('data-sub-text');

    var body = target.parentNode.parentNode.children[1];
    body.style.display = '';

    target.innerHTML = sub_text;
    target.onclick = hide_youtube_replies;
    target.setAttribute('data-inner-text', inner_text);
    target.setAttribute('data-sub-text', sub_text);
}

function get_youtube_replies(target, load_more) {
    var continuation = target.getAttribute('data-continuation');

    var body = target.parentNode.parentNode;
    var fallback = body.innerHTML;
    body.innerHTML =
        '<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';

    var url = '/api/v1/channels/comments/' + community_data.ucid +
        '?format=html' +
        '&hl=' + community_data.preferences.locale +
        '&thin_mode=' + community_data.preferences.thin_mode +
        '&continuation=' + continuation;

    helpers.xhr('GET', url, {}, {
        on200: function (response) {
            if (load_more) {
                body = body.parentNode.parentNode;
                body.removeChild(body.lastElementChild);
                body.innerHTML += response.contentHtml;
            } else {
                body.removeChild(body.lastElementChild);

                var p = document.createElement('p');
                var a = document.createElement('a');
                p.appendChild(a);

                a.href = 'javascript:void(0)';
                a.onclick = hide_youtube_replies;
                a.setAttribute('data-sub-text', community_data.hide_replies_text);
                a.setAttribute('data-inner-text', community_data.show_replies_text);
                a.textContent = community_data.hide_replies_text;

                var div = document.createElement('div');
                div.innerHTML = response.contentHtml;

                body.appendChild(p);
                body.appendChild(div);
            }
        },
        onNon200: function (xhr) {
            body.innerHTML = fallback;
        },
        onTimeout: function (xhr) {
            console.warn('Pulling comments failed');
            body.innerHTML = fallback;
        }
    });
}
gsubject'>Update Polish translationHosted Weblate Update Polish translation Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Matthaiks <kitynska@gmail.com> 2024-04-25Update Hindi translationHosted Weblate Update Hindi translation Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Scrambled777 <weblate.scrambled777@simplelogin.com> 2024-04-25Update Croatian translationHosted Weblate Update Croatian translation Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Milo Ivir <mail@milotype.de> 2024-04-25Update Vietnamese translationHosted Weblate Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Knight Hat <knightchanelgaming@gmail.com> 2024-04-25Update Portuguese translationHosted Weblate Update Portuguese translation Update Portuguese translation Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Samantaz Fox <translator-weblate@samantaz.fr> Co-authored-by: Sergio Marques <so.boston.android@gmail.com> 2024-04-25Update Czech translationHosted Weblate Update Czech translation Co-authored-by: Fjuro <fjuro@alius.cz> Co-authored-by: Hosted Weblate <hosted@weblate.org> 2024-04-25Update Japanese translationHosted Weblate Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: maboroshin <maboroshin@users.noreply.hosted.weblate.org> 2024-04-25Update Ukrainian translationHosted Weblate Update Ukrainian translation Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Ihor Hordiichuk <igor_ck@outlook.com> Co-authored-by: Samantaz Fox <translator-weblate@samantaz.fr> 2024-04-25Update Bengali translationHosted Weblate Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Tauhid Alam Rifty <tauhidalamrifty@gmail.com> 2024-04-25Update Romanian translationHosted Weblate Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Wiktor Muzynski <wiktormuzynski@gmail.com> 2024-04-25Update Basque translationHosted Weblate Co-authored-by: Samantaz Fox <translator-weblate@samantaz.fr> 2024-04-25Update Danish translationHosted Weblate Co-authored-by: Samantaz Fox <translator-weblate@samantaz.fr> 2024-04-25Update German translationHosted Weblate Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Lenny Angst <lenny@familie-angst.ch> 2024-04-25Update Portuguese (Brazil) translationHosted Weblate Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Update Portuguese (Brazil) translation Co-authored-by: André Marcelo Alvarenga <andrealvarenga@gmx.net> Co-authored-by: Hosted Weblate <hosted@weblate.org> Co-authored-by: Jose Delvani <delvani.eletricista@gmail.com> Co-authored-by: joaooliva <joaooliva@protonmail.com>