2020-12-11 20:21:28 +08:00
2020-12-11 20:21:28 +08:00
2020-12-11 20:21:28 +08:00
2020-12-10 13:47:41 +08:00
2020-12-11 13:50:29 +08:00
2020-12-11 20:21:28 +08:00
2020-11-28 22:54:21 +08:00
2020-11-28 22:54:21 +08:00
2020-12-11 20:21:28 +08:00
2020-12-11 20:21:28 +08:00
2020-12-10 13:47:41 +08:00
2020-11-30 16:09:03 +08:00
2020-11-29 17:57:09 +08:00
2020-12-11 20:21:28 +08:00

调试、自动刷新

起个本地服务托管 dist,如 live-server --port=777,之后在油猴脚本中写入以下代码,当源码更新后可自动刷新:

// ==UserScript==
// ... 其他必要的配置
// @grant                   unsafeWindow
// @grant                   GM_setValue
// @grant                   GM_getValue
// @grant                   GM_log
// @grant                   GM_xmlhttpRequest
// @connect                 127.0.0.1
// @match                   *://localhost*/*
// ==/UserScript==

const loop = () => {
  GM_xmlhttpRequest({
    url: 'http://127.0.0.1:7777/index.js',
    onload: e => {
      const res = e.responseText;
      if (e.status === 200 && code !== res) {
        GM_setValue('code', res);
        location.reload();
      }
    },
  });
};

setInterval(loop, 3000);

const code = GM_getValue('code');
if (code) {
  eval(code);
}
Description
一款代理请求(包括 XMLHttpRequest 和 fetch)响应结果的油猴脚本,即 mock 请求的响应。
Readme 865 KiB
Languages
TypeScript 62.1%
Vue 35.3%
Less 2.6%