mirror of
https://github.com/yusufipk/AndroidAcikKalsin.git
synced 2026-09-11 10:46:13 +00:00
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
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
|
||||
</head>
|
||||
<body data-share-base="https://androidacikkalsin.org/">
|
||||
<body data-share-base="https://ozgurandroid.yusufipek.me/">
|
||||
<!-- Hero Section -->
|
||||
<section class="hero">
|
||||
<div class="container">
|
||||
|
||||
+58
-11
@@ -275,6 +275,29 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
});
|
||||
|
||||
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() {
|
||||
if (navigator.share) {
|
||||
@@ -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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
|
||||
</head>
|
||||
<body data-share-base="https://androidacikkalsin.org/">
|
||||
<body data-share-base="https://ozgurandroid.yusufipek.me/">
|
||||
<!-- Header -->
|
||||
<header class="guide-header">
|
||||
<div class="container">
|
||||
|
||||
Reference in New Issue
Block a user