Save GameFAQs as a text file

Save GameFAQs as a text file.

  1. // ==UserScript==
  2. // @name Save GameFAQs as a text file
  3. // @description Save GameFAQs as a text file.
  4. // @namespace undefined
  5. // @include https://www.gamefaqs.com/*
  6. // @version 0.3a
  7. // @grant none
  8. // ==/UserScript==
  9. (function () {
  10. "use strict";
  11. var doc = document;
  12. var faqText = doc.getElementById("faqtext").innerHTML;
  13. var blob;
  14. var a = doc.createElement("a");
  15. var filename = doc.URL.substr(doc.URL.lastIndexOf("/") + 1) + ".txt";
  16. var location;
  17. function organizeText(text) {
  18. var entity = {
  19. lt: "<",
  20. gt: ">",
  21. amp: "&",
  22. nbsp: " "
  23. };
  24. var unreChar = [];
  25. text = text.replace(/<\/?span.*?>/g, "");
  26. text = text.replace(/&([^&;]{2,8});/g, function (match, p1) {
  27. var r = entity[p1];
  28. if (r) {
  29. return r;
  30. } else {
  31. unreChar.push(match);
  32. return match;
  33. }
  34. });
  35. if (unreChar.length > 0) {
  36. a.onclick = function () {
  37. alert("This document may have some unrecognized characters.\n[" + unreChar[0] + "]");
  38. };
  39. }
  40. return text;
  41. }
  42. function getLocation() {
  43. var p = doc.getElementsByTagName("p");
  44. var i = 0;
  45. var length = p.length;
  46. while (i < length) {
  47. if (p[i].className === "ffaq_page") {
  48. return p[i];
  49. }
  50. i += 1;
  51. }
  52. return doc.body;
  53. }
  54. if (faqText) {
  55. faqText = organizeText(faqText);
  56. blob = new Blob([faqText], {
  57. endings: "native"
  58. });
  59. a.href = URL.createObjectURL(blob);
  60. a.download = filename;
  61. a.textContent = "Download the Text File";
  62. location = getLocation();
  63. location.appendChild(doc.createElement("br"));
  64. location.appendChild(a);
  65. }
  66. }());