diff options
author | luxagraf <sng@luxagraf.net> | 2023-07-27 10:54:16 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-07-27 10:54:16 -0500 |
commit | 5be880ce1fabeb5eb4f1254f74c0212d1b71892b (patch) | |
tree | 71d4ae919645554e831ebb9f7d48ccbf1bdd3661 | |
parent | 94dc3eb97f4ddb09da3dde887703e95d5a876576 (diff) |
deals: made a bookmarklet to generate deal code markdown
-rw-r--r-- | app/deals/templates/deals/deal_code.html | 58 | ||||
-rw-r--r-- | app/deals/urls.py | 5 | ||||
-rw-r--r-- | app/deals/views.py | 5 |
3 files changed, 68 insertions, 0 deletions
diff --git a/app/deals/templates/deals/deal_code.html b/app/deals/templates/deals/deal_code.html new file mode 100644 index 0000000..2ab33e2 --- /dev/null +++ b/app/deals/templates/deals/deal_code.html @@ -0,0 +1,58 @@ +{% load humanize %} +<html> + <head> +<style> +body { + padding-top: 30px; +} +.button { + color: white; + padding: 1rem; + text-decoration: none; + background-color: #2ea44f; + border: 1px solid rgba(27, 31, 35, .15); + border-radius: 6px; + box-shadow: rgba(27, 31, 35, .1) 0 1px 0; + box-sizing: border-box; + color: #fff; + cursor: pointer; + display: inline-block; + font-family: -apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; + font-size: 14px; + font-weight: 600; + line-height: 20px; + padding: 6px 16px; + position: relative; + text-align: center; + text-decoration: none; + user-select: none; + -webkit-user-select: none; + touch-action: manipulation; + vertical-align: middle; + white-space: nowrap; +} +</style> + </head> + <body> +<a class="button" href="#" onclick="CopyToClipboard('markdown');return false;">Copy Markdown</a> + +<textarea id="markdown" style="min-width: 35rem; height: 15rem;"> + +</textarea> + +<script> +let params = new URL(document.location).searchParams; +var str = "####"+" ["+params.get("title")+"]("+params.get("url")+")\n\n+++button-group\n\n[Amazon]("+params.get("url")+" \"Amazon\"){: target=\"_blank\"}\n\n+++"; +document.getElementById('markdown').value = str +function CopyToClipboard(id) +{ +var r = document.createRange(); +r.selectNode(document.getElementById(id)); +window.getSelection().removeAllRanges(); +window.getSelection().addRange(r); +document.execCommand('copy'); +window.getSelection().removeAllRanges(); +} +</script> +</body> +</html> diff --git a/app/deals/urls.py b/app/deals/urls.py index 8ca1fca..277e1c4 100644 --- a/app/deals/urls.py +++ b/app/deals/urls.py @@ -6,6 +6,11 @@ app_name = "deals" urlpatterns = [ path( + r'deal', + views.GenerateDealCodeView.as_view(), + name="code" + ), + path( r'mydeals', views.MyDealListView.as_view(), name="detail" diff --git a/app/deals/views.py b/app/deals/views.py index 10b02c9..bf0a4c8 100644 --- a/app/deals/views.py +++ b/app/deals/views.py @@ -1,4 +1,5 @@ from django.views.generic import DetailView, ListView +from django.views.generic.base import TemplateView from .models import Deal, MyDeal @@ -12,3 +13,7 @@ class MyDealListView(ListView): class MyDealLapListView(ListView): model = MyDeal queryset = MyDeal.objects.filter(asin="newbest") + + +class GenerateDealCodeView(TemplateView): + template_name = "deals/deal_code.html" |