Save GameFAQs as a text file

Save GameFAQs as a text file.

当前为 2017-05-08 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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