Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
373 lines (322 loc) · 20.7 KB
/
Copy pathscript.js
File metadata and controls
373 lines (322 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// script.js
document.addEventListener('DOMContentLoaded', () => {
// --- Elements ---
const langButtons = document.querySelectorAll('.lang-button');
const translatableElements = document.querySelectorAll('[data-translate]');
const yearSpan = document.getElementById('current-year');
const themeToggleButton = document.getElementById('theme-toggle');
const bodyElement = document.body;
// --- Config for Persistent Parameters ---
const TRACKED_PARAMS_KEY = 'persistentUrlParams';
const ALLOWED_PARAMS = ['refCode', 'refcode', 'source', 'donation', 'lang', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
// --- Translations ---
const translations = {
en: {
profileName: "Julius Moshiro",
profileTagline: "Digital Creator | Atana Ventures",
resourceTitle: "What Are You Looking For?",
linkKarani: "Karani",
linkKaraniDesc: "Scan a receipt. Claim every shilling of VAT.",
linkMatukio: "Event Photography",
linkMatukioDesc: "Engagements, graduations & the short ones.",
linkStore: "Julius' Store",
linkStoreDesc: "Get: Digital Skills, Tools, Classes & More",
linkKidarasa: "Kidarasa",
linkKidarasaDesc: "Skills, Guides & More.",
linkMoney: "Money Mindset",
linkMoneyDesc: "Dialogues on Finance and Money.",
linkCollab: "About Julius",
linkCollabDesc: "My story, my work & an open invitation.",
footerRights: "All rights reserved.",
backLink: "Back",
/* --- About Julius --- */
aboutTitle: "About Julius",
aboutHello: "Habari. I’m Julius.",
aboutLede: "I’m a photographer, a builder of software, and an early-morning runner, based in Tanzania.",
aboutContentKicker: "Pictures & stories",
aboutContentTitle: "The camera came first",
aboutContentDesc: "Long before I wrote any software, I was the person at the back of the room with a camera, waiting for the moment people forget they are being photographed. That is still my favourite moment. It has taken me across Africa documenting work for teams at the European Union, the African Wildlife Foundation, the World Bank and the Bill & Melinda Gates Foundation — and also to weddings, send-offs and small family shops that never make the news. Different budgets, same job: pay attention, and tell the truth kindly.",
aboutSoftwareKicker: "Software",
aboutSoftwareTitle: "Then I started building the tools I wished existed",
aboutSoftwareDesc: "Somewhere along the way I got tired of watching good people lose whole days to bad systems — a shop owner copying receipts into a notebook at midnight, a creator handing a third of every sale to a platform that did nothing for them. So I started building. I am not interested in software that impresses other developers. I want software my aunt can use, on the phone she already owns, with two bars of signal.",
aboutNyotaTitle: "Nyota ✨",
aboutNyotaDesc: "A storefront you actually own. Sell courses, e-books, podcasts or templates — your customer pays with M-Pesa, Airtel Money, Mixx or a card and receives the file immediately.",
aboutStokiTitle: "Stoki 📦",
aboutStokiDesc: "Stock and sales, minus the expensive POS machine. Know what you have, what sold, and what is quietly disappearing — from the phone already in your pocket.",
aboutKaraniTitle: "Karani 🧾",
aboutKaraniDesc: "Every business has a silent thief: paperwork. Scan a receipt, Karani verifies it with TRA and files it, so nothing you paid for goes unclaimed.",
aboutKaraniLink: "Try Karani",
aboutBusinessKicker: "Entrepreneurship",
aboutBusinessTitle: "Business, the honest version",
aboutBusinessDesc: "I have learned more from the things that did not work than from the ones that did — and I try to talk about both. That is part of why Money Mindset exists: monthly conversations about money, the kind we usually only have in whispers. Building a business here is not a stage talk. It is pricing your work fairly, filing by the 20th, staying patient through a slow month, and choosing customers you would actually want to meet again.",
aboutCommunityKicker: "Community",
aboutCommunityTitle: "Nobody builds alone",
aboutCommunityDesc: "The best things I have made started as a conversation with someone else — over coffee, in a WhatsApp group, at the end of a morning run. So I keep the door open. I share what I learn while I am still learning it, I answer messages from people I have never met, and I would rather teach someone to build the thing than sell them the thing. You do not need to be technical, funded, fluent in English, or “ready”. Curiosity is the whole entry requirement.",
aboutInviteKicker: "An open invitation",
aboutInviteTitle: "Let’s make something together",
aboutInviteDesc: "If any of this sounds like your kind of thing, I would love to hear from you. Here is how it usually starts:",
aboutInvite1: "You have something worth documenting — a project, an event, a day that matters. Let’s shoot it.",
aboutInvite2: "You are drowning in a manual process. Let’s automate the boring part.",
aboutInvite3: "You are building something and want a second pair of eyes — or a co-conspirator.",
aboutInvite4: "You just want to talk shop — cameras, code, business, running. Coffee is on me.",
aboutInviteClose: "No pitch deck needed. Say hello, tell me what you are working on, and we will figure out the rest together.",
aboutCtaWhatsapp: "Send me a message",
storeTitle: "Julius' Store",
kidarasaTitle: "Kidarasa",
karaniTitle: "Karani",
karaniIntro: "Your business has a silent thief: paperwork. Karani automates receipt data entry, giving you back the hours to focus on your dream.",
returnHome: "Julius Moshiro",
returnHomeAria: "Back to Julius Moshiro's home page",
},
sw: {
profileName: "Julius Moshiro",
profileTagline: "Mwana Digitali | Atana Ventures",
resourceTitle: "Unatafuta Nini?",
linkKarani: "Karani",
linkKaraniDesc: "Piga picha ya risiti. Dai kila shilingi ya VAT.",
linkMatukio: "Picha za Matukio",
linkMatukioDesc: "Uchumba, mahafali na matukio mafupi.",
linkStore: "Julius' Store",
linkStoreDesc: "Jipatie: Ujuzi wa Kidigitali, Vifaa, Fremu na vinginevyo",
linkKidarasa: "Kidarasa",
linkKidarasaDesc: "Vijarida na Juzi tofauti",
linkMoney: "Money Mindset",
linkMoneyDesc: "Majadiliano ya kila mwezi kuhusu fikra na fedha.",
linkCollab: "Kuhusu Julius",
linkCollabDesc: "Hadithi yangu, kazi zangu & mwaliko wa wazi.",
footerRights: "Haki zote zimehifadhiwa.",
backLink: "Rudi",
/* --- Kuhusu Julius --- */
aboutTitle: "Kuhusu Julius",
aboutHello: "Habari. Mimi ni Julius.",
aboutLede: "Mimi ni mpiga picha, mtengenezaji wa programu zinazorahisisha kazi, na mkimbiaji, ninaishi Tanzania.",
aboutContentKicker: "Picha na Hadithi",
aboutContentTitle: "Kamera ilikuja kwanza",
aboutContentDesc: "Kabla sijaandika programu yoyote, nilikuwa yule mtu wa nyuma ya ukumbi mwenye kamera, nikisubiri dakika ile ambayo watu husahau kama wanapigwa picha. Hadi leo, hiyo ndiyo dakika ninayoipenda zaidi. Imenipeleka sehemu nyingi barani Afrika nikirekodi kazi za taasisi kama Umoja wa Ulaya (EU), African Wildlife Foundation, World Bank na Bill & Melinda Gates Foundation — na pia kwenye harusi, send-off, na maduka madogo ya kifamilia ambayo hayaandikwi kwenye habari. Bajeti zinatofautiana, lakini kazi ni ileile: kuwa makini, na kusimulia ukweli kwa upole.",
aboutSoftwareKicker: "Programu",
aboutSoftwareTitle: "Kisha nikaanza kutengeneza zana nilizotamani ziwepo",
aboutSoftwareDesc: "Njiani nilichoka kuona watu wazuri wakipoteza siku nzima kwa sababu ya mifumo mibovu — mfanyabiashara akiandika risiti kwenye daftari saa sita usiku, mbunifu akipoteza theluthi ya kila mauzo kwa jukwaa lisilomsaidia chochote. Ndipo nikaanza kujenga. Sivutiwi na programu zinazowashangaza watengenezaji wenzangu. Ninataka programu ambayo shangazi yangu anaweza kuitumia, kwa simu aliyo nayo tayari, hata kwa mtandao wa alama mbili.",
aboutNyotaTitle: "Nyota ✨",
aboutNyotaDesc: "Duka ambalo ni lako kweli. Uza kozi, vitabu (e-books), podikasti au 'templates' — mteja wako analipa kwa M-Pesa, Airtel Money, Mixx au kadi, na anapokea bidhaa yake papo hapo.",
aboutStokiTitle: "Stoki 📦",
aboutStokiDesc: "Stoki na mauzo, bila mashine ghali ya POS. Jua una nini, kimeuzwa nini, na nini kinapotea kimyakimya — kwa simu uliyo nayo mfukoni.",
aboutKaraniTitle: "Karani 🧾",
aboutKaraniDesc: "Kila biashara ina mwizi wa kimya: makaratasi. Piga picha ya risiti, Karani anaithibitisha na TRA na kuiweka kwenye rekodi, ili kila uliyolipia isipotee bure.",
aboutKaraniLink: "Jaribu Karani",
aboutBusinessKicker: "Ujasiriamali",
aboutBusinessTitle: "Biashara, kwa ukweli wake",
aboutBusinessDesc: "Nimejifunza zaidi kutoka kwenye mambo yaliyoshindikana kuliko yale yaliyofanikiwa — na najitahidi kuzungumzia yote mawili. Ndiyo sababu Money Mindset ipo: mazungumzo ya kila mwezi kuhusu fedha, yale ambayo mara nyingi tunayafanya kwa minong'ono. Kufanya biashara hapa si hotuba ya jukwaani. Ni kupanga bei ya haki kwa kazi yako, kuwasilisha kodi kabla ya tarehe 20, kuvumilia mwezi wa kigugumizi, na kuchagua wateja ambao ungependa kukutana nao tena.",
aboutCommunityKicker: "Jumuiya",
aboutCommunityTitle: "Hakuna anayejenga peke yake",
aboutCommunityDesc: "Vitu vizuri nilivyowahi kutengeneza vilianza kama mazungumzo na mtu mwingine — kwenye kahawa, kwenye grupu la WhatsApp, au mwishoni mwa mbio za asubuhi. Kwa hiyo mlango wangu uko wazi. Ninashiriki ninachojifunza wakati bado ninajifunza, ninajibu ujumbe wa watu ambao sijawahi kukutana nao, na napendelea kumfundisha mtu kutengeneza kitu kuliko kumuuzia kitu. Huhitaji kuwa mtaalamu wa teknolojia, huhitaji mtaji, huhitaji Kiingereza, wala huhitaji kuwa “tayari”. Hamu ya kujifunza ndiyo kigezo pekee.",
aboutInviteKicker: "Mwaliko wa wazi",
aboutInviteTitle: "Tutengeneze kitu pamoja",
aboutInviteDesc: "Kama chochote kati ya haya kinakugusa, ningefurahi kusikia kutoka kwako. Mara nyingi mambo huanza hivi:",
aboutInvite1: "Una kitu kinachostahili kurekodiwa — mradi, tukio, au siku yenye maana. Tuipige picha.",
aboutInvite2: "Umezidiwa na kazi za mikono zinazojirudia. Tuweke mfumo utakaokupunguzia mzigo.",
aboutInvite3: "Unajenga kitu na unahitaji jicho la pili — au mwenzako wa safari.",
aboutInvite4: "Unataka tu kupiga stori — kamera, programu, biashara, mbio. Kahawa iko juu yangu.",
aboutInviteClose: "Hakuna haja ya pendekezo rasmi. Niambie tu habari, unifahamishe unachofanya, na mengine tutapanga pamoja.",
aboutCtaWhatsapp: "Niandikie ujumbe",
storeTitle: "Duka la Atana",
kidarasaTitle: "Kidarasa",
karaniTitle: "Karani",
karaniIntro: "Biashara yako ina mwizi wa kimya: makaratasi. Karani inaweka risiti zako kidigitali kiotomatiki, ikikupa muda zaidi wa kuzingatia ndoto yako.",
returnHome: "Julius Moshiro",
returnHomeAria: "Rudi kwenye ukurasa wa nyumbani wa Julius Moshiro",
}
};
// --- Persistent Parameter Functions ---
function getStoredParams() {
try {
const paramsString = localStorage.getItem(TRACKED_PARAMS_KEY);
return paramsString ? JSON.parse(paramsString) : {};
} catch (e) {
console.error("Error reading stored params:", e);
return {};
}
}
function storeParams(paramsObject) {
try {
localStorage.setItem(TRACKED_PARAMS_KEY, JSON.stringify(paramsObject));
} catch (e) {
console.error("Error storing params:", e);
}
}
function processUrlParameters() {
const currentUrl = new URL(window.location.href);
const urlParams = new URLSearchParams(currentUrl.search);
let storedParams = getStoredParams();
let activeParams = { ...storedParams };
let paramsChanged = false;
ALLOWED_PARAMS.forEach(paramName => {
if (urlParams.has(paramName)) {
const urlValue = urlParams.get(paramName);
if (activeParams[paramName] !== urlValue) {
activeParams[paramName] = urlValue;
paramsChanged = true;
}
}
});
for (const key in activeParams) {
if (!ALLOWED_PARAMS.includes(key) || activeParams[key] === null || activeParams[key] === '') {
delete activeParams[key];
paramsChanged = true;
}
}
if (paramsChanged || JSON.stringify(activeParams) !== JSON.stringify(getStoredParams())) {
storeParams(activeParams);
}
const newSearchParams = new URLSearchParams();
Object.entries(activeParams).forEach(([key, value]) => {
if (value) newSearchParams.set(key, value);
});
const newSearchString = newSearchParams.toString();
if (currentUrl.search.substring(1) !== newSearchString) {
currentUrl.search = newSearchString ? `?${newSearchString}` : '';
history.replaceState(null, '', currentUrl.toString());
}
return activeParams;
}
function updatePageLinks(activeParams) {
const links = document.querySelectorAll('a[href]');
const currentOrigin = window.location.origin;
links.forEach(link => {
try {
const linkUrl = new URL(link.href, window.location.href);
if (linkUrl.protocol.startsWith('http') && linkUrl.origin === currentOrigin) {
const linkParams = new URLSearchParams(linkUrl.search);
Object.entries(activeParams).forEach(([key, value]) => {
if (value) {
linkParams.set(key, value);
}
});
linkUrl.search = linkParams.toString();
link.href = linkUrl.toString();
}
} catch (e) {
// console.warn(`Could not process link: ${link.href}`, e);
}
});
}
// --- Theme Functions ---
const applyTheme = (theme) => {
bodyElement.setAttribute('data-theme', theme);
if (themeToggleButton) {
themeToggleButton.innerHTML = theme === 'dark' ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>';
}
};
const setThemePreference = (theme) => {
localStorage.setItem('theme', theme);
applyTheme(theme);
};
const toggleTheme = () => {
const currentTheme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
setThemePreference(newTheme);
};
// --- Language Functions ---
function setLanguage(lang) {
if (!translations[lang]) return;
const titleElement = document.querySelector('title');
let pageKey = null;
if (document.body.classList.contains('page-karani')) pageKey = 'karaniTitle';
else if (document.body.classList.contains('page-store')) pageKey = 'storeTitle';
else if (document.body.classList.contains('page-kidarasa')) pageKey = 'kidarasaTitle';
else if (document.querySelector('.about-content')) pageKey = 'aboutTitle';
else if (document.querySelector('.profile-header')) pageKey = 'profileName';
if (titleElement) {
if (pageKey && translations[lang][pageKey]) {
let baseTitle = translations[lang][pageKey];
if (pageKey === 'profileName') {
titleElement.textContent = `${baseTitle} - Atana Ventures`;
} else if (pageKey === 'karaniTitle') {
titleElement.textContent = `${baseTitle} - Receipt Automation by Julius Moshiro`;
} else if (pageKey === 'aboutTitle') {
titleElement.textContent = `${baseTitle} - Atana Ventures`;
} else {
titleElement.textContent = `${baseTitle} - Julius Moshiro`;
}
} else {
titleElement.textContent = "Julius Moshiro - Atana Ventures";
}
}
translatableElements.forEach(el => {
const key = el.getAttribute('data-translate');
if (key && translations[lang][key] !== undefined) {
el.innerHTML = translations[lang][key];
}
});
// Tooltips / accessible labels that also need translating
document.querySelectorAll('[data-translate-title]').forEach(el => {
const key = el.getAttribute('data-translate-title');
if (key && translations[lang][key] !== undefined) {
el.setAttribute('title', translations[lang][key]);
el.setAttribute('aria-label', translations[lang][key]);
}
});
langButtons.forEach(button => {
button.classList.toggle('active', button.getAttribute('data-lang') === lang);
});
const uzaProductsElements = document.querySelectorAll('uza-products');
uzaProductsElements.forEach(uzaEmbed => {
uzaEmbed.setAttribute('__locale-override', lang);
});
localStorage.setItem('preferredLanguage', lang);
document.documentElement.lang = lang;
}
// --- Event Listeners ---
if (themeToggleButton) {
themeToggleButton.addEventListener('click', toggleTheme);
}
langButtons.forEach(button => {
button.addEventListener('click', () => {
const lang = button.getAttribute('data-lang');
setLanguage(lang);
});
});
if (document.querySelector('.profile-header')) {
document.addEventListener('keydown', (e) => {
if (document.activeElement && ['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement.tagName)) return;
const key = e.key.toUpperCase();
let targetLinkElement = null;
switch (key) {
case 'K': targetLinkElement = document.querySelector('a[href^="karani"]'); break;
case 'P': targetLinkElement = document.querySelector('a[href^="matukio"]'); break;
case 'S': targetLinkElement = document.querySelector('a[href*="duka.atana"], a[href^="store"]'); break;
case 'M': targetLinkElement = document.querySelector('a[href*="moneymindset.tz"]'); break;
case 'A': targetLinkElement = document.querySelector('a[href^="about"]'); break;
}
if (targetLinkElement) {
targetLinkElement.style.transform = 'scale(0.98)';
setTimeout(() => { targetLinkElement.style.transform = ''; }, 100);
const targetUrl = targetLinkElement.href;
if (targetLinkElement.target === '_blank') {
window.open(targetUrl, '_blank');
} else {
window.location.href = targetUrl;
}
e.preventDefault();
}
});
}
// --- Seamless embed: reveal the app once it has painted, so there is no white flash ---
const seamlessEmbed = document.querySelector('.seamless-embed');
if (seamlessEmbed) {
const revealEmbed = () => bodyElement.classList.add('embed-ready');
seamlessEmbed.addEventListener('load', revealEmbed);
// Fallback: never leave a visitor staring at the placeholder.
setTimeout(revealEmbed, 5000);
}
// --- Initial Setup ---
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
applyTheme(savedTheme || (prefersDark ? 'dark' : 'light'));
const preferredLanguage = localStorage.getItem('preferredLanguage') || 'sw';
setLanguage(preferredLanguage);
const activeParams = processUrlParameters();
updatePageLinks(activeParams);
}); // End DOMContentLoaded