FitGirl Repacks - all games in a single page.

All games will be shown in a single page instead of multiple pages. Use CTRL+F!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         FitGirl Repacks - all games in a single page.
// @description  All games will be shown in a single page instead of multiple pages. Use CTRL+F!
// @namespace    erkexzcx
// @version      0.2
// @author       You
// @match        http://fitgirl-repacks.site/all-my-repacks-a-z/*
// @grant        none
// ==/UserScript==

// Make sure we are on the first page:
if(window.location.href !== "http://fitgirl-repacks.site/all-my-repacks-a-z/?lcp_page0=1#lcp_instance_0"){
    window.location.replace("http://fitgirl-repacks.site/all-my-repacks-a-z/?lcp_page0=1#lcp_instance_0");
    return;
}

// Some reusable vars:
var gamesContainer = document.getElementById("lcp_instance_0");
var pagesContainer = document.getElementsByClassName("lcp_paginator")[0];
var dummyDocument = document.implementation.createHTMLDocument();

// Hide pages:
pagesContainer.style.display = 'none';

// Open links in new tab:
makeLinksOpenInNewTab(document);

var pages = pagesContainer.querySelectorAll('li > a[href^="http://fitgirl-repacks.site/all-my-repacks-a-z/?lcp_page0="][title]');
Array.prototype.forEach.call(pages, function(el, i){

    if(el.innerHTML === "Next Page"){
        return;
    }

    var request = new XMLHttpRequest();
    request.open('GET', el.getAttribute('href'), true);
    request.onload = function() {
        if (this.status >= 200 && this.status < 400) {
            parseAndAppend(this.response);
        } else {
            alert("Error occured while parsing games! Userscript now stops, please refresh the page.");
            return;
        }
    };
    request.onerror = function() {
        alert("Error occured while parsing games! Userscript now stops, please refresh the page.");
        return;
    };
    request.send();

});

function parseAndAppend(html){
    dummyDocument.body.innerHTML = html;

    // Open links in new tab:
    dummyDocument = makeLinksOpenInNewTab(dummyDocument);

    // Append parsed new links to existing page:
    var elements = dummyDocument.querySelectorAll('#lcp_instance_0 > li');
    Array.prototype.forEach.call(elements, function(el, i){
        gamesContainer.appendChild(el);
    });
}

// Make all links to open in a new tab:
function makeLinksOpenInNewTab(doc){
    var links = doc.querySelectorAll('#lcp_instance_0 > li > a[href][title]');
    for(var i=0; i < links.length; i++) {
        links[i].setAttribute('target', '_blank');
    }
    return doc;
}