Save GameFAQs as a text file

Save GameFAQs as a text file.

Versione datata 26/04/2017. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Save GameFAQs as a text file
// @description Save GameFAQs as a text file.
// @namespace   undefined
// @include     https://www.gamefaqs.com/*
// @version     0.3
// @grant       none
// ==/UserScript==
(function () {
    "use strict";
    var doc = document;
    var text = doc.getElementById("faqtext").innerHTML;
    var blob;
    var a = doc.createElement("a");
    var filename = doc.URL.substr(doc.URL.lastIndexOf("/") + 1) + ".txt";
    var entity = {
        lt: "<",
        gt: ">",
        amp: "&",
        nbsp: " "
    };
    var unreChar = [];
    var p = doc.getElementsByTagName("p");
    var location;
    var i = 0;
    if (text) {
        text = text.replace(/<\/?span.*?>/g, "");
        text = text.replace(/&([^&;]{2,8});/g, function (match, p1) {
            var r = entity[p1];
            if (r) {
                return r;
            } else {
                unreChar.push(match);
                return match;
            }
        });
        blob = new Blob([text], {
            endings: "native"
        });
        a.href = URL.createObjectURL(blob);
        a.download = filename;
        a.textContent = "Download the Text File";
        a.onclick = function () {
            if (unreChar.length > 0) {
                alert("This document may have some unrecognized characters.\n[" + unreChar[0] + "]");
            }
        };
        while (!location) {
            if (p[i].className === "ffaq_page") {
                location = p[i];
            }
            i += 1;
        }
        if (location) {
            location.appendChild(doc.createElement("br"));
            location.appendChild(a);
        } else {
            doc.body.appendChild(a);
        }
    }
}());