From bee1f61d8f7c47cab0b11cd5ae9ddfa42326d15f Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 13 Apr 2024 18:41:22 -0400 Subject: [PATCH] initial commit --- .gitignore | 6 ++++ README.md | 0 extension/README.md | 2 ++ extension/unshorten/background.js | 41 ++++++++++++++++++++++++ extension/unshorten/icons/border-48.png | Bin 0 -> 225 bytes extension/unshorten/manifest.json | 23 +++++++++++++ server/README.md | 2 ++ server/requirements.txt | 2 ++ server/src/main.py | 29 +++++++++++++++++ 9 files changed, 105 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 extension/README.md create mode 100644 extension/unshorten/background.js create mode 100644 extension/unshorten/icons/border-48.png create mode 100644 extension/unshorten/manifest.json create mode 100644 server/README.md create mode 100644 server/requirements.txt create mode 100644 server/src/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f380988 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea +venv + +__pycache__ +*.py[cod] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/extension/README.md b/extension/README.md new file mode 100644 index 0000000..c5dc95f --- /dev/null +++ b/extension/README.md @@ -0,0 +1,2 @@ +# Unshorten +A Firefox extension to unshorten links from sites like Twitter. \ No newline at end of file diff --git a/extension/unshorten/background.js b/extension/unshorten/background.js new file mode 100644 index 0000000..22203cc --- /dev/null +++ b/extension/unshorten/background.js @@ -0,0 +1,41 @@ +const shortenerDomains = [ + "t.co" +]; + +browser.contextMenus.create({ + id: "unshorten-link", + title: "Unshorten link", + contexts: ["link"], + }, + // See https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/#event-pages-and-backward-compatibility + // for information on the purpose of this error capture. + () => void browser.runtime.lastError, +); + +browser.contextMenus.onClicked.addListener((info, tab) => { + if (info.menuItemId === "unshorten-link") { + const linkUrl = info.linkUrl; + const linkDomain = getDomainFromUrl(linkUrl); + const canShorten = shortenerDomains.includes(linkDomain); + + if (canShorten) { + unshortenUrl(linkUrl); + } + } +}); + +function getDomainFromUrl(linkUrl) { + const url = new URL(linkUrl); + return url.hostname; +} + +function unshortenUrl(linkUrl) { + console.log(linkUrl); + + fetch("http://localhost:8000/?url=" + linkUrl) + .then(res => { + if (res.ok) { + console.log(res); + } + }); +} \ No newline at end of file diff --git a/extension/unshorten/icons/border-48.png b/extension/unshorten/icons/border-48.png new file mode 100644 index 0000000000000000000000000000000000000000..90687de26d71e91b7c82565772a7df470ae277a6 GIT binary patch literal 225 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq zxP?KOkzv*x37}xJr;B4qM&sM7j(iOY0?rpNR{Ym~eNUieh4I>d+mEvHuIy!K@bZ41 zJ}N$e^&*#q7kxbW`Aeg?)>n&l0$ z8xrIlb~3+dVExT-N;ZLA=LS%o!8+lf-GRA$F@Klex9jiV-^0Mj@Zdh*s&