diff --git a/scripts/templates/script.html b/scripts/templates/script.html index 91d63d9d..6bc27d4a 100644 --- a/scripts/templates/script.html +++ b/scripts/templates/script.html @@ -18,6 +18,12 @@ // Set the name of the page to the name & version of the script. document.title = "{{ script.name }} - v{{ script_version.version }}" + function decodeHtml(html) { + var txt = document.createElement("textarea"); + txt.innerHTML = html; + return txt.value; + } + function showAndDismissAlert(message) { var htmlAlert = '
' + message + '
'; @@ -29,9 +35,9 @@ $(".alert-messages .alert").first().hide().fadeIn(200).delay(2000).fadeOut(1000, function () { $(this).remove(); }); } - function CopyLink() { - navigator.clipboard.writeText("{{request.scheme}}://{{request.META.HTTP_HOST}}/api/scripts/{{script_version.pk}}/json/") - showAndDismissAlert("Link Copied to Clipboard") + function CopyLink(json) { + navigator.clipboard.writeText(decodeHtml(json)) + showAndDismissAlert("JSON Copied to Clipboard") } @@ -111,7 +117,7 @@

You

{% endif %}
- +
{% if script_version.edition > 2 %} {% if perms.scripts.download_unsupported_json %} diff --git a/scripts/views.py b/scripts/views.py index b35d00c0..4aae017f 100644 --- a/scripts/views.py +++ b/scripts/views.py @@ -34,6 +34,7 @@ from dataclasses import dataclass from typing import Dict, Any, List, Optional import requests +import json class ScriptsListView(SingleTableMixin, FilterView): @@ -261,6 +262,7 @@ def get_context_data(self, **kwargs): ) context["can_delete"] = self.request.user == current_script.script.owner + context["json"] = json.dumps(current_script.content) return context