Skip to content

Instantly share code, notes, and snippets.

@whamer100
Created May 8, 2020 20:14
Show Gist options
  • Save whamer100/ee679df4e1c9d46b67b51e603d836316 to your computer and use it in GitHub Desktop.
Save whamer100/ee679df4e1c9d46b67b51e603d836316 to your computer and use it in GitHub Desktop.
Fangame Archive Extension for greasemonkey/tampermonkey/violentmonkey
// ==UserScript==
// @name Fangame Archive Extension
// @namespace Violentmonkey Scripts
// @match *://*.delicious-fruit.com/*
// @grant none
// @version 1.0
// @author Fangame Archive
// @description 5/2/2020, 1:55:35 AM
// ==/UserScript==
"use-strict";
const isOnGamePage = () => {
return window.location.pathname === "/ratings/game_details.php";
}
const getGameLink = () => {
return document.querySelector("#game-link");
}
const getNoLink = () => {
return document.querySelector("#no-link");
}
const isPrivate = () => {
return getGameLink().style.display === "none";
}
const getGameName = () => {
return document.querySelector("#content h1").innerText.trim();
}
const generateFindURL = (gameName) => {
return "https://fangamearchive.isocodes.org/find.php?game=" + encodeURIComponent(gameName);
}
const fetchURL = (url, callback) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4)
callback(xhr.response);
}
xhr.open("GET", url, true);
xhr.send("");
}
if (isOnGamePage() && isPrivate()) {
const gameName = getGameName();
const findURL = generateFindURL(gameName);
fetchURL(findURL, (downloadURL) => {
if (downloadURL === "")
return;
getGameLink().style.display = "";
getGameLink().setAttribute("href", downloadURL);
getNoLink().style.display = "none";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment