diff options
| author | Caian Benedicto <caianbene@gmail.com> | 2024-12-13 18:29:28 -0300 |
|---|---|---|
| committer | Caian Benedicto <caianbene@gmail.com> | 2024-12-13 20:26:52 -0300 |
| commit | d7f5cdc2f971af524c496aaeb25226eb9f8236df (patch) | |
| tree | 1e69d1088ee67407b1058f490cc188cd1dd4e287 /assets/js/playlist_widget.js | |
| parent | 78773d732672d8985795fb040a39dd7e946c7b7c (diff) | |
| parent | 98926047586154269bb269d01e3e52e60e044035 (diff) | |
| download | invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.tar.gz invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.tar.bz2 invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.zip | |
Merge branch 'master' into unix-sockets
Diffstat (limited to 'assets/js/playlist_widget.js')
| -rw-r--r-- | assets/js/playlist_widget.js | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/assets/js/playlist_widget.js b/assets/js/playlist_widget.js index 0ec27859..c92592ac 100644 --- a/assets/js/playlist_widget.js +++ b/assets/js/playlist_widget.js @@ -1,4 +1,6 @@ -var playlist_data = JSON.parse(document.getElementById('playlist_data').innerHTML); +'use strict'; +var playlist_data = JSON.parse(document.getElementById('playlist_data').textContent); +var payload = 'csrf_token=' + playlist_data.csrf_token; function add_playlist_video(target) { var select = target.parentNode.children[0].children[1]; @@ -7,21 +9,12 @@ function add_playlist_video(target) { var url = '/playlist_ajax?action_add_video=1&redirect=false' + '&video_id=' + target.getAttribute('data-id') + '&playlist_id=' + option.getAttribute('data-plid'); - var xhr = new XMLHttpRequest(); - xhr.responseType = 'json'; - xhr.timeout = 10000; - xhr.open('POST', url, true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status == 200) { - option.innerText = '✓' + option.innerText; - } + helpers.xhr('POST', url, {payload: payload}, { + on200: function (response) { + option.textContent = '✓' + option.textContent; } - } - - xhr.send('csrf_token=' + playlist_data.csrf_token); + }); } function add_playlist_item(target) { @@ -31,21 +24,12 @@ function add_playlist_item(target) { var url = '/playlist_ajax?action_add_video=1&redirect=false' + '&video_id=' + target.getAttribute('data-id') + '&playlist_id=' + target.getAttribute('data-plid'); - var xhr = new XMLHttpRequest(); - xhr.responseType = 'json'; - xhr.timeout = 10000; - xhr.open('POST', url, true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status != 200) { - tile.style.display = ''; - } + helpers.xhr('POST', url, {payload: payload}, { + onNon200: function (xhr) { + tile.style.display = ''; } - } - - xhr.send('csrf_token=' + playlist_data.csrf_token); + }); } function remove_playlist_item(target) { @@ -55,19 +39,10 @@ function remove_playlist_item(target) { var url = '/playlist_ajax?action_remove_video=1&redirect=false' + '&set_video_id=' + target.getAttribute('data-index') + '&playlist_id=' + target.getAttribute('data-plid'); - var xhr = new XMLHttpRequest(); - xhr.responseType = 'json'; - xhr.timeout = 10000; - xhr.open('POST', url, true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status != 200) { - tile.style.display = ''; - } + helpers.xhr('POST', url, {payload: payload}, { + onNon200: function (xhr) { + tile.style.display = ''; } - } - - xhr.send('csrf_token=' + playlist_data.csrf_token); -}
\ No newline at end of file + }); +} |
