Skip to content

Commit

Permalink
Added fitgirlscrape POC
Browse files Browse the repository at this point in the history
  • Loading branch information
k3rielit committed Nov 12, 2023
1 parent e91a009 commit 4875cca
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fitgirl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# FitgirlScrape

A simple POC for repack scraping, which only logs the result(s) to the console at the moment. Only tested on the index page of the site.

## Install

1. Install the Tampermonkey extension. ([Link](https://www.tampermonkey.net))
2. [Install](https://github.com/k3rielit/scripts/raw/main/fitgirl/fitgirlscrape.user.js)
77 changes: 77 additions & 0 deletions fitgirl/fitgirlscrape.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ==UserScript==
// @name FitgirlScrape
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author k3rielit
// @match *://fitgirl-repacks.site/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=fitgirl-repacks.site
// @grant none
// ==/UserScript==

(function() {
'use strict';

function parseRepacks() {
let repackNodes = document.querySelectorAll('article.type-post:not(.category-uncategorized)');
let repackList = [];
repackNodes.forEach((article) => {
let repackData = {
post: {},
repack: {
categories: [],
downloads: [],
features: [],
},
game: {},
};
// Post information
repackData.post.id = article.getAttribute('id');
repackData.post.title = article.querySelector('header.entry-header h1.entry-title a').innerText;
repackData.post.page = article.querySelector('header.entry-header h1.entry-title a').href;
// Repack information
repackData.repack.id = article.querySelector('div.entry-content h3 span').innerText.replace('#', '');
article.querySelectorAll('div.entry-content ul').forEach((listNode, index) => {
switch(index) {
case 0:
// Download links
listNode.querySelectorAll('a').forEach((downloadNode) => {
repackData.repack.downloads.push({
name: downloadNode.innerText,
url: downloadNode.href,
});
})
break;
case 1:
// Repack features
listNode.querySelectorAll('li').forEach((repackFeatureNode) => {
repackData.repack.features.push(repackFeatureNode.innerText);
});
break;
}
});
article.querySelectorAll('header.entry-header div.entry-meta span.cat-links a').forEach((categoryNode) => {
repackData.repack.categories.push({
name: categoryNode.innerText,
url: categoryNode.href
});
});
// Game information
repackData.game.title = article.querySelector('div.entry-content h3 strong').innerText;
repackData.game.url = article.querySelector('div.entry-content p a').href;
repackData.game.metadata = article.querySelector('div.entry-content p').innerText.split('\n').filter(metadata => metadata);
repackData.game.description = article.querySelector('div.su-spoiler-content').innerText;
// Push the completed repack to the container
repackList.push(repackData);
});
return repackList;
}

// Observe and parse repack data
const observer = new MutationObserver(() => {
const repacks = parseRepacks();
console.log(repacks);
});
// Start the observer
observer.observe(document.body, { subtree: true, childList: true, attributes: true });
})();

0 comments on commit 4875cca

Please sign in to comment.