diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
commit | 83354b2b88218090988dd6e526b0a2505b57e0f1 (patch) | |
tree | e3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/website.js | |
parent | 47b8f2299a483024c4a6a8876af825a010954caa (diff) | |
download | pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2 pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip |
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/website.js')
-rw-r--r-- | includes/external/addressbook/website.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/includes/external/addressbook/website.js b/includes/external/addressbook/website.js new file mode 100644 index 0000000..48aa072 --- /dev/null +++ b/includes/external/addressbook/website.js @@ -0,0 +1,57 @@ +const axios = require('axios'); +const ogs = require('open-graph-scraper'); + +function sleep(ms) { + return new Promise((res) => { + setTimeout(res, ms); + }); +} + +(async () => { + let user = process.argv[2]; + + try { + let url = new URL(user); + let data = (await ogs({ url: user })); + + if (data.error) throw data.error; + if (!data.result.success) throw new Error("Failed"); + + let obj = { + error: null, + avatar: data.result.favicon.startsWith("/") ? url.origin + data.result.favicon : ((data.result.favicon.startsWith("http:") || data.result.favicon.startsWith("https:")) ? data.result.favicon : data.result.requestUrl + "/" + data.result.favicon), + name: data.result.ogTitle, + description: url.host + (url.pathname === "/" ? "" : url.pathname), + link: data.result.requestUrl, + copy: [ + { + title: "Copy URL", + text: data.result.requestUrl + }, + { + title: "Copy URL to favicon", + text: data.result.favicon.startsWith("/") ? url.origin + data.result.favicon : ((data.result.favicon.startsWith("http:") || data.result.favicon.startsWith("https:")) ? data.result.favicon : data.result.requestUrl + "/" + data.result.favicon) + }, + { + title: "Copy home URL", + text: url.origin + }, + { + title: "Copy page title", + text: data.result.ogTitle + } + ] + } + + console.log(JSON.stringify(obj, null, 2)); + } catch (e) { + console.log(JSON.stringify({ + error: e, + avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/globe.png", + name: user, + description: "Website", + link: null, + copy: [] + }, null, 2)); + } +})();
\ No newline at end of file |