summaryrefslogtreecommitdiffstats
path: root/assets/js/watched_widget.js
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-06-09 00:30:34 +0200
committerSamantaz Fox <coding@samantaz.fr>2022-06-09 00:30:34 +0200
commit2313ca8f72cec823bfd7ec0d46107e6f8ba490a1 (patch)
tree5ff05751e359323bccc2576094f0caebd5d4f0a9 /assets/js/watched_widget.js
parent7ad111e2f65c2688c7accb31ff75171c29f2cc26 (diff)
parenta402128a7d4a2d3dccbeeb553e5363447f501a37 (diff)
downloadinvidious-2313ca8f72cec823bfd7ec0d46107e6f8ba490a1.tar.gz
invidious-2313ca8f72cec823bfd7ec0d46107e6f8ba490a1.tar.bz2
invidious-2313ca8f72cec823bfd7ec0d46107e6f8ba490a1.zip
Merge pull request #3084 from AHOHNMYC/js-helpers-polyfills
JS refactoring part 2: helper functions, poyfills
Diffstat (limited to 'assets/js/watched_widget.js')
-rw-r--r--assets/js/watched_widget.js39
1 files changed, 11 insertions, 28 deletions
diff --git a/assets/js/watched_widget.js b/assets/js/watched_widget.js
index 87989a79..f1ac9cb4 100644
--- a/assets/js/watched_widget.js
+++ b/assets/js/watched_widget.js
@@ -1,5 +1,6 @@
'use strict';
var watched_data = JSON.parse(document.getElementById('watched_data').textContent);
+var payload = 'csrf_token=' + watched_data.csrf_token;
function mark_watched(target) {
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
@@ -7,45 +8,27 @@ function mark_watched(target) {
var url = '/watch_ajax?action_mark_watched=1&redirect=false' +
'&id=' + target.getAttribute('data-id');
- 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=' + watched_data.csrf_token);
+ });
}
function mark_unwatched(target) {
var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode;
tile.style.display = 'none';
var count = document.getElementById('count');
- count.innerText = count.innerText - 1;
+ count.textContent--;
var url = '/watch_ajax?action_mark_unwatched=1&redirect=false' +
'&id=' + target.getAttribute('data-id');
- 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) {
- count.innerText = count.innerText - 1 + 2;
- tile.style.display = '';
- }
+ helpers.xhr('POST', url, {payload: payload}, {
+ onNon200: function (xhr) {
+ count.textContent++;
+ tile.style.display = '';
}
- };
-
- xhr.send('csrf_token=' + watched_data.csrf_token);
+ });
}