diff --git a/static/script/share.js b/static/script/share.js
index ed884ed..6e7b5da 100644
--- a/static/script/share.js
+++ b/static/script/share.js
@@ -135,129 +135,4 @@ function roundRect(ctx, x, y, w, h, r, fill, stroke) {
ctx.closePath();
if (fill) ctx.fill();
if (stroke) ctx.stroke();
-}
-document.addEventListener('DOMContentLoaded', () => {
- const shareModal = document.getElementById('shareModal');
- const closeshareModal = document.getElementById('closeModal');
- const fb = document.getElementById('fb');
- const vk = document.getElementById('vk');
- const tg = document.getElementById('tg');
- const ok = document.getElementById('ok');
- const wa = document.getElementById('wa');
- const inst = document.getElementById('inst');
- const copyBtn = document.getElementById('copyBtn');
- const copyMsg = document.getElementById('copyMsg');
- function buildShareUrl(platform, url, text = '') {
- const u = encodeURIComponent(url);
- const t = encodeURIComponent(text);
- switch (platform) {
- case 'tw': return `https://twitter.com/intent/tweet?url=${u}&text=${t}`;
- case 'vk': return `https://vk.com/share.php?url=${u}&title=${t}`;
- case 'tg': return `https://telegram.me/share/url?url=${u}&text=${t}`;
- case 'fb': return `https://www.facebook.com/sharer/sharer.php?u=${u}"e=${t}`;
- case 'ok': return `https://connect.ok.ru/offer?url=${u}&title=${t}`;
- case 'wa': return `https://api.whatsapp.com/send?text=${t} ${u}`;
- case 'inst': return `https://www.instagram.com/?url=${u}`;
- default: return '#';
- }
- }
- const shareBtns = document.querySelectorAll('#shareBtn');
-shareBtns.forEach(btn => {
- btn.addEventListener('click', async () => {
- const link = window.location.origin + btn.dataset.link || window.location.href;
- const text = btn.dataset.text || document.title;
- const image = btn.dataset.image;
- const imagetext = btn.dataset.imagetext || '';
- let blob = null;
- let file = null;
- let objectUrl = null;
- try {
- if (image) {
- const imageUrl = window.location.origin + image;
- // В обработчике кнопки
- const blob = await imageWithTextBlob(imageUrl, imagetext, {
- textColor: '#5F1798',
- });
- console.log(`Generated blob for "${imagetext}" | size: ${blob.size} | url: ${imageUrl}`);
- const filename = `shared-image-${Date.now()}.png`;
- file = new File([blob], filename, { type: blob.type });
- // Создаём object URL только если хотим (необязательно для navigator.share)
- objectUrl = URL.createObjectURL(file);
- if (navigator.canShare && navigator.canShare({ files: [file] })) {
- await navigator.share({
- title: text,
- text: text,
- url: link,
- files: [file],
- });
- } else {
- await navigator.share({
- title: text,
- text: '',
- url: link,
- });
- }
- } else {
- await navigator.share({ title: text, text: '', url: link });
- }
- } catch (err) {
- openshareModal(link, text);
- } finally {
- // Очистка
- try {
- if (objectUrl) {
- URL.revokeObjectURL(objectUrl);
- objectUrl = null;
- }
- } catch (e) { /* ignore */ }
- // Удаляем ссылки, чтобы GC мог собрать объекты
- blob = null;
- file = null;
- }
- });
-});
- function openshareModal(link, text) {
- vk.href = buildShareUrl('vk', link, text);
- tg.href = buildShareUrl('tg', link, text);
- fb.href = buildShareUrl('fb', link, text);
- ok.href = buildShareUrl('ok', link, text);
- wa.href = buildShareUrl('wa', link, text);
- inst.href = buildShareUrl('inst', link, text);
- shareModal.style.display = 'flex';
- copyBtn.dataset.link = link;
- shareModal.style.display = 'flex'
- }
- closeshareModal.addEventListener('click', () => {
- shareModal.style.display = 'none';
- });
- shareModal.addEventListener('click', (e) => {
- if (e.target === shareModal) shareModal.style.display = 'none';
- });
- async function copyToClipboard(text) {
- try {
- if (navigator.clipboard && navigator.clipboard.writeText) {
- await navigator.clipboard.writeText(text);
- } else {
- const ta = document.createElement('textarea');
- ta.value = text;
- ta.style.position = 'fixed';
- ta.style.left = '-9999px';
- document.body.appendChild(ta);
- ta.select();
- document.execCommand('copy');
- document.body.removeChild(ta);
- }
- showCopyMessage();
- } catch (e) {
- showToast({message: 'Не удалось скопировать ссылку', status: 'error'});
- }
- }
- function showCopyMessage() {
- copyMsg.style.display = 'inline';
- setTimeout(() => copyMsg.style.display = 'none', 2000);
- }
- copyBtn.addEventListener('click', () => {
- const link = copyBtn.dataset.link || window.location.href;
- copyToClipboard(link);
- });
-});
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
index 1fd37f5..c37fde2 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -172,6 +172,131 @@ function showToast(e={}){let{message:t="",status:a="info",duration:l=4e3}=e,n=do
+