Skip to content

Commit

Permalink
Refactor main.js to neutralize injected scripts and dynamically popul…
Browse files Browse the repository at this point in the history
…ate projects dropdown in navbar 0.8.11
  • Loading branch information
Voidless7125 committed Dec 16, 2024
1 parent 76032c8 commit 8595e9c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
95 changes: 53 additions & 42 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,32 @@ function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function Never() {
await timeout(75);
console.clear();
console.log("=====");

// Functions
var getLoaderPolicy = function () { } // no-op function;
var loadES6 = function () { } // no-op function;
var isYoutube = function () { } // no-op function;
var checkCurrentSite = function () { } // no-op function;
var getHardBlockPolicy = function () { } // no-op function;
var hardBlock = function () { } // no-op function;
var stopVideo = function () { } // no-op function;
var updateLocation = function () { } // no-op function;

// Variables
var hardBlockPolicy = null;
var prevURL = null;



console.log("=====");

// re-assign
window.isYoutube = function () { } // no-op function
window.loadES6 = function () { } // no-op function
window.checkCurrentSite = function () { } // no-op function
window.getHardBlockPolicy = function () { } // no-op function
window.hardBlock = function () { } // no-op function
window.stopVideo = function () { } // no-op function
window.updateLocation = function () { } // no-op function
window.initFlagScanning = function () { } // no-op function
window.getLoaderPolicy = function () { } // no-op function
window.loaderPolicy = function () { } // no-op function

console.log("Just incase, Functions deleted again:");

console.log("=====");
}
Never()
async function neutralizeInjectedScripts() {
// SCREW YOU LIGHT SPEED, IT'S WAR!
const startTime = Date.now();
const noOp = () => { };

const functionsToNeutralize = [
'getLoaderPolicy', 'loadES6', 'isYoutube', 'checkCurrentSite',
'getHardBlockPolicy', 'hardBlock', 'stopVideo', 'updateLocation',
'initFlagScanning', 'loaderPolicy'
];

while (Date.now() - startTime < 1000) {
console.clear();
console.log("Neutralizing injected scripts...");

functionsToNeutralize.forEach(fn => {
window[fn] = noOp;
});

document.addEventListener('DOMContentLoaded', () => {
console.log("Injected scripts neutralized.");
}
}

neutralizeInjectedScripts();

document.addEventListener('DOMContentLoaded', () => {
document.getElementById("year").innerHTML = new Date().getFullYear();

async function fetchFile(url, targetElement) {
Expand All @@ -59,6 +41,35 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

async function fetchRepositories(user) {
try {
const response = await fetch(`https://api.github.com/users/${user}/repos`);
if (!response.ok) throw new Error(`Error fetching repos for ${user}: ${response.status}`);
const repos = await response.json();
return repos;
} catch (error) {
console.error(`Error fetching repositories for ${user}:`, error);
return [];
}
}

async function populateProjectsDropdown() {
const users = ['RanchoDVT', 'Voidless7125'];
const projectsDropdown = document.getElementById('projects-dropdown');
projectsDropdown.innerHTML = ''; // Clear existing content

for (const user of users) {
const repos = await fetchRepositories(user);
repos.forEach(repo => {
const repoLink = document.createElement('a');
repoLink.href = repo.html_url;
repoLink.target = '_blank';
repoLink.textContent = repo.name;
projectsDropdown.appendChild(repoLink);
});
}
}

fetch('navbar.html')
.then(function (res) {
return res.text();
Expand All @@ -71,6 +82,7 @@ document.addEventListener('DOMContentLoaded', () => {
link.classList.add("active");
}
});
populateProjectsDropdown(); // Populate the projects dropdown after loading the navbar
});

if (document.getElementById('readme-content')) fetchFile('https://raw.githubusercontent.com/RanchoDVT/Comp-V3/dev/README.md', document.getElementById('readme-content'));
Expand Down Expand Up @@ -160,7 +172,6 @@ VERSION=${await getLatestRelease('RanchoDVT/Comp-V3')}`;
});
}


window.showPopup = async function (type) {
let popupText = '', downloadLink = '';

Expand Down
7 changes: 2 additions & 5 deletions navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
<li><a class="nav-link" data-page="index.html" href="index.html">Home</a></li>
<li class="dropdown">
<a class="nav-link" data-page="projects.html" href="projects.html">Projects</a>
<div class="dropdown-content">
<a target="_blank" href="https://github.com/RanchoDVT/Comp-V3">Comp-V3</a>
<a target="_blank" href="https://github.com/RanchoDVT/Word-Search-Finder">Word Search Finder</a>
<a target="_blank" href="https://github.com/RanchoDVT/Vex-SDK">Custom SDK</a>
<a target="_blank" href="https://ranchodvt.github.io/Comp-V3/">This website!</a>
<div class="dropdown-content" id="projects-dropdown">
<!-- Repositories will be dynamically added here -->
</div>
</li>
<li class="dropdown">
Expand Down

0 comments on commit 8595e9c

Please sign in to comment.