scrapbox-wandbox-proxy
実装したいこと
NDJSONに対応させる
Async Generatorでwrapする
Typescriptで書く
GitHubに移す
code:tamperMonkey.js
// ==UserScript==
// @name wandbox proxy
// @version 0.1
// @description ScrapboxからWandbox APIを叩くのに使うやつ
// @author takker
// @connect wandbox.org
// @grant GM_xmlhttpRequest
// @license MIT
// @copyright Copyright (c) 2021 takker
// ==/UserScript==
"use strict"
unsafeWindow.fetchWandBox = (pathname, {method, body} = {}) => new Promise(resolve =>
GM_xmlhttpRequest({
method: method ?? 'GET',
url: https://wandbox.org${pathname},
...(method === 'POST' ? {
headers: {'Content-Type': 'application/json'},
data: body,
} : {}
),
withCredentials: true,
responseType: 'json',
onload: ({response: json}) => resolve(json),
})
);
test code
code:js
await fetchWandBox('/api/template/rust')
code:js
await fetchWandBox('/api/compile.json', {
method: 'POST',
body: JSON.stringify({
code: [
'#include <iostream>',
'int main() { int x = 0; std::cout << "hoge" << std::endl; }',
].join('\n'),
options: 'warning,gnu++1y',
compiler: 'gcc-head',
'compiler-option-raw': '-Dx=hogefuga\n-O3',
}),
});
code:js
await fetchWandBox('/api/compile.json', {
method: 'POST',
body: JSON.stringify({
code: [
'fn main() {',
' println!("Hello, Wandbox!");',
'}',
].join('\n'),
compiler: 'rust-head',
}),
});