Use assproc! (idk if IE8 still works but I'm killing that compat soon anyway)

This commit is contained in:
flash 2024-08-11 15:34:30 +02:00
parent c477551412
commit e4b551a789
8 changed files with 1562 additions and 9 deletions

6
.gitignore vendored
View file

@ -2,3 +2,9 @@
.DS_Store .DS_Store
[Tt]humbs.db [Tt]humbs.db
desktop.ini desktop.ini
config.json
/public/robots.txt
/.debug
/node_modules
/public/assets
/public/index.html

42
build.js Normal file
View file

@ -0,0 +1,42 @@
const assproc = require('@railcomm/assproc');
const { join: pathJoin } = require('path');
const fs = require('fs');
const exec = require('util').promisify(require('child_process').exec);
(async () => {
const config = JSON.parse(fs.readFileSync(pathJoin(__dirname, 'config.json')));
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
const env = {
root: __dirname,
source: pathJoin(__dirname, 'src'),
public: pathJoin(__dirname, 'public'),
debug: isDebug,
swc: {
es: 'es5',
},
vars: {
html: {}, // BUG: if this isn't definited prior, assproc will fail
build: {
DEBUG: isDebug,
IPV4_LOOKUP: config.ipv4_lookup,
IPV6_LOOKUP: config.ipv6_lookup,
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout.trim(),
},
},
};
const tasks = {
js: [
{ source: 'ipaddr.js', target: '/assets', name: 'ipaddr.{hash}.js', vars: { html: ':source' } },
],
css: [
{ source: 'ipaddr.css', target: '/assets', name: 'ipaddr.{hash}.css', vars: { html: ':source' } },
],
html: [
{ source: 'index.html', target: '/', name: 'index.html', template: 'html' },
],
};
await assproc.process(env, tasks);
})();

4
config.json.example Normal file
View file

@ -0,0 +1,4 @@
{
"ipv4_lookup": "//ipv4.flash.moe",
"ipv6_lookup": "//ipv6.flash.moe"
}

1498
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

5
package.json Normal file
View file

@ -0,0 +1,5 @@
{
"dependencies": {
"@railcomm/assproc": "^1.0.0"
}
}

View file

@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="//fonts.googleapis.com"> <link rel="preconnect" href="//fonts.googleapis.com">
<link rel="preconnect" href="//fonts.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.gstatic.com" crossorigin>
<link href="/style.css" rel="stylesheet"> <link href="{ipaddr.css}" rel="stylesheet">
<link href="//fonts.googleapis.com/css2?family=Electrolize&family=Victor+Mono:ital,wght@0,100..700;1,100..700&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&display=swap" rel="stylesheet"> <link href="//fonts.googleapis.com/css2?family=Electrolize&family=Victor+Mono:ital,wght@0,100..700;1,100..700&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&display=swap" rel="stylesheet">
</head> </head>
<body> <body>
@ -33,6 +33,6 @@
<a class="info-link" href="//flash.moe" target="_blank" rel="noopener">flashwave</a> 2020-2024 <a class="info-link" href="//flash.moe" target="_blank" rel="noopener">flashwave</a> 2020-2024
| <a class="info-link" href="//patchii.net/flash/ip.flash.moe" target="_blank" rel="noopener">source code</a> | <a class="info-link" href="//patchii.net/flash/ip.flash.moe" target="_blank" rel="noopener">source code</a>
</div> </div>
<script src="/script.js"></script> <script src="{ipaddr.js}"></script>
</body> </body>
</html> </html>

View file

@ -1,3 +1,5 @@
#vars window build
var createXHR = function() { var createXHR = function() {
if('all' in document && !('atob' in window) && 'XDomainRequest' in window) if('all' in document && !('atob' in window) && 'XDomainRequest' in window)
return new XDomainRequest; return new XDomainRequest;
@ -62,6 +64,7 @@ var copyTextInElement = function(target, skipClipboardAPI) {
(function() { (function() {
var fields = document.querySelectorAll('.js-address'); var fields = document.querySelectorAll('.js-address');
var urls = { ipv4: window.IPV4_LOOKUP, ipv6: window.IPV6_LOOKUP };
for(var i = 0; i < fields.length; ++i) for(var i = 0; i < fields.length; ++i)
(function(field) { (function(field) {
@ -76,17 +79,12 @@ var copyTextInElement = function(target, skipClipboardAPI) {
setValueField('loading...'); setValueField('loading...');
var subdomain = field.getAttribute('data-subdomain'); var subdomain = field.getAttribute('data-subdomain');
if(typeof subdomain !== 'string') if(typeof subdomain !== 'string' && !(subdomain in urls))
return; return;
var copyButton = field.querySelector('.js-address-copy'); var copyButton = field.querySelector('.js-address-copy');
var host = location.host.split('.'); getRemoteString(urls[subdomain], function(info) {
host[0] = subdomain;
var url = location.protocol + '//' + host.join('.') + '/';
getRemoteString(url, function(info) {
if(!info.success) { if(!info.success) {
setValueField('not available'); setValueField('not available');