Automatically maintains the daily streak on Duolingo (NEW VERSION UPDATE)
当前为
// ==UserScript==
// @name DUO_KEEPSTREAK
// @namespace ´꒳`ⓎⒶⓂⒾⓈⒸⓇⒾⓅⓉ×͜×
// @version v1.0.4
// @description Automatically maintains the daily streak on Duolingo (NEW VERSION UPDATE)
// @author ´꒳`ⓎⒶⓂⒾⓈⒸⓇⒾⓅⓉ×͜×
// @match https://*.duolingo.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=duolingo.com
// ==/UserScript==
const getToken = () => {
const tokenRow = document.cookie.split('; ').find(row => row.startsWith('jwt_token='));
return tokenRow ? tokenRow.split('=')[1] : null;
};
const parseJwt = (token) => {
try {
return JSON.parse(atob(token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/')));
} catch (e) {
console.error("JWT parsing error", e);
return null;
}
};
const getHeaders = (token) => ({
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
"User-Agent": navigator.userAgent
});
const fetchUserData = async (userId, headers) => {
try {
const response = await fetch(`https://www.duolingo.com/2017-06-30/users/${userId}?fields=fromLanguage,learningLanguage,streakData`, { headers });
if (!response.ok) throw new Error("Failed to fetch user data");
return response.json();
} catch (error) {
console.error("Error fetching user data:", error);
return null;
}
};
const hasStreakToday = (data) => {
const today = new Date().toISOString().split('T')[0];
return data?.streakData?.currentStreak?.endDate === today;
};
const startSession = async (fromLang, learningLang, headers) => {
try {
const payload = {
challengeTypes: ["translate", "match", "tapComplete", "reverseAssist", "judge"],
fromLanguage: fromLang,
learningLanguage: learningLang,
type: "GLOBAL_PRACTICE"
};
const response = await fetch("https://www.duolingo.com/2017-06-30/sessions", {
method: 'POST',
headers,
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error("Failed to start session");
return response.json();
} catch (error) {
console.error("Error starting session:", error);
return null;
}
};
const completeSession = async (session, headers) => {
try {
const payload = { ...session, heartsLeft: 0, failed: false, shouldLearnThings: true };
const response = await fetch(`https://www.duolingo.com/2017-06-30/sessions/${session.id}`, {
method: 'PUT',
headers,
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error("Failed to complete session");
return response.json();
} catch (error) {
console.error("Error completing session:", error);
return null;
}
};
const addConfettiStyle = () => {
const style = document.createElement("style");
style.innerHTML = `
@keyframes confetti {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(100vh); opacity: 0; }
}
.confetti {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 9999;
}
.confetti div {
position: absolute;
width: 10px;
height: 10px;
background-color: #ff0;
opacity: 0.8;
animation: confetti 3s infinite;
}
`;
document.head.appendChild(style);
};
const isVipUser = (userData) => {
// Check if the user has a VIP subscription
return userData?.subscriptions?.some(sub => sub.type === "VIP");
};
const attemptStreak = async (button) => {
button.innerText = "Processing...";
button.disabled = true;
button.style.opacity = "0.7";
const token = getToken();
if (!token) {
alert("❌ You are not logged into Duolingo!");
} else {
const userId = parseJwt(token)?.sub;
if (!userId) {
alert("❌ Error retrieving user ID.");
} else {
const headers = getHeaders(token);
const userData = await fetchUserData(userId, headers);
if (!userData) {
alert("⚠️ Error fetching user data, try again!");
} else if (hasStreakToday(userData)) {
alert("✅ You have already maintained your streak today!");
} else {
if (isVipUser(userData)) {
alert("🌟 VIP User detected! Enjoy your premium benefits.");
}
const session = await startSession(userData.fromLanguage, userData.learningLanguage, headers);
if (!session) {
alert("⚠️ Error starting session, try again!");
} else {
const completed = await completeSession(session, headers);
if (completed) {
const xpBonus = isVipUser(userData) ? 20 : 10; // VIP users get double XP
alert(`🎉 Streak has been maintained! You earned ${xpBonus} XP. Reload the page to check.`);
createConfetti();
} else {
alert("⚠️ Error maintaining streak, try again!");
}
}
}
}
}
button.innerText = "🔥 Get Streak 🔥";
button.disabled = false;
button.style.opacity = "1";
};
const addButton = () => {
if (document.getElementById("get-streak-btn")) return;
const button = document.createElement("button");
button.id = "get-streak-btn";
button.innerText = "🔥 Get Streak 🔥";
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.padding = "14px 24px";
button.style.backgroundColor = "#58cc02";
button.style.color = "white";
button.style.fontSize = "18px";
button.style.fontWeight = "bold";
button.style.border = "none";
button.style.borderRadius = "30px";
button.style.boxShadow = "0px 6px 12px rgba(0, 0, 0, 0.2)";
button.style.cursor = "pointer";
button.style.zIndex = "1000";
button.style.transition = "all 0.2s ease-in-out";
button.onmouseover = () => {
button.style.backgroundColor = "#46a102";
button.style.transform = "scale(1.1)";
};
button.onmouseout = () => {
button.style.backgroundColor = "#58cc02";
button.style.transform = "scale(1)";
};
button.onclick = () => attemptStreak(button);
document.body.appendChild(button);
};
window.onload = () => {
addConfettiStyle();
setTimeout(addButton, 2000);
};
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址