From e38d3e22c4db3e2dc39b8d42b1d9f2b6ef487942 Mon Sep 17 00:00:00 2001 From: SmAsHeD <6071159+smashedr@users.noreply.github.com> Date: Wed, 15 Nov 2023 19:30:24 -0800 Subject: [PATCH] Add Download Links/Domains Option (#32) * Add Download Links/Domains Option * Update README.md --- README.md | 1 + manifest.json | 2 +- src/html/links.html | 14 ++++++-------- src/js/links.js | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 35df113..8c51d29 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ For any issues, bugs or concerns; please [Open an Issue](https://github.com/cssn * Extract Links from Selected Text on any Site * Extract Links from Clipboard or Any Text * Open Multiple Links in Tabs from Text +* Download Links and Domains as a Text File * Copy the Text from a Link via Context Menu * Quick Filter Links with a Regular Expression * Store Regular Expressions for Quick Filtering diff --git a/manifest.json b/manifest.json index d4d3da8..992209e 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "description": "Easily extract, parse, or open all links/domains from a site or text with optional filters.", "homepage_url": "https://link-extractor.cssnr.com/", "author": "Shane", - "version": "0.1.6", + "version": "0.1.7", "manifest_version": 3, "commands": { "_execute_action": { diff --git a/src/html/links.html b/src/html/links.html index 1da266f..4e93a9e 100644 --- a/src/html/links.html +++ b/src/html/links.html @@ -39,11 +39,10 @@

Loading...

Copy Links - - + + Download Press C or L to Copy Links. @@ -60,11 +59,10 @@ Copy Domains - - + + Download Press D or M to Copy Domains. diff --git a/src/js/links.js b/src/js/links.js index a7cddff..1b24ed0 100644 --- a/src/js/links.js +++ b/src/js/links.js @@ -18,6 +18,8 @@ document.addEventListener('keyup', (event) => { const openLinksBtns = document.querySelectorAll('.open-in-tabs') openLinksBtns.forEach((el) => el.addEventListener('click', openLinksClick)) +const downFileBtns = document.querySelectorAll('.download-file') +downFileBtns.forEach((el) => el.addEventListener('click', downloadFileClick)) /** * Links Init @@ -223,3 +225,38 @@ function openLinksClick(event) { console.log('links:', links) openLinksInTabs(links) } + +/** + * Download links Button Click Callback + * @function downloadLinksClick + * @param {KeyboardEvent} event + */ +function downloadFileClick(event) { + console.log('downloadLinksClick:', event) + console.log(`openLinksBtn: ${event.target.dataset.target}`) + const input = document.querySelector(event.target.dataset.target) + const links = input.value.toString() + console.log('links:', links) + download(event.target.dataset.filename, links) + // showToast('File Downloaded.') +} + +/** + * Download filename with text + * @function download + * @param {String} filename + * @param {String} text + */ +function download(filename, text) { + console.log(`download: ${filename}`) + const element = document.createElement('a') + element.setAttribute( + 'href', + 'data:text/plain;charset=utf-8,' + encodeURIComponent(text) + ) + element.setAttribute('download', filename) + element.style.display = 'none' + document.body.appendChild(element) + element.click() + document.body.removeChild(element) +}