Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

pnpm-lock.yaml
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "logseq-copy-url",
"version": "1.0.0",
"version": "1.1.0",
"description": "A simple plugin that allows you to easily copy the URL of a link, enhancing workflow efficiency.",
"main": "dist/index.html",
"targets": {
"main": false
},
"scripts": {
"build": "bun run ./build.ts"
"dev": "vite build --watch",
"build": "vite build"
},
"logseq": {
"id": "logseq-copy-url",
"title": "Copy URL",
"icon": "./icon.png"
},
"keywords": [],
"author": "RubenSmn",
"author": "RubenSmn + tejonaco",
"license": "MIT",
"dependencies": {
"@logseq/libs": "^0.0.15"
},
"devDependencies": {
"bun-plugin-html": "^1.2.0"
"vite": "^5.2.12"
}
}
7 changes: 4 additions & 3 deletions src/copyButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { clipboardIcon, checkIcon } from ".";

export const setCopyButtons = (links: HTMLAnchorElement[]) => {
links.forEach((link) => {
if (link.nextElementSibling?.classList.contains(`${PL.id}-button`)) return;
if (link.querySelector(`.${PL.id}-button`) !== null) return

const href = link.getAttribute("href");

Expand All @@ -18,7 +18,8 @@ export const setCopyButtons = (links: HTMLAnchorElement[]) => {
// add icon
button.innerHTML = clipboardIcon;

button.addEventListener("click", async () => {
button.addEventListener("click", async e => {
e.preventDefault()
try {
await parent.navigator.clipboard.writeText(href);
button.innerHTML = checkIcon;
Expand All @@ -29,7 +30,7 @@ export const setCopyButtons = (links: HTMLAnchorElement[]) => {
});

// add button
link.insertAdjacentElement("afterend", button);
link.appendChild(button);
});
};

Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logseq as PL } from "../package.json";
import { getExternalLinks } from "./utils";
import { initLinksObserver, runLinksObserver } from "./observer";
import { removeCopyButtons, setCopyButtons } from "./copyButtons";
import { globals } from './global'

export const clipboardIcon = `
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
Expand All @@ -24,7 +25,12 @@ const main = () => {
vertical-align: middle;
cursor: pointer;
display: inline-flex;
margin-left: 0.25rem;
margin-left: 0.3rem;
width: 1.3em;
margin-bottom: 0.15rem;
}
${globals.extLinksSelector}:not(:hover) > .logseq-copy-url-button {
display: none;
}
`,
});
Expand Down
13 changes: 13 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ConfigEnv, UserConfig, defineConfig } from 'vite'

export default defineConfig((mode: ConfigEnv): UserConfig => {
return {
root: './src',
base: './',
build: {
target: 'esnext',
minify: false,
outDir: '../dist'
}
}
})