-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
63 lines (51 loc) · 1.77 KB
/
content.js
File metadata and controls
63 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
console.log("✅ content.js loaded on arXiv page");
function addSaveAsTitleButton() {
// 오른쪽 상단 View PDF 버튼 찾기
const listItems = document.querySelectorAll("div.full-text ul li");
let pdfLinkElement = null;
for (const li of listItems) {
const a = li.querySelector("a");
if (a && a.href.includes("/pdf/")) {
pdfLinkElement = a;
break;
}
}
if (!pdfLinkElement) {
console.warn("❗ PDF 링크를 찾지 못했습니다.");
return;
}
if (document.getElementById("save-as-title-btn")) {
console.log("✅ 버튼이 이미 존재합니다.");
return;
}
const button = document.createElement("button");
button.textContent = "💾 Save PDF as Title";
button.id = "save-as-title-btn";
button.style.marginTop = "5px";
button.style.padding = "6px 12px";
button.style.backgroundColor = "#4CAF50";
button.style.color = "white";
button.style.border = "none";
button.style.borderRadius = "4px";
button.style.cursor = "pointer";
button.style.display = "block";
// PDF 링크 바로 아래에 버튼 삽입
pdfLinkElement.parentElement.appendChild(button);
button.addEventListener("click", () => {
let title = document.querySelector("h1.title")?.innerText || document.title;
if (title.includes("Title:")) {
title = title.split("Title:")[1].trim();
}
const safeTitle = title.replace(/[\/:*?"<>|]/g, "").replace(/\s+/g, "_");
const pdfUrl = pdfLinkElement.href;
chrome.runtime.sendMessage({
action: "download",
url: pdfUrl,
filename: `${safeTitle}.pdf`
});
});
console.log("✅ Save PDF as Title 버튼 삽입 완료");
}
window.addEventListener("load", () => {
setTimeout(addSaveAsTitleButton, 1000); // arXiv는 JS로 DOM 구성하므로 딜레이 필요
});