如何在不使用Tampermonkey扩展的情况下加载JS

时间:2019-11-15 05:05:38

标签: javascript tampermonkey

我对网络编程了解不多。 我曾经用tampermonkey和此扩展程序来玩agar.io:

// ==UserScript==
// @name         HSLO ~saigo~ [PROD]
// @description  HSLO
// @version      6.1.8
// @author       2CL투샤르
// @match        *://agar.io/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

if (location.host === 'agar.io' && location.href !== 'https://agar.io/hslo') {
  location.href = 'https://agar.io/hslo';
  return;
}

const HSLO = new class {
  constructor() {
    this.method = 'GET';
    this.URL = 'https://saigo.hslo.io/?v=618';
    this.HTML = ``;
  }

  load() {
    this.setMessage();
    this.fetch();
  }

  setMessage() {
    document.body.innerHTML = "LOADING...";
  }

  fetch() {
    const request = new XMLHttpRequest();
    request.open(this.method, this.URL, true);
    request.onload = () => {
      this.HTML = request.responseText;
      this.write();
    };
    request.onerror = () => {
      document.body.innerHTML = "<div style='width: 100%; text-align: center; font-size: 24px; font-family: sans-serif;'>Failed to fetch HSLO files.</div>";
    }
    request.send();
  }

  write() {
    document.open();
    document.write(this.HTML);
    document.close();
  }
}

HSLO.load();

但是我需要它在不安装任何chrome扩展程序的情况下运行。 如何在网站上托管此JS,以使其无需扩展即可工作?

0 个答案:

没有答案