diff --git a/changedetectionio/static/js/browser-steps.js b/changedetectionio/static/js/browser-steps.js index 4e576bd4..5c5fc52a 100644 --- a/changedetectionio/static/js/browser-steps.js +++ b/changedetectionio/static/js/browser-steps.js @@ -1,14 +1,5 @@ $(document).ready(function () { - // duplicate - var csrftoken = $('input[name=csrf_token]').val(); - $.ajaxSetup({ - beforeSend: function (xhr, settings) { - if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { - xhr.setRequestHeader("X-CSRFToken", csrftoken) - } - } - }) var browsersteps_session_id; var browser_interface_seconds_remaining = 0; var apply_buttons_disabled = false; diff --git a/changedetectionio/static/js/csrf.js b/changedetectionio/static/js/csrf.js new file mode 100644 index 00000000..4e2aca53 --- /dev/null +++ b/changedetectionio/static/js/csrf.js @@ -0,0 +1,10 @@ +$(document).ready(function () { + $.ajaxSetup({ + beforeSend: function (xhr, settings) { + if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { + xhr.setRequestHeader("X-CSRFToken", csrftoken) + } + } + }) +}); + diff --git a/changedetectionio/static/js/diff-overview.js b/changedetectionio/static/js/diff-overview.js index 95e6dd7a..1f501529 100644 --- a/changedetectionio/static/js/diff-overview.js +++ b/changedetectionio/static/js/diff-overview.js @@ -1,13 +1,4 @@ $(document).ready(function () { - var csrftoken = $('input[name=csrf_token]').val(); - $.ajaxSetup({ - beforeSend: function (xhr, settings) { - if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { - xhr.setRequestHeader("X-CSRFToken", csrftoken) - } - } - }) - $('.needs-localtime').each(function () { for (var option of this.options) { var dateObject = new Date(option.value * 1000); @@ -48,6 +39,12 @@ $(document).ready(function () { $("#highlightSnippet").remove(); } + // Listen for Escape key press + window.addEventListener('keydown', function (e) { + if (e.key === 'Escape') { + clean(); + } + }, false); function dragTextHandler(event) { console.log('mouseupped'); diff --git a/changedetectionio/static/js/notifications.js b/changedetectionio/static/js/notifications.js index d3a0b81a..95f3eacf 100644 --- a/changedetectionio/static/js/notifications.js +++ b/changedetectionio/static/js/notifications.js @@ -13,16 +13,6 @@ $(document).ready(function() { $('#send-test-notification').click(function (e) { e.preventDefault(); - // this can be global - var csrftoken = $('input[name=csrf_token]').val(); - $.ajaxSetup({ - beforeSend: function(xhr, settings) { - if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { - xhr.setRequestHeader("X-CSRFToken", csrftoken) - } - } - }) - data = { notification_body: $('#notification_body').val(), notification_format: $('#notification_format').val(), diff --git a/changedetectionio/templates/base.html b/changedetectionio/templates/base.html index 87018a7d..27ce8419 100644 --- a/changedetectionio/templates/base.html +++ b/changedetectionio/templates/base.html @@ -26,7 +26,11 @@ + + diff --git a/changedetectionio/tests/test_ignorehighlighter.py b/changedetectionio/tests/test_ignorehighlighter.py index 88bd0af6..52163845 100644 --- a/changedetectionio/tests/test_ignorehighlighter.py +++ b/changedetectionio/tests/test_ignorehighlighter.py @@ -45,7 +45,6 @@ def test_highlight_ignore(client, live_server): ) res = client.get(url_for("edit_page", uuid=uuid)) - # should be a regex now assert b'/oh\ yeah\ \d+/' in res.data @@ -55,3 +54,7 @@ def test_highlight_ignore(client, live_server): # And it should register in the preview page res = client.get(url_for("preview_page", uuid=uuid)) assert b'
oh yeah 456' in res.data + + # Should be in base.html + assert b'csrftoken' in res.data + diff --git a/requirements.txt b/requirements.txt index ae099de4..44049fb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -83,4 +83,4 @@ jsonschema==4.17.3 loguru # Needed for > 3.10, https://github.com/microsoft/playwright-python/issues/2096 -greenlet >= 3.0.3 \ No newline at end of file +greenlet >= 3.0.3