From 3d8d56f356bc15d9ab66dcb0f50082843629abb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0pek?= Date: Fri, 31 Oct 2025 23:50:31 +0300 Subject: [PATCH] feat: improve share URL resolution with base attribute priority --- js/script.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/js/script.js b/js/script.js index 26f8bb3..cbc021c 100644 --- a/js/script.js +++ b/js/script.js @@ -134,18 +134,25 @@ document.addEventListener('DOMContentLoaded', function() { }); function resolveShareUrl() { + const baseAttr = document.body?.dataset.shareBase; + const preferredBase = baseAttr ? baseAttr.trim() : ''; + + if (preferredBase) { + return preferredBase; + } + if (window.location.protocol !== 'file:' && window.location.origin && window.location.origin !== 'null') { return window.location.href; } - const base = document.body?.dataset.shareBase; - if (!base) { + const relativePath = window.location.pathname.replace(/^\//, '') || 'index.html'; + + try { + return new URL(relativePath, window.location.href).toString(); + } catch (error) { + console.error('Paylaşım adresi oluşturulamadı:', error); return window.location.href; } - - const normalizedBase = base.endsWith('/') ? base : base + '/'; - const relativePath = window.location.pathname.replace(/^\//, '') || 'index.html'; - return new URL(relativePath, normalizedBase).toString(); } // Simplify CTA boxes that only contain buttons @@ -276,25 +283,26 @@ document.querySelectorAll('img').forEach(img => { }); function resolveShareUrl() { + const baseAttr = document.body?.dataset.shareBase; + const preferredBase = baseAttr ? baseAttr.trim() : ''; const isFileProtocol = window.location.protocol === 'file:'; const hasValidOrigin = window.location.origin && window.location.origin !== 'null'; + if (preferredBase) { + return preferredBase; + } + 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(); + return new URL(relativePath, window.location.href).toString(); } catch (error) { console.error('Paylaşım adresi oluşturulamadı:', error); - return normalizedBase; + return window.location.href; } }