mirror of
https://github.com/yusufipk/AndroidAcikKalsin.git
synced 2026-09-11 10:46:13 +00:00
feat: improve share URL resolution with base attribute priority
This commit is contained in:
+22
-14
@@ -134,18 +134,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function resolveShareUrl() {
|
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') {
|
if (window.location.protocol !== 'file:' && window.location.origin && window.location.origin !== 'null') {
|
||||||
return window.location.href;
|
return window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
const base = document.body?.dataset.shareBase;
|
const relativePath = window.location.pathname.replace(/^\//, '') || 'index.html';
|
||||||
if (!base) {
|
|
||||||
|
try {
|
||||||
|
return new URL(relativePath, window.location.href).toString();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Paylaşım adresi oluşturulamadı:', error);
|
||||||
return window.location.href;
|
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
|
// Simplify CTA boxes that only contain buttons
|
||||||
@@ -276,25 +283,26 @@ document.querySelectorAll('img').forEach(img => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function resolveShareUrl() {
|
function resolveShareUrl() {
|
||||||
|
const baseAttr = document.body?.dataset.shareBase;
|
||||||
|
const preferredBase = baseAttr ? baseAttr.trim() : '';
|
||||||
const isFileProtocol = window.location.protocol === 'file:';
|
const isFileProtocol = window.location.protocol === 'file:';
|
||||||
const hasValidOrigin = window.location.origin && window.location.origin !== 'null';
|
const hasValidOrigin = window.location.origin && window.location.origin !== 'null';
|
||||||
|
|
||||||
|
if (preferredBase) {
|
||||||
|
return preferredBase;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isFileProtocol && hasValidOrigin) {
|
if (!isFileProtocol && hasValidOrigin) {
|
||||||
return window.location.href;
|
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';
|
const relativePath = window.location.pathname.replace(/^\//, '') || 'index.html';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new URL(relativePath, normalizedBase).toString();
|
return new URL(relativePath, window.location.href).toString();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Paylaşım adresi oluşturulamadı:', error);
|
console.error('Paylaşım adresi oluşturulamadı:', error);
|
||||||
return normalizedBase;
|
return window.location.href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user