Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LoydOsborne committed Mar 31, 2024
1 parent 97e9634 commit 01fc6ae
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 93 deletions.
171 changes: 171 additions & 0 deletions m/resources/pixeldrain/index-script.js
Original file line number Diff line number Diff line change
@@ -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 = `
<div class="user-info-box" id="userInfoBox">
You have provided an invalid Pixeldrain video ID.
</div>`;
}
}
96 changes: 96 additions & 0 deletions m/resources/pixeldrain/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: Resource Directory
layout: page
type: resources
---
<style>
hr.has-background-black {
display: none;
}

h1.title {
display: none;
}
</style>
<link rel="stylesheet" href="https://api.scyted.tv/wave-development/dashboard/scytedtv-resources-mobile.css">
<body>

<div class="banner">
<img src="https://cdn.scyted.tv/website-assets/resource-portal/banner.jpg" alt="Banner Image" class="banner-image">
</div>

<div class="resource-container">

<div class="resource-wrapper">

<div class="resource-back" onclick="backButton()"><p>← back</p></div>

<div class="resource-info-box">
<img src="https://cdn.scyted.tv/website-assets/resource-portal/logos/pixeldrain.jpg" alt="Resource Image" class="resource-image">
<h3>Watch & Download PD Videos</h3>
Watch Pixeldrain videos, save your watch position, and bypass download restrictions.<br>
</div>

</div>

<div class="resource-box">

<div id="login-container" class="login-container">
</div>

<style>
.user-info-box {
flex: 1;
padding: 20px;
background-color: #fff;
border-radius: 8px;
margin-top: 10px;
text-align: left;
}
.input-group {
display: flex;
margin-bottom: 20px;
}
.input-group input[type="text"] {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.input-group button {
padding: 10px 20px;
background-color: #161616;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
.input-group button:hover {
background-color: #45a049;
}
#error {
color: red;
margin-top: 10px;
}
</style>
<div class="container">

<div class="user-info-box" id="userInfoBox">

This resource isn't meant for mobile devices. Please try again on a Desktop or PC.

</div>
</div>
</div>
</div>

<script src="https://api.scyted.tv/wave-development/dashboard/page-loading-script.js"></script>
<script src="index-script.js"></script>
<script src="insert-scripts.js"></script>
<script src="https://api.scyted.tv/wave-development/dashboard/mobile-redirect.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LF3ZTHGQHE"></script>

</body>
113 changes: 113 additions & 0 deletions m/resources/pixeldrain/insert-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
function displayAccessError() {
var fullpageDiv = document.getElementById("insert-content");
fullpageDiv.innerHTML = `
<div id="error-message" style="color: red;">
This resource requires you to login with Discord.
</div>
`;
displayLoginButton();
}

function displayErrorInvalidAccess() {
var fullpageDiv = document.getElementById("insert-content");
fullpageDiv.innerHTML = `
<div id="error-message" style="color: red;">
This Discord account doesn't have access to this resource.
</div>
`;
}

function displayLoginButton() {
var fullpageDiv = document.getElementById("login-container");
fullpageDiv.innerHTML = `
<button onclick="redirectToDiscord()" class="discord-button">Login</button>
`;
}

function displayContents() {
return true;
}

function displayUserInfo(userData) {

var fullpageDiv = document.getElementById("login-container");
fullpageDiv.innerHTML = `
<style>
.user-info {
display: flex;
align-items: center;
cursor: pointer;
justify-content: right;
}
.profile-picture {
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 10px;
justify-content: right;
}
.user-dropdown {
display: none;
position: absolute;
top: 60px;
right: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
flex-direction: column;
z-index: 1;
}
.user-dropdown a {
color: #333;
padding: 10px;
text-decoration: none;
display: block;
}
.user-dropdown a:hover {
background-color: #ddd;
}
.user-dropdown.show {
display: flex;
}
.user-dropdown a.logout {
color: #ff5252;
}
</style>
<button class="discord-button" id="discord-button">
<div class="user-info" onclick="toggleUserDropdown()">
<img src="https://cdn.scyted.tv/website-assets/wave-development/default-discord.png"
alt="Profile Picture" class="profile-picture">
<span>Loading...</span>
<div class="user-dropdown" id="userDropdown">
<a href="#" class="logout" onclick="logout()">Logout</a>
</div>
</div>
</button>
`;

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');
}
Loading

0 comments on commit 01fc6ae

Please sign in to comment.