Greasy Fork

Save GameFAQs as textfile

Save GameFAQs as textfile.

目前为 2017-04-23 提交的版本。查看 最新版本

// ==UserScript==
// @name        Save GameFAQs as textfile
// @description Save GameFAQs as textfile.
// @namespace   undefined
// @include     https://www.gamefaqs.com/*
// @version     0.2
// @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 p = doc.getElementsByTagName("p");
    var entity = {
        lt: "<",
        gt: ">",
        amp: "&",
        nbsp: " "
    };
    var unreChar = [];
    if (text) {
        text = text.replace(/<\/?span.*?>/g, "");
        text = text.replace(/&([^&;]{1,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 Textfile";
        a.onclick = function () {
            if (unreChar.length > 0) {
                alert("This document may have some unrecognized characters.\n[" + unreChar[0] + "]");
            }
        };
        p[7].appendChild(doc.createElement("br"));
        p[7].appendChild(a);
        // doc.body.appendChild(a);
    }
}());