Skip to content

Commit

Permalink
chrome-extension: init project
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Login <batazor111@gmail.com>
  • Loading branch information
batazor committed Dec 8, 2022
1 parent 3d8d99e commit 8b28b60
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 20 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,27 @@ made along with its context and consequences.

##### Services

| Service | Description | Language/Framework | Docs |
|-------------------------|-----------------------------------------------------------------------|---------------------------|--------------------------------------------------|
| api | Internal GateWay | Go | [docs](./internal/services/api/README.md) |
| billing | Billing service | Go | [docs](./internal/services/billing/README.md) |
| bot | Telegram bot | JAVA | [docs](./internal/services/bot/README.md) |
| chat | Chat service | Elixir (Phoenix) | [docs](./internal/services/chat/README.md) |
| shortdb | Custom database | Go | [docs](./pkg/shortdb/README.md) |
| shortdb-operator | Kubernetes Operator for [shortdb]((./pkg/shortdb/README.md)) database | Go | [docs](./pkg/shortdb-operator/README.md) |
| csi | CSI example | Go | [docs](./internal/services/csi/README.md) |
| link | Link service | Go | [docs](./internal/services/api/README.md) |
| logger | Logger service | Go | [docs](./internal/services/logger/README.md) |
| metadata | Parser site by API | Go | [docs](./internal/services/metadata/README.md) |
| newsletter | Newsletter service | Rust | [docs](./internal/services/newsletter/README.md) |
| notify | Send notify to smtp, slack, telegram | Go | [docs](./internal/services/notify/README.md) |
| proxy | Proxy service for redirect to original URL | TypeScript | [docs](./internal/services/proxy/README.md) |
| referral | Referral program | Python | [docs](./internal/services/referral/README.md) |
| shortctl | Shortlink CLI | Go | [docs](./internal/services/cli/README.md) |
| stats | Stats server | CPP | [docs](./internal/services/stats/README.md) |
| wallet | Wallet service | Go (Solidity) | [docs](./internal/services/wallet/README.md) |
| ws | Webscoket service | Go | [docs](./internal/services/ws/README.md) |
| Service | Description | Language/Framework | Docs |
|-------------------|-----------------------------------------------------------------------|---------------------------|----------------------------------------------------------|
| api | Internal GateWay | Go | [docs](./internal/services/api/README.md) |
| billing | Billing service | Go | [docs](./internal/services/billing/README.md) |
| bot | Telegram bot | JAVA | [docs](./internal/services/bot/README.md) |
| chat | Chat service | Elixir (Phoenix) | [docs](./internal/services/chat/README.md) |
| chrome-extension | Chrome extension | JavaScript | [docs](./internal/services/chrome-extension/README.md) |
| shortdb | Custom database | Go | [docs](./pkg/shortdb/README.md) |
| shortdb-operator | Kubernetes Operator for [shortdb]((./pkg/shortdb/README.md)) database | Go | [docs](./pkg/shortdb-operator/README.md) |
| csi | CSI example | Go | [docs](./internal/services/csi/README.md) |
| link | Link service | Go | [docs](./internal/services/api/README.md) |
| logger | Logger service | Go | [docs](./internal/services/logger/README.md) |
| metadata | Parser site by API | Go | [docs](./internal/services/metadata/README.md) |
| newsletter | Newsletter service | Rust | [docs](./internal/services/newsletter/README.md) |
| notify | Send notify to smtp, slack, telegram | Go | [docs](./internal/services/notify/README.md) |
| proxy | Proxy service for redirect to original URL | TypeScript | [docs](./internal/services/proxy/README.md) |
| referral | Referral program | Python | [docs](./internal/services/referral/README.md) |
| shortctl | Shortlink CLI | Go | [docs](./internal/services/cli/README.md) |
| stats | Stats server | CPP | [docs](./internal/services/stats/README.md) |
| wallet | Wallet service | Go (Solidity) | [docs](./internal/services/wallet/README.md) |
| ws | Webscoket service | Go | [docs](./internal/services/ws/README.md) |

### Third-party Service

Expand Down
4 changes: 4 additions & 0 deletions internal/services/chrome-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## chrome-extension

It is a Chrome extension that allows you to parse the current page
and create a short link automatically.
Binary file added internal/services/chrome-extension/icons/128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/services/chrome-extension/icons/16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/services/chrome-extension/icons/32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/services/chrome-extension/icons/48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions internal/services/chrome-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"manifest_version": 3,
"name": "ShortLink",
"version": "1.0",

"action": {
"default_popup":"popup.html"
},
"description": "ShortLink is a simple URL shortener.",
"icons": {
"16":"icons/16.png",
"32":"icons/32.png",
"48":"icons/48.png",
"128":"icons/128.png"
},

"author": "batazor",
"background": {},
"permissions": [
"scripting",
"activeTab"
]
}
21 changes: 21 additions & 0 deletions internal/services/chrome-extension/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ShortLink</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/daisyui@2.42.1/dist/full.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="card w-96 bg-base-100 shadow-xl">
<div class="card-body items-center text-center">
<h2 class="card-title">ShortLink</h2>

<button class="btn btn-primary" id="addLinkButton">Parse links</button>
</div>
</div>

<script src="popup.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions internal/services/chrome-extension/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const grabBtn = document.getElementById("addLinkButton");
grabBtn.addEventListener("click",() => {
chrome.tabs.query({active: true}, (tabs) => {
const tab = tabs[0];
if (tab) {
chrome.scripting.executeScript(
{
target: {tabId: tab.id, allFrames: true},
func: grabURL
},
onResult
)
} else {
alert("There are no active tabs")
}
})
})

/*
* This function is executed in the context of the active tab.
* It grabs the URL of the page and returns it to the popup.
* @return {string} The URL of the page.
*/
function grabURL() {
const links = document.querySelectorAll("a")
return Array.from(links).map(link => ({href: link.href, text: link.innerText}))
}

function onResult(frames) {
console.log(frames)
if (!frames || !frames.length) {
alert("Could not retrieve links from specified page")
return
}

const links = frames.map(frame => frame.result)
.reduce((r1,r2)=>r1.concat(r2))

window.navigator.clipboard
.writeText(links.join("\n"))
.then(() => alert("Links copied to clipboard"))
.catch(() => alert("Could not copy links to clipboard"))

window.close()
}

0 comments on commit 8b28b60

Please sign in to comment.