-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Victor Login <batazor111@gmail.com>
- Loading branch information
Showing
9 changed files
with
114 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |