Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Server will start on port 3000 (or use PORT environment variable to customize)
- Events: `page_view`, `search` (`search_scope`: `single`/`group`/`all`, `library_count`), `search_complete` (`library_count`, `failed_count`, `result_count`, `available_count`, `duration_ms`), `search_cancel` (`library_count`, `completed_count`, `duration_ms`), `my_library_select`
- Entry source: open the app with `?ref=<source>` (e.g. `?ref=ext` for the Chrome extension, `?ref=bm` for the bookmarklet; lowercase letters, digits, `-`, `_`, up to 20 chars). The first `page_view` gets `utm_source=<source>` in `page_location`, so GA4 shows it as the session source. `page_view` and `search` also carry `entry_ref`; register it as an event-scoped custom dimension in GA4 to break down searches by source.
- Bookmarklet: the bottom of the page shows a "📚 동네 도서관" button to drag to the bookmarks bar (the link text becomes the bookmark name; bookmarklets have no favicon, so the emoji stands in for one). On any site, select a book title (or type one when nothing is selected) and click it to open `/?title=<title>&ref=bm`. When the app is opened with `ref` but no `library`, it searches the user's "내 도서관" (up to 5 recently searched libraries, stored in this site's localStorage) instead of every library; with no saved libraries it only fills in the title. The search wizard shows that scope as "내 도서관 (…)" and the search button keeps searching those libraries until the library, region, module or filter selection changes. Older bookmarklets that include `library` keep searching that library.
- Chrome extension: [`extension/`](extension/README.md) does the same from the right-click menu or the toolbar icon and opens `/?title=<title>&ref=ext`. Load it with "Load unpacked" in `chrome://extensions`.

## Library Regions

Expand Down
40 changes: 40 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 동네 도서관에서 찾기 (크롬 확장)

웹에서 본 책 제목을 드래그해 [동네 도서관](https://dongne.onrender.com/)에서 바로 찾는 크롬 확장입니다.
같은 일을 하는 북마클릿은 사이트 맨 아래 "📚 동네 도서관" 버튼입니다.

## 쓰는 법

- 제목을 드래그하고 우클릭 → **📚 동네 도서관에서 "…" 찾기**
- 또는 제목을 드래그하고 툴바의 확장 아이콘을 누릅니다. 선택이 없으면 사이트만 엽니다.

새 탭에서 `https://dongne.onrender.com/?title=<제목>&ref=ext` 가 열립니다. 도서관은 넣지 않으므로 사이트가
내 도서관(그 사이트에서 최근에 검색한 도서관 최대 5곳)에서 찾고, 내 도서관이 없으면 제목만 채워 둡니다.
GA 에서는 `entry_ref=ext` 로 구분됩니다.

## 설치 (압축해제된 확장 프로그램)

1. `chrome://extensions` 를 엽니다.
2. 오른쪽 위 **개발자 모드** 를 켭니다.
3. **압축해제된 확장 프로그램을 로드합니다** → 이 `extension/` 폴더를 고릅니다.
4. 툴바의 퍼즐 아이콘에서 "동네 도서관에서 찾기" 를 고정하면 아이콘이 보입니다.

코드를 고친 뒤에는 `chrome://extensions` 에서 새로고침(↻)을 누릅니다.

## 권한

| 권한 | 쓰는 곳 |
|---|---|
| `contextMenus` | 우클릭 메뉴 |
| `activeTab`, `scripting` | 툴바 아이콘을 눌렀을 때만 그 탭의 선택한 텍스트를 읽습니다 |

페이지 내용을 미리 읽거나 다른 곳으로 보내지 않습니다. 빌드 과정은 없습니다 (순수 JS, Manifest V3).

## 구성

| 파일 | 내용 |
|---|---|
| `manifest.json` | 확장 설정 |
| `background.js` | 우클릭 메뉴·툴바 아이콘 처리 |
| `searchUrl.js` | 검색 주소 만들기 (테스트: `searchUrl.test.js`, `npm run test:server` 에 포함) |
| `icons/` | 사이트 로고(`public/logo.jpg`)의 책 더미를 잘라 만든 16·32·48·128px 아이콘 |
33 changes: 33 additions & 0 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { buildSearchUrl } from "./searchUrl.js";

const MENU_ID = "dongne-search";

chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: MENU_ID,
title: "📚 동네 도서관에서 \"%s\" 찾기",
contexts: ["selection"],
});
});

const openSearch = (text, tab) =>
chrome.tabs.create({ url: buildSearchUrl(text), index: tab ? tab.index + 1 : undefined });

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === MENU_ID) openSearch(info.selectionText, tab);
});

// 툴바 아이콘: 선택한 텍스트로 찾고, 선택이 없거나 읽을 수 없는 페이지(chrome:// 등)면 사이트만 연다
chrome.action.onClicked.addListener(async (tab) => {
let text = "";
try {
const [result] = await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: () => String(getSelection()),
});
text = result?.result ?? "";
} catch {
// 스크립트를 넣을 수 없는 페이지
}
openSearch(text, tab);
});
Binary file added extension/icons/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"manifest_version": 3,
"name": "동네 도서관에서 찾기",
"short_name": "동네 도서관",
"version": "0.1.0",
"description": "웹에서 본 책 제목을 드래그해 내 동네 도서관에서 빌릴 수 있는지 바로 찾습니다.",
"homepage_url": "https://dongne.onrender.com/",
"permissions": ["contextMenus", "activeTab", "scripting"],
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_title": "선택한 제목을 동네 도서관에서 찾기",
"default_icon": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
}
},
"icons": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
}
}
22 changes: 22 additions & 0 deletions extension/searchUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 확장이 여는 검색 주소. 북마클릿(src/utils/bookmarklet.ts)과 같은 규칙이다.
export const SITE_ORIGIN = "https://dongne.onrender.com";

/** 선택한 텍스트를 제목으로 다듬는다. 줄바꿈·연속 공백은 한 칸, 최대 100자 */
export const normalizeTitle = (text) =>
String(text ?? "")
.replace(/\s+/g, " ")
.trim()
.slice(0, 100)
.trim();

/**
* 제목이 있으면 `/?title=…&ref=ext`, 없으면 `/?ref=ext` 를 돌려준다.
* 도서관은 넣지 않는다. 사이트가 ref 를 보고 내 도서관에서 찾는다.
*/
export const buildSearchUrl = (text, origin = SITE_ORIGIN) => {
const url = new URL("/", origin);
const title = normalizeTitle(text);
if (title) url.searchParams.set("title", title);
url.searchParams.set("ref", "ext");
return url.href;
};
32 changes: 32 additions & 0 deletions extension/searchUrl.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, it, expect } from "vitest";
import { buildSearchUrl, normalizeTitle } from "./searchUrl.js";

describe("확장 검색 주소", () => {
it("선택한 제목과 ref=ext 로 사이트를 연다", () => {
const url = new URL(buildSearchUrl("채식주의자"));

expect(url.origin).toBe("https://dongne.onrender.com");
expect(url.searchParams.get("title")).toBe("채식주의자");
expect(url.searchParams.get("ref")).toBe("ext");
expect(url.searchParams.has("library")).toBe(false);
});

it("줄바꿈·연속 공백을 한 칸으로 줄이고 100자로 자른다", () => {
expect(normalizeTitle(" 비전공자도\n이해할 수 있는\tLLM ")).toBe("비전공자도 이해할 수 있는 LLM");
expect(normalizeTitle("가".repeat(150))).toHaveLength(100);
});

it("선택이 없으면 제목 없이 ref=ext 만 붙인다", () => {
const url = new URL(buildSearchUrl(" "));

expect(url.searchParams.has("title")).toBe(false);
expect(url.searchParams.get("ref")).toBe("ext");
expect(new URL(buildSearchUrl(undefined)).searchParams.has("title")).toBe(false);
});

it("& · # 같은 문자도 제목에 그대로 담는다", () => {
const url = new URL(buildSearchUrl("R&D #1 가이드"));

expect(url.searchParams.get("title")).toBe("R&D #1 가이드");
});
});
2 changes: 1 addition & 1 deletion vitest.config.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
test: {
globals: true,
environment: "node",
include: ["server.test.ts", "mcpAnalytics.test.ts", "librarySearch.test.ts"],
include: ["server.test.ts", "mcpAnalytics.test.ts", "librarySearch.test.ts", "extension/**/*.test.js"],
exclude: ["src/**", "node_modules/**", "package.test.ts"],
},
});
Loading