Fix lint problems
This commit is contained in:
parent
e2ddc5221f
commit
4df79c322b
3 changed files with 46 additions and 40 deletions
13
api/toot.js
13
api/toot.js
|
@ -19,20 +19,21 @@
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
|
||||||
http
|
http
|
||||||
.createServer(async (req, res) => {
|
.createServer(async (request, response) => {
|
||||||
const buffers = [];
|
const buffers = [];
|
||||||
for await (const chunk of req) {
|
for await (const chunk of request) {
|
||||||
buffers.push(chunk);
|
buffers.push(chunk);
|
||||||
}
|
}
|
||||||
const data = Buffer.concat(buffers).toString();
|
const data = Buffer.concat(buffers).toString();
|
||||||
const params = new URLSearchParams(data);
|
const searchParameters = new URLSearchParams(data);
|
||||||
|
|
||||||
const text = params.get("text") || "";
|
const text = searchParameters.get("text") || "";
|
||||||
const instanceURL = params.get("instance") || "https://mastodon.social/";
|
const instanceURL =
|
||||||
|
searchParameters.get("instance") || "https://mastodon.social/";
|
||||||
|
|
||||||
const finalURL = new URL("share", instanceURL);
|
const finalURL = new URL("share", instanceURL);
|
||||||
finalURL.search = new URLSearchParams({ text }).toString();
|
finalURL.search = new URLSearchParams({ text }).toString();
|
||||||
|
|
||||||
res.writeHead(303, { Location: finalURL.toString() }).end();
|
response.writeHead(303, { Location: finalURL.toString() }).end();
|
||||||
})
|
})
|
||||||
.listen(8000);
|
.listen(8000);
|
||||||
|
|
|
@ -38,8 +38,8 @@ if (
|
||||||
window.location.host === "s2f.kytta.dev" ||
|
window.location.host === "s2f.kytta.dev" ||
|
||||||
window.location.host === "share2fedi.kytta.dev"
|
window.location.host === "share2fedi.kytta.dev"
|
||||||
) {
|
) {
|
||||||
fetch("//gc.zgo.at/", { method: "HEAD" })
|
// eslint-disable-next-line unicorn/prefer-top-level-await
|
||||||
.then((result) => {
|
fetch("//gc.zgo.at/", { method: "HEAD" }).then((result) => {
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,5 @@ if (
|
||||||
navigator.sendBeacon(
|
navigator.sendBeacon(
|
||||||
`https://share2fedi.goatcounter.com/count?p=%2F&s=${screen}&b=0&rnd=${random}`
|
`https://share2fedi.goatcounter.com/count?p=%2F&s=${screen}&b=0&rnd=${random}`
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
.catch((_) => {});
|
|
||||||
}
|
}
|
||||||
|
|
38
src/main.js
38
src/main.js
|
@ -30,8 +30,8 @@ const INSTANCE_LIST_URL = "https://api.joinmastodon.org/servers";
|
||||||
const LOCAL_STORAGE_KEY = "recentInstances";
|
const LOCAL_STORAGE_KEY = "recentInstances";
|
||||||
const RECENT_INSTANCES_SIZE = 5;
|
const RECENT_INSTANCES_SIZE = 5;
|
||||||
|
|
||||||
const $instance = document.getElementById("instance");
|
const $instance = document.querySelector("#instance");
|
||||||
const $instanceDatalist = document.getElementById("instanceDatalist");
|
const $instanceDatalist = document.querySelector("#instanceDatalist");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds missing "https://" and ending slash to the URL
|
* Adds missing "https://" and ending slash to the URL
|
||||||
|
@ -40,7 +40,7 @@ const $instanceDatalist = document.getElementById("instanceDatalist");
|
||||||
* @return {string} normalized URL
|
* @return {string} normalized URL
|
||||||
*/
|
*/
|
||||||
function normalizeUrl(url) {
|
function normalizeUrl(url) {
|
||||||
if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) {
|
if (!url.includes("http://") && !url.includes("https://")) {
|
||||||
url = "https://" + url;
|
url = "https://" + url;
|
||||||
}
|
}
|
||||||
if (url.charAt(url.length - 1) !== "/") {
|
if (url.charAt(url.length - 1) !== "/") {
|
||||||
|
@ -59,16 +59,18 @@ function onLoadInstancesSuccess() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentInstance = $instance.value;
|
const currentInstance = $instance.value;
|
||||||
const instanceDomains = JSON.parse(this.responseText).map((i) => i.domain);
|
const instanceDomains = JSON.parse(this.responseText).map(
|
||||||
if (currentInstance && instanceDomains.indexOf(currentInstance) < 0) {
|
(index) => index.domain
|
||||||
|
);
|
||||||
|
if (currentInstance && !instanceDomains.includes(currentInstance)) {
|
||||||
instanceDomains.push(currentInstance);
|
instanceDomains.push(currentInstance);
|
||||||
}
|
}
|
||||||
instanceDomains.sort();
|
instanceDomains.sort();
|
||||||
|
|
||||||
for (let i = 0; i < instanceDomains.length; i++) {
|
for (const instanceDomain of instanceDomains) {
|
||||||
const $option = document.createElement("option");
|
const $option = document.createElement("option");
|
||||||
$option.value = normalizeUrl(instanceDomains[i]);
|
$option.value = normalizeUrl(instanceDomain);
|
||||||
$instanceDatalist.appendChild($option);
|
$instanceDatalist.append($option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +108,8 @@ function rememberInstance(instance) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used in HTML
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function onFormSubmit(form) {
|
function onFormSubmit(form) {
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
|
@ -117,17 +121,19 @@ function onFormSubmit(form) {
|
||||||
|
|
||||||
let prefillInstance = getRecentInstances()[0];
|
let prefillInstance = getRecentInstances()[0];
|
||||||
|
|
||||||
const URLParams = window.location.search.substr(1).split("&");
|
const URLParameters = window.location.search.slice(1).split("&");
|
||||||
for (let i = 0; i < URLParams.length; i++) {
|
for (const URLParameter of URLParameters) {
|
||||||
const URLParamPair = URLParams[i].split("=");
|
const URLParameterPair = URLParameter.split("=");
|
||||||
if (URLParamPair[0] === "text") {
|
if (URLParameterPair[0] === "text") {
|
||||||
document.getElementById("text").value = decodeURIComponent(URLParamPair[1]);
|
document.querySelector("#text").value = decodeURIComponent(
|
||||||
} else if (URLParamPair[0] === "instance") {
|
URLParameterPair[1]
|
||||||
prefillInstance = decodeURIComponent(URLParamPair[1]);
|
);
|
||||||
|
} else if (URLParameterPair[0] === "instance") {
|
||||||
|
prefillInstance = decodeURIComponent(URLParameterPair[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefillInstance != null) {
|
if (prefillInstance != undefined) {
|
||||||
$instance.value = normalizeUrl(prefillInstance);
|
$instance.value = normalizeUrl(prefillInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue