From d3de5235a5d1c9b2cc8e54f496b142e9a8e36f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0pek?= Date: Fri, 31 Oct 2025 23:33:58 +0300 Subject: [PATCH] feat: update share base URL and improve share functionality - Update share base URL from androidacikkalsin.org to ozgurandroid.yusufipek.me - Add resolveShareUrl function to handle file protocol and invalid origins - Improve clipboard API support with fallback mechanisms - Add popup detection for Twitter share dialog - Refactor copy functionality into reusable fallbackCopy function - Enhance error handling for share operations --- index.html | 2 +- js/script.js | 79 +++++++++++++++++++++++++++++++++++--------- sikayet-rehberi.html | 2 +- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 3efdf81..e5ce493 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ - +
diff --git a/js/script.js b/js/script.js index c29fc85..26f8bb3 100644 --- a/js/script.js +++ b/js/script.js @@ -270,10 +270,33 @@ document.addEventListener('DOMContentLoaded', function() { }); }); - document.querySelectorAll('img').forEach(img => { - imageObserver.observe(img); - }); +document.querySelectorAll('img').forEach(img => { + imageObserver.observe(img); }); +}); + +function resolveShareUrl() { + const isFileProtocol = window.location.protocol === 'file:'; + const hasValidOrigin = window.location.origin && window.location.origin !== 'null'; + + if (!isFileProtocol && hasValidOrigin) { + return window.location.href; + } + + const base = document.body ? document.body.dataset.shareBase : ''; + if (!base) { + return window.location.href; + } + + const normalizedBase = base.endsWith('/') ? base : `${base}/`; + const relativePath = window.location.pathname.replace(/^\//, '') || 'index.html'; + try { + return new URL(relativePath, normalizedBase).toString(); + } catch (error) { + console.error('Paylaşım adresi oluşturulamadı:', error); + return normalizedBase; + } +} // Share functionality function shareWebsite() { @@ -286,18 +309,18 @@ function shareWebsite() { } else { // Fallback for browsers that don't support Web Share API const url = resolveShareUrl(); - navigator.clipboard.writeText(url).then(() => { - showNotification('Link panoya kopyalandı!'); - }).catch(() => { - // Final fallback - const textarea = document.createElement('textarea'); - textarea.value = url; - document.body.appendChild(textarea); - textarea.select(); - document.execCommand('copy'); - document.body.removeChild(textarea); - showNotification('Link panoya kopyalandı!'); - }); + const clipboardSupported = navigator.clipboard && typeof navigator.clipboard.writeText === 'function'; + if (clipboardSupported) { + navigator.clipboard.writeText(url) + .then(() => { + showNotification('Link panoya kopyalandı!'); + }) + .catch(() => { + fallbackCopy(url); + }); + } else { + fallbackCopy(url); + } } } @@ -312,7 +335,31 @@ function shareHashtag() { } else { // Open Twitter/X share dialog const twitterUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}`; - window.open(twitterUrl, '_blank', 'width=550,height=420'); + const popup = window.open(twitterUrl, '_blank', 'width=550,height=420'); + if (!popup) { + fallbackCopy(shareUrl); + } + } +} + +function fallbackCopy(value) { + if (!value) { + return; + } + + try { + const textarea = document.createElement('textarea'); + textarea.value = value; + textarea.style.position = 'fixed'; + textarea.style.opacity = '0'; + document.body.appendChild(textarea); + textarea.select(); + document.execCommand('copy'); + document.body.removeChild(textarea); + showNotification('Link panoya kopyalandı!'); + } catch (error) { + console.error('Kopyalama başarısız:', error); + window.prompt('Bağlantıyı manuel kopyalayın:', value); } } diff --git a/sikayet-rehberi.html b/sikayet-rehberi.html index c4bf1de..fbf72cd 100644 --- a/sikayet-rehberi.html +++ b/sikayet-rehberi.html @@ -9,7 +9,7 @@ - +