From 01fc6aeefc429c3667efaea8625c8da359f9f7f0 Mon Sep 17 00:00:00 2001 From: Loyd Osborne Date: Sun, 31 Mar 2024 01:17:42 -0600 Subject: [PATCH] Commit --- m/resources/pixeldrain/index-script.js | 171 ++++++++++++++++++ m/resources/pixeldrain/index.md | 96 ++++++++++ m/resources/pixeldrain/insert-scripts.js | 113 ++++++++++++ resources/pixeldrain/index.html | 93 ---------- .../pixeldrain/{index-fg.md => index.md} | 0 5 files changed, 380 insertions(+), 93 deletions(-) create mode 100644 m/resources/pixeldrain/index-script.js create mode 100644 m/resources/pixeldrain/index.md create mode 100644 m/resources/pixeldrain/insert-scripts.js delete mode 100644 resources/pixeldrain/index.html rename resources/pixeldrain/{index-fg.md => index.md} (100%) diff --git a/m/resources/pixeldrain/index-script.js b/m/resources/pixeldrain/index-script.js new file mode 100644 index 0000000..205ac6f --- /dev/null +++ b/m/resources/pixeldrain/index-script.js @@ -0,0 +1,171 @@ +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; +} + + + + + + + + + + +function toggleButton() { + var idInput = document.getElementById("idInput").value.trim(); + var generateBtn = document.getElementById("generateBtn"); + if (idInput !== "") { + generateBtn.disabled = false; + } else { + generateBtn.disabled = true; + } + } + + function generateURL() { + var id = document.getElementById("idInput").value.trim(); + if (id !== "") { + var url = "https://pd.resources.scyted.tv/" + id; + window.location.href = url; + } else { + alert("Please enter an ID."); + } + } + + // Check for error in the URL + window.onload = function() { + var url = window.location.href; + if (url.includes("?error=invalidID")) { + var errorDiv = document.getElementById("error"); + errorDiv.innerHTML = ` +
+ You have provided an invalid Pixeldrain video ID. +
`; + } + } \ No newline at end of file diff --git a/m/resources/pixeldrain/index.md b/m/resources/pixeldrain/index.md new file mode 100644 index 0000000..279272a --- /dev/null +++ b/m/resources/pixeldrain/index.md @@ -0,0 +1,96 @@ +--- +title: Resource Directory +layout: page +type: resources +--- + + + + + + +
+ +
+ +

← back

+ +
+ Resource Image +

Watch & Download PD Videos

+ Watch Pixeldrain videos, save your watch position, and bypass download restrictions.
+
+ +
+ +
+ + + + +
+ + +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/m/resources/pixeldrain/insert-scripts.js b/m/resources/pixeldrain/insert-scripts.js new file mode 100644 index 0000000..1db8e6d --- /dev/null +++ b/m/resources/pixeldrain/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/pixeldrain/index.html b/resources/pixeldrain/index.html deleted file mode 100644 index 71bf535..0000000 --- a/resources/pixeldrain/index.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - -URL Generator - - - - -
-

URL Generator

-
-
- - - -
-
- - - - - diff --git a/resources/pixeldrain/index-fg.md b/resources/pixeldrain/index.md similarity index 100% rename from resources/pixeldrain/index-fg.md rename to resources/pixeldrain/index.md