Skip to content

Commit cba3b13

Browse files
authored
Add files via upload
1 parent 7db3690 commit cba3b13

File tree

1 file changed

+86
-23
lines changed

1 file changed

+86
-23
lines changed

assets/js/dynamicContentLoader.js

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,88 @@
1-
// Get the query parameters from the URL
2-
const params = new URLSearchParams(window.location.search);
3-
const page = params.get('page'); // Extract the 'page' parameter
4-
// Select all articles
5-
const articles = document.querySelectorAll('article');
6-
// Default section if no valid page is provided
7-
const defaultPage = 'about';
8-
// Flag to check if a matching page was found
9-
let isPageFound = false;
10-
// Loop through articles to show the matched one
11-
articles.forEach(article => {
12-
if (article.dataset.page === page) {
13-
article.classList.add('active'); // Add 'active' class to show
14-
isPageFound = true; // A matching page was found
15-
} else {
16-
article.classList.remove('active'); // Hide other sections
17-
}
18-
});
19-
// Show the default page if no matching page was found
20-
if (!isPageFound) {
21-
const defaultArticle = document.querySelector(article[data-page="${defaultPage}"]);
22-
if (defaultArticle) {
23-
defaultArticle.classList.add('active');
1+
const q = new URLSearchParams(window.location.search);
2+
const s = q.get('s');
3+
const p = q.get('p');
4+
const t = q.get('t');
5+
const h = q.get('h');
6+
7+
document.addEventListener('DOMContentLoaded', () => {
8+
if (s === '0') {
9+
const sidebar = document.querySelector('.sidebar');
10+
if (sidebar) sidebar.style.display = 'none';
11+
}
12+
13+
let found = false;
14+
document.querySelectorAll('article').forEach(article => {
15+
if (article.dataset.page === p) {
16+
article.classList.add('active');
17+
found = true;
18+
if (t) {
19+
const title = article.querySelector('#customTitle');
20+
if (title) title.textContent = decodeURIComponent(t);
2421
}
22+
} else {
23+
article.classList.remove('active');
24+
}
25+
});
26+
27+
if (!found) {
28+
const defaultArticle = document.querySelector('article[data-page="about"]');
29+
if (defaultArticle) defaultArticle.classList.add('active');
30+
}
31+
32+
if (h) {
33+
try {
34+
const decrypted = CryptoJS.AES.decrypt(h, 'utf8').toString(CryptoJS.enc.Utf8);
35+
const decompressed = LZString.decompressFromBase64(decrypted);
36+
document.getElementById('contentArea').innerHTML = decompressed || '<p>Error decoding content.</p>';
37+
} catch {
38+
document.getElementById('contentArea').innerHTML = '<p>Error decoding content.</p>';
2539
}
40+
} else {
41+
document.getElementById('contentArea').innerHTML = '<p>No HTML content found in the URL.</p>';
42+
}
43+
});
44+
45+
//Make yours!!
46+
document.getElementById('cook').addEventListener('click', function () {
47+
const input = document.getElementById('htmlInput').value;
48+
const pageTitle = document.getElementById('pageTitle').value;
49+
if (!input) {
50+
alert('Enter HTML content');
51+
return;
52+
}
53+
const currentUrl = window.location.origin + window.location.pathname;
54+
const compressed = LZString.compressToBase64(input);
55+
const encrypted = CryptoJS.AES.encrypt(compressed, 'utf8').toString();
56+
const url = `${(currentUrl)}?p=1&t=${encodeURIComponent(pageTitle)}&h=${encodeURIComponent(encrypted)}`;
57+
document.getElementById("cook").style.display = "none";
58+
document.getElementById("preview").style.display = "flex";
59+
document.getElementById("share").style.display = "flex";
60+
document.getElementById('output').value = url;
61+
document.getElementById("preview").addEventListener("click", openPreview);
62+
document.getElementById("share").addEventListener("click", share);
63+
function openPreview() { window.open(url, "_blank"); }
64+
function share() {
65+
if (navigator.share) {
66+
navigator.share({
67+
title: 'Gift Share',
68+
text: `title!`,
69+
url: url
70+
}).then(() => {
71+
console.log('Share was successful');
72+
}).catch((error) => {
73+
console.log('Error sharing:', error);
74+
});
75+
} else {
76+
copyToClipboard(url);
77+
alert('Link copied to clipboard! You can now paste it anywhere to share.');
78+
}
79+
function copyToClipboard(text) {
80+
const textArea = document.createElement('textarea');
81+
textArea.value = text;
82+
document.body.appendChild(textArea);
83+
textArea.select();
84+
document.execCommand('copy');
85+
document.body.removeChild(textArea);
86+
}
87+
}
88+
});

0 commit comments

Comments
 (0)