diff --git a/assets/scripts.js b/assets/scripts.js index 3b49fdf..f5c9d40 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -245,7 +245,7 @@ async function displayProfile(opts) { async function verifyProof(url, fingerprint) { // Init - let reVerify, output = {url: url, type: null, proofUrl: url, proofUrlFetch: null, isVerified: false, display: null}; + let reVerify, match, output = {url: url, type: null, proofUrl: url, proofUrlFetch: null, isVerified: false, display: null}; // DNS if (/^dns:/.test(url)) { @@ -277,6 +277,30 @@ async function verifyProof(url, fingerprint) { return output; } } + // Twitter + if (/^https:\/\/twitter.com/.test(url)) { + output.type = "twitter"; + match = url.match(/https:\/\/twitter\.com\/(.*)\/status\/(.*)/); + output.display = `@${match[1]}`; + output.url = `https://twitter.com/${match[1]}`; + output.proofUrlFetch = `/server/verifyTweet.php?id=${match[2]}&fp=${fingerprint}`; + try { + response = await fetch(output.proofUrlFetch, { + headers: { + Accept: 'application/json' + }, + credentials: 'omit' + }); + if (!response.ok) { + throw new Error('Response failed: ' + response.status); + } + json = await response.json(); + output.isVerified = json.verified; + } catch (e) { + } finally { + return output; + } + } // HN if (/^https:\/\/news.ycombinator.com/.test(url)) { output.type = "hn"; diff --git a/server/verifyTweet.php b/server/verifyTweet.php new file mode 100644 index 0000000..7ff6ecf --- /dev/null +++ b/server/verifyTweet.php @@ -0,0 +1,30 @@ +