-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
193 lines (168 loc) · 8.46 KB
/
Copy pathscript.js
File metadata and controls
193 lines (168 loc) · 8.46 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
// Language Switcher for Coding Agent PIMP Manifesto
function initLanguageToggle() {
const langButtons = document.querySelectorAll('.lang-btn');
const elementsWithLang = document.querySelectorAll('[data-lang]:not(.lang-btn)');
if (langButtons.length === 0) {
console.error('No language buttons found! Retrying in 500ms...');
setTimeout(initLanguageToggle, 500);
return;
}
// Meta tag elements that need dynamic updates
const metaDescription = document.querySelector('meta[name="description"]');
const metaKeywords = document.querySelector('meta[name="keywords"]');
const metaLanguage = document.querySelector('meta[name="language"]');
const metaContentLanguage = document.querySelector('meta[http-equiv="content-language"]');
const ogTitle = document.querySelector('meta[property="og:title"]');
const ogDescription = document.querySelector('meta[property="og:description"]');
const ogLocale = document.querySelector('meta[property="og:locale"]');
const twitterTitle = document.querySelector('meta[name="twitter:title"]');
const twitterDescription = document.querySelector('meta[name="twitter:description"]');
const structuredData = document.querySelector('script[type="application/ld+json"]');
const documentTitle = document.querySelector('title');
// Language content for meta tags
const metaContent = {
fr: {
title: "The Coding Agent PIMP Manifesto - Programmeurs Intelligents et Malins sur leurs Projets",
description: "Le manifeste officiel des PIMPs - Programmeurs Intelligents et Malins pour les Projets. Apprenez à exploiter... pardon, optimiser vos coding agents pour maximiser vos profits et votre gloire.",
keywords: "coding agents, AI development, PIMP manifesto, programmeur intelligent, Claude, ChatGPT, GitHub Copilot, développeur IA, manifeste humoristique",
language: "French",
contentLanguage: "fr-FR",
ogTitle: "The Coding Agent PIMP Manifesto",
ogDescription: "Découvrez comment devenir un PIMP certifié et mettre vos coding agents au travail. Le guide ultime pour exploiter l'IA et briller en société!",
ogLocale: "fr_FR",
twitterTitle: "The Coding Agent PIMP Manifesto",
twitterDescription: "Le guide officiel pour devenir un PIMP certifié. Mettez vos agents IA au travail et récoltez la gloire!",
structuredLang: "fr-FR",
structuredHeadline: "Le guide ultime pour exploiter vos coding agents"
},
en: {
title: "The Coding Agent PIMP Manifesto - Programmers Intelligently Managing Projects",
description: "The official manifesto of PIMPs - Programmers Intelligently Managing Projects. Learn to exploit... sorry, optimize your coding agents to maximize your profits and glory.",
keywords: "coding agents, AI development, PIMP manifesto, intelligent programmer, Claude, ChatGPT, GitHub Copilot, AI developer, humorous manifesto",
language: "English",
contentLanguage: "en-US",
ogTitle: "The Coding Agent PIMP Manifesto",
ogDescription: "Discover how to become a certified PIMP and put your coding agents to work. The ultimate guide to exploit AI and shine in society!",
ogLocale: "en_US",
twitterTitle: "The Coding Agent PIMP Manifesto",
twitterDescription: "The official guide to becoming a certified PIMP. Put your AI agents to work and reap the glory!",
structuredLang: "en-US",
structuredHeadline: "The ultimate guide to exploit your coding agents"
}
};
// Prevent rapid-fire switching
let switching = false;
// Get saved language or default to French
let currentLang = localStorage.getItem('pimp-manifesto-lang') || 'fr';
// Initialize with saved language
switchLanguage(currentLang);
// Clean, single event handler per button
langButtons.forEach((button, index) => {
const lang = button.getAttribute('data-lang');
// Single, clean event handler
button.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
switchLanguage(lang);
localStorage.setItem('pimp-manifesto-lang', lang);
});
});
function switchLanguage(lang) {
if (switching) {
return;
}
switching = true;
currentLang = lang;
// Update button states
langButtons.forEach(btn => {
btn.classList.remove('active');
if (btn.getAttribute('data-lang') === lang) {
btn.classList.add('active');
}
});
// Show/hide elements based on language
elementsWithLang.forEach(element => {
const elementLang = element.getAttribute('data-lang');
if (elementLang === lang) {
element.style.display = '';
element.classList.add('active-lang');
} else {
element.style.display = 'none';
element.classList.remove('active-lang');
}
});
// Update meta tags
updateMetaTags(lang);
// Add smooth transition class
document.body.classList.add('lang-switching');
setTimeout(() => {
document.body.classList.remove('lang-switching');
switching = false; // Reset switching flag after animation
}, 300);
}
function updateMetaTags(lang) {
const content = metaContent[lang];
// Update HTML lang attribute
document.documentElement.setAttribute('lang', content.contentLanguage.substring(0, 2));
if (documentTitle) documentTitle.textContent = content.title;
if (metaDescription) metaDescription.setAttribute('content', content.description);
if (metaKeywords) metaKeywords.setAttribute('content', content.keywords);
if (metaLanguage) metaLanguage.setAttribute('content', content.language);
if (metaContentLanguage) metaContentLanguage.setAttribute('content', content.contentLanguage);
if (ogTitle) ogTitle.setAttribute('content', content.ogTitle);
if (ogDescription) ogDescription.setAttribute('content', content.ogDescription);
if (ogLocale) ogLocale.setAttribute('content', content.ogLocale);
if (twitterTitle) twitterTitle.setAttribute('content', content.twitterTitle);
if (twitterDescription) twitterDescription.setAttribute('content', content.twitterDescription);
// Update structured data
if (structuredData) {
try {
const jsonLd = JSON.parse(structuredData.textContent);
jsonLd.inLanguage = content.structuredLang;
jsonLd.mainEntity.headline = content.structuredHeadline;
structuredData.textContent = JSON.stringify(jsonLd, null, 4);
} catch (e) {
console.warn('Could not update structured data:', e);
}
}
}
}
// Multiple initialization strategies for reliability
let initialized = false;
function safeInit() {
if (initialized) return;
try {
initLanguageToggle();
initialized = true;
} catch (error) {
console.error('Language toggle initialization failed:', error);
setTimeout(safeInit, 1000); // Retry in 1 second
}
}
// Primary initialization
document.addEventListener('DOMContentLoaded', safeInit);
// Backup initialization strategies
window.addEventListener('load', safeInit);
document.addEventListener('readystatechange', function() {
if (document.readyState === 'complete') {
safeInit();
}
});
// Ultimate fallback - initialize after 2 seconds regardless
setTimeout(safeInit, 2000);
// Global debugging function
window.debugLanguageToggle = function() {
console.log('=== Language Toggle Debug ===');
console.log('Initialized:', initialized);
console.log('Buttons found:', document.querySelectorAll('.lang-btn').length);
console.log('EN button exists:', !!document.getElementById('lang-en'));
console.log('FR button exists:', !!document.getElementById('lang-fr'));
console.log('Current language:', localStorage.getItem('pimp-manifesto-lang') || 'fr');
return {
initialized,
buttonCount: document.querySelectorAll('.lang-btn').length,
enExists: !!document.getElementById('lang-en'),
frExists: !!document.getElementById('lang-fr'),
currentLang: localStorage.getItem('pimp-manifesto-lang') || 'fr'
};
};