diff --git a/resources/loyd-gtav/index-script.js b/resources/loyd-gtav/index-script.js new file mode 100644 index 0000000..2e7f672 --- /dev/null +++ b/resources/loyd-gtav/index-script.js @@ -0,0 +1,209 @@ +const currentURL = window.location.href; + +function redirectToDiscord() { + const baseURL = window.location.origin; // Extract base URL + const AuthUrl = `${baseURL}/oauth/discord/?callbackUrl=${encodeURIComponent(currentURL)}`; + window.location.href = AuthUrl; +} + +document.addEventListener("DOMContentLoaded", function () { + const storedAccessToken = getCookie("accessToken"); + displayContents(); + // Redirect to login if access token is not found + if (!storedAccessToken) { + // window.location.href = `https://auth.scyted.tv/www.scyted.tv/discord?redirectUri=${currentURL}`; + displayLoginButton(); + } else { + // Fetch user data from Discord API + fetchDiscordUserData(storedAccessToken) + .then(userData => { + // Display bot info and user info on the dashboard + + displayUserInfo(userData); + + const loggedInUserId = userData.id; + + // Fetch the list of user IDs from the JSON file + // fetch('https://api.scyted.tv/wave-development/dashboard/access/scytedtv-user-access.json') + fetch('https://api.scyted.tv/website/dashboard/access/dashboard-access.json') + .then(response => response.json()) + .then(userIds => { + // Check if the logged-in user's ID is in the list + if (!userIds.includes(loggedInUserId)) { + // Clear cookies + // document.cookie = "accessToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + // Redirect to the specified page if the user's ID is not in the + // window.location.href = `https://auth.scyted.tv/www.scyted.tv/discord?error=invalidAccess`; + displayContents(); + displayUserInfo(userData); + } + }) + .catch(error => { + console.error("Error fetching user IDs:", error); + // Handle error + }); + }) + .catch(error => { + console.error("Error fetching user data:", error); + // Clear cookies + // document.cookie = "accessToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + // Handle error (e.g., redirect to login page) + // window.location.href = `https://auth.scyted.tv/www.scyted.tv/discord?error=fetchingUserData`; + }); + } +}); + +const urlParams = new URLSearchParams(window.location.hash.substring(1)); +const accessToken = urlParams.get("access_token"); + +if (accessToken) { + try { + // Check if the access token is valid (add your validation logic here) + if (isValidAccessToken(accessToken)) { + // Store the access token in a cookie + setCookie("accessToken", accessToken, 30); // Set cookie to expire in 30 days + // Redirect to the dashboard + window.location.href = "./"; + } else { + // Clear the accessToken cookie + clearCookie("accessToken"); + } + } catch (error) { + console.error("Error setting accessToken:", error); + } +} + +function isValidAccessToken(token) { + // Add your validation logic here + // Return true if the token is valid, otherwise return false + return true; // Placeholder, replace with actual validation +} + +function setCookie(name, value, days) { + const date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + const expires = "expires=" + date.toUTCString(); + document.cookie = name + "=" + value + ";" + expires + ";path=/"; +} + +function clearCookie(name) { + document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; +} + +function fetchDiscordUserData(accessToken) { + const apiUrl = 'https://discord.com/api/users/@me'; + + return fetch(apiUrl, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }) + .then(response => { + if (!response.ok) { + throw new Error(`Discord API Request Failed! Status: ${response.status}`); + } + return response.json(); + }); +} + +function logout() { + // Clear cookies + document.cookie = "accessToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + + // Redirect to login page + window.location.href = `${currentURL}`; +} + +function backButton() { + window.location.href = `../`; +} + +function getCookie(name) { + const cookies = document.cookie.split("; "); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].split("="); + if (cookie[0] === name) { + return cookie[1]; + } + } + return null; +} + + + + + + + + + +fetch('https://api.scyted.tv/resources/game-tracking/loyd-gtav.json') + .then(response => response.json()) + .then(data => { + const achievementsDiv = document.getElementById('achievements'); + const completedAchievements = []; + const incompleteAchievements = []; + + // Separate completed and incomplete achievements + data.achievements.forEach(achievement => { + if (achievement.achieved) { + completedAchievements.push(achievement); + } else { + incompleteAchievements.push(achievement); + } + }); + + // Sort completed achievements by date and time (newest to oldest) + completedAchievements.sort((a, b) => { + const dateA = new Date(a.date + ' ' + a.time); + const dateB = new Date(b.date + ' ' + b.time); + return dateB - dateA; + }); + + // Concatenate completed achievements with incomplete ones + const sortedAchievements = completedAchievements.concat(incompleteAchievements); + + // Display achievements + sortedAchievements.forEach(achievement => { + const achievementDiv = document.createElement('div'); + achievementDiv.classList.add('achievement'); + if (achievement.achieved) { + achievementDiv.classList.add('achievement-unlocked'); + } else { + achievementDiv.classList.add('achievement-locked'); + achievementDiv.classList.add('incomplete'); + } + const iconClass = achievement.achieved ? 'fas fa-check-circle' : 'far fa-circle'; + achievementDiv.innerHTML = ` +
+ +
+
+

${achievement.name}

+

${achievement.description}

+

${achievement.achieved ? 'Achieved' : 'Not achieved'}

+ ${achievement.achieved ? ` +
+ ${achievement.date} at ${achievement.time} +
+ ` : ''} + ${achievement.type === 'Progress' ? ` +
+
+
${achievement.progress}
+
+ ` : ''} +
+ ${achievement.name} + `; + achievementsDiv.appendChild(achievementDiv); + }); + }) + .catch(error => console.error('Error fetching data:', error)); + + function calculateProgress(progress) { + const progressParts = progress.split('/'); + const current = parseInt(progressParts[0]); + const total = parseInt(progressParts[1]); + return `${(current / total) * 100}%`; + } \ No newline at end of file diff --git a/resources/loyd-gtav/index.md b/resources/loyd-gtav/index.md new file mode 100644 index 0000000..2d3b8cf --- /dev/null +++ b/resources/loyd-gtav/index.md @@ -0,0 +1,187 @@ +--- +title: Resource Directory +layout: page +type: resources +--- + + + + + + + + + +
+ +
+ +

← back

+ +
+ Resource Image +

GTA V Achievements

+ Loyd's Grand Theft Auto V achievement tracking.
+
+ +
+ +
+ + + + + +
+ + +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/resources/loyd-gtav/insert-scripts.js b/resources/loyd-gtav/insert-scripts.js new file mode 100644 index 0000000..1db8e6d --- /dev/null +++ b/resources/loyd-gtav/insert-scripts.js @@ -0,0 +1,113 @@ +function displayAccessError() { + var fullpageDiv = document.getElementById("insert-content"); + fullpageDiv.innerHTML = ` +
+ This resource requires you to login with Discord. +
+ `; + displayLoginButton(); +} + +function displayErrorInvalidAccess() { + var fullpageDiv = document.getElementById("insert-content"); + fullpageDiv.innerHTML = ` +
+ This Discord account doesn't have access to this resource. +
+ `; +} + +function displayLoginButton() { + var fullpageDiv = document.getElementById("login-container"); + fullpageDiv.innerHTML = ` + + `; +} + +function displayContents() { + return true; +} + +function displayUserInfo(userData) { + + var fullpageDiv = document.getElementById("login-container"); + fullpageDiv.innerHTML = ` + + + `; + + const userDropdown = document.getElementById('userDropdown'); + const profilePicture = document.querySelector('.profile-picture'); + const username = document.querySelector('.user-info span'); + + // Check if userData.avatar is null + if (userData.avatar === null || userData.avatar === "null") { + profilePicture.src = "https://cdn.scyted.tv/website-assets/wave-development/default-discord.png"; + } else { + profilePicture.src = `https://cdn.discordapp.com/avatars/${userData.id}/${userData.avatar}.png`; + } + + username.textContent = userData.username; + return true; +} + +function toggleUserDropdown() { + const userDropdown = document.getElementById('userDropdown'); + userDropdown.classList.toggle('show'); +} \ No newline at end of file diff --git a/resources/resources.json b/resources/resources.json index 28f97e4..e47f89b 100644 --- a/resources/resources.json +++ b/resources/resources.json @@ -40,6 +40,12 @@ "title": "JBW Beta", "description": "JuJu's Better Wynncraft Beta.", "resourceUrl": "jbw-beta" + }, + { + "imageUrl": "https://cdn.scyted.tv/website-assets/resource-portal/logos/loyd-gtav.jpg", + "title": "GTA V Achievements", + "description": "Loyd's Grand Theft Auto V achievement tracking.", + "resourceUrl": "loyd-gtav" } ] \ No newline at end of file diff --git a/show/do/404.html b/show/do/404.html deleted file mode 100644 index 49bab10..0000000 --- a/show/do/404.html +++ /dev/null @@ -1,202 +0,0 @@ - - - - - - Custom Video Player - - - -
-

Custom Video Player

- -
- - -
- 00:00 - / - 00:00 -
-
-
- - - - diff --git a/show/do/dirty-laundry.html b/show/do/dirty-laundry.html deleted file mode 100644 index 4b91279..0000000 --- a/show/do/dirty-laundry.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - Custom Video Player - - - -
-

Custom Video Player

- -
- - Download - -
- 00:00 - / - 00:00 -
-
-
- - - - diff --git a/show/do/dirty.md b/show/do/dirty.md deleted file mode 100644 index 0169e02..0000000 --- a/show/do/dirty.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: Dirty Laundry -layout: page -type: show ---- - - - - -
-

Custom Video Player

- -
- - -
- 00:00 - / - 00:00 -
-
-
- - - \ No newline at end of file diff --git a/show/do/show-scripts.js b/show/do/show-scripts.js deleted file mode 100644 index 49881c9..0000000 --- a/show/do/show-scripts.js +++ /dev/null @@ -1,106 +0,0 @@ -window.onload = function() { - var video = document.getElementById('videoPlayer'); - var playPauseBtn = document.getElementById('playPauseBtn'); - var currentTimeSpan = document.getElementById('currentTime'); - var durationSpan = document.getElementById('duration'); - var volumeControl = document.getElementById('volumeControl'); - var videoUrl = window.location.href; - var wasPlaying = false; - - video.onloadedmetadata = function() { - durationSpan.textContent = formatTime(video.duration); - }; - - // Check if there's a saved playback time for this video - var playbackTime = getCookie(videoUrl); - - if (playbackTime) { - video.currentTime = playbackTime; - } - - // Check if the video was playing before unloading the page - var wasPlayingValue = getCookie("wasPlaying"); - - if (wasPlayingValue === "true") { - wasPlaying = true; - } - - // Check if there's a saved volume for the website - var savedVolume = getCookie("websiteVolume"); - - if (savedVolume !== null) { - video.volume = parseFloat(savedVolume); - volumeControl.value = savedVolume; - } - - // Save the playback time whenever the video is paused - video.addEventListener('pause', function() { - setCookie(videoUrl, video.currentTime, 365); - setCookie("wasPlaying", "false", 365); - }); - - // Save the playback time and state whenever the video is played - video.addEventListener('play', function() { - setCookie(videoUrl, video.currentTime, 365); - setCookie("wasPlaying", "true", 365); - }); - - // Save the volume for the website - volumeControl.addEventListener('input', function() { - video.volume = volumeControl.value; - setCookie("websiteVolume", volumeControl.value, 365); - }); - - // Update current time display as video progresses - video.addEventListener('timeupdate', function() { - currentTimeSpan.textContent = formatTime(video.currentTime); - setCookie(videoUrl + "_timestamp", video.currentTime, 365); // Save timestamp to cookie - }); - - // Function to set a cookie - function setCookie(name, value, days) { - var expires = ""; - if (days) { - var date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - expires = "; expires=" + date.toUTCString(); - } - document.cookie = name + "=" + value + expires + "; path=/"; - } - - // Function to get a cookie - function getCookie(name) { - var nameEQ = name + "="; - var ca = document.cookie.split(';'); - for (var i = 0; i < ca.length; i++) { - var c = ca[i]; - while (c.charAt(0) === ' ') c = c.substring(1, c.length); - if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); - } - return null; - } - - // Format time in MM:SS format - function formatTime(seconds) { - var minutes = Math.floor(seconds / 60); - var remainingSeconds = Math.floor(seconds % 60); - return `${minutes < 10 ? '0' : ''}${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`; - } - - // Play/Pause button functionality - playPauseBtn.addEventListener('click', function() { - if (video.paused) { - video.play(); - playPauseBtn.textContent = 'Pause'; - } else { - video.pause(); - playPauseBtn.textContent = 'Play'; - } - }); - - // If the video was playing before unloading the page, resume playback - if (wasPlaying) { - video.play(); - playPauseBtn.textContent = 'Pause'; - } -}; \ No newline at end of file