Guest User

js is garbage

a guest
Mar 25th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. console.log("Disclaimer: some websites may take some time to load and parse so please be patient, all websites tested so far work")
  2. const readline = require('readline').createInterface({
  3. input: process.stdin,
  4. output: process.stdout
  5. });
  6. const jsdom = require("jsdom");
  7. const { stringify } = require('querystring');
  8. var raw = ""
  9. var tables = ""
  10. var links1 = []
  11. var lmfaooo = []
  12. var path = []
  13. const request = require('request');
  14. const { getSystemErrorMap } = require('util');
  15. function getstuff(link) {
  16. request(link, function (error, response, body) {
  17. raw = body
  18. var doc = new jsdom.JSDOM(raw);
  19. tables = doc.window.document.getElementsByTagName("table")
  20. for (let i = 0; i < tables.length; i++) {
  21. tables[i].innerHTML = ""
  22. }
  23. raw = doc.window.document.documentElement.outerHTML
  24. raw = raw.substring(raw.indexOf("firstHeading"))
  25. raw = raw.substring(raw.indexOf("<p>"))
  26. raw = raw.substring(0,raw.indexOf("<h2>"))
  27. doc = new jsdom.JSDOM(raw);
  28. var links = doc.window.document.getElementsByTagName("a")
  29. for (let i = 0;i<links.length;i++){
  30. links1[i] = links[i].getAttribute("href")
  31. links[i].setAttribute("href", i)
  32. }
  33. raw = doc.window.document.documentElement.outerHTML
  34. raw = raw.replace(/ *\([^)]*\) */g, "")
  35. raw = restorelinks(raw)
  36. raw = raw.substring(raw.indexOf('a href="/wiki/') + 14)
  37. raw = raw.substring(0, raw.indexOf('"'))
  38. console.log(raw)
  39. if (path.indexOf(raw)!=-1){
  40. console.log("Loop detected, looped back to "+raw+", path to philosophy not found")
  41. return;
  42. }
  43. path.push(raw)
  44. if (raw != "Philosophy") {
  45. getstuff("https://en.wikipedia.org/wiki/" + raw)
  46. }
  47. else {
  48. lmfaooo = path
  49. }
  50. })
  51. return lmfaooo
  52. }
  53. function restorelinks(bruh){
  54. var pos = 0
  55. while (bruh.indexOf("a href", pos)!=-1){
  56. bruh = bruh.substring(0,bruh.indexOf('a href="', pos)+8)+links1[parseInt(bruh.substring(bruh.indexOf('a href="', pos)+8,bruh.indexOf('"',bruh.indexOf('a href="', pos)+8)))]+bruh.substring(bruh.indexOf('"',bruh.indexOf('a href="', pos)+8))
  57. pos = bruh.indexOf("a href", pos)+7
  58. }
  59. return bruh
  60. }
  61. readline.question(`Do you want to enter a link to a wikipedia page?`, name => {
  62. if (name.toLowerCase() == "yes") {
  63. readline.question(`Please enter your link:`, g => {
  64. getstuff(g)
  65. readline.close()
  66. })
  67. } else {
  68. readline.question(`Would you like to start from a random page?`, name1 => {
  69. if (name1.toLowerCase() == "yes") {
  70. getstuff("https://en.wikipedia.org/wiki/Special:Random")
  71. readline.close()
  72. }
  73. else {
  74. readline.question(`Would you like to display the longest length from 25 pages?(they run at the same time)`, name2 => {
  75. if (name2.toLowerCase() == "yes") {
  76. var max = ["g"]
  77. var s = ["s"]
  78. for (let i = 0;i<25;i++){
  79. s = getstuff("https://en.wikipedia.org/wiki/Special:Random")
  80. if (max.length<s.length){
  81. max = s
  82. }
  83. }
  84. console.log("The longest path was:"+max)
  85. readline.close()
  86. }
  87. else {
  88. console.log("sorry!")
  89. readline.close()
  90. }
  91. })
  92. }
  93. })
  94. }
  95. })
Advertisement
Add Comment
Please, Sign In to add comment