如何逐行读取在线文件?

How to read online file line by line?

对于这个非常基本的问题,我很抱歉,但我找不到答案。基本上我正在尝试阅读 this file line-by-line, then in another HTML page whenever there is a string that match one of these lines, then it will be wrapped within the <span class="hello">...</span> tag. For the latter I can use the findAndReplaceDOMText 库,我认为前者也应该很容易。但我只能找到阅读上传文件的答案。即使用

<input type="file" name="file" id="file">

上传。例如:How to use Javascript to read local text file and read line by line?, Reading line-by-line file in JavaScript on client side. Googling js read line by line 只有 returns 结果 Node.js

您可以使用 Fetch API 并以文本形式读取响应并逐行迭代

(async () => {
  const response = await fetch("https://xn--qucu-hr5aza.cc/files/M%E1%BB%99t%20h%E1%BB%87%20th%E1%BB%91ng%20ni%E1%BB%81m%20tin/Node%20list");
  const data = await response.text();
  const lines = data.split("\n");
  console.log(lines)
})();