Skip to content

Commit 5b8dcc7

Browse files
committed
Refactor copyDocumentTitle using document.title
1 parent a819fe4 commit 5b8dcc7

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

dist/copyDocumentTitle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/copyDocumentTitle.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import { copyToClipboard } from "./utils/copyToClipboard";
77

8-
const titleElement = document.querySelector("title");
9-
const title = titleElement?.innerText.trim().split("\n").join("");
10-
(async () => {
11-
if (title) await copyToClipboard(title, false);
12-
})().catch((err) => console.error(err));
8+
void (async () => {
9+
if (document.title) {
10+
await copyToClipboard(document.title, false);
11+
} else {
12+
window.alert("Failed to get document title");
13+
}
14+
})();

0 commit comments

Comments
 (0)