├── .github └── workflows │ └── submit.yml ├── .gitignore ├── .prettierrc.mjs ├── LICENSE ├── README.md ├── assets └── icon.png ├── example.keys.json ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── src ├── components │ ├── bookmark-tree.tsx │ ├── icons.tsx │ ├── main-footer.tsx │ └── ui │ │ ├── button.tsx │ │ └── progress.tsx ├── content.tsx ├── context │ └── app-context.tsx ├── hooks │ ├── overflow.tsx │ └── use-recursive-progress.tsx ├── lib │ └── utils.tsx ├── popup │ ├── bookmark.tsx │ ├── export.tsx │ ├── finish.tsx │ ├── home.tsx │ └── index.tsx ├── style.css ├── types │ └── bookmarks.ts └── utils │ ├── bookmark │ └── chrome.ts │ ├── index.ts │ ├── tree.ts │ └── wrapper.ts ├── tailwind.config.js └── tsconfig.json /.github/workflows/submit.yml: -------------------------------------------------------------------------------- 1 | name: "Submit to Web Store" 2 | on: 3 | workflow_dispatch: 4 | 5 | jobs: 6 | build: 7 | if: github.event_name == 'release' 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - name: Cache pnpm modules 12 | uses: actions/cache@v3 13 | with: 14 | path: ~/.pnpm-store 15 | key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} 16 | restore-keys: | 17 | ${{ runner.os }}- 18 | - uses: pnpm/action-setup@v2.2.4 19 | with: 20 | version: latest 21 | run_install: true 22 | - name: Use Node.js 16.x 23 | uses: actions/setup-node@v3.4.1 24 | with: 25 | node-version: 16.x 26 | cache: "pnpm" 27 | - name: Build the extension 28 | run: pnpm build 29 | - name: Package the extension into a zip artifact 30 | run: pnpm package 31 | - name: Browser Platform Publish 32 | uses: PlasmoHQ/bpp@v3 33 | with: 34 | keys: ${{ secrets.SUBMIT_KEYS }} 35 | artifact: build/chrome-mv3-prod.zip 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 3 | 4 | # dependencies 5 | /node_modules 6 | /.pnp 7 | .pnp.js 8 | 9 | # testing 10 | /coverage 11 | 12 | #cache 13 | .turbo 14 | 15 | # misc 16 | .DS_Store 17 | *.pem 18 | 19 | # debug 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | .pnpm-debug.log* 24 | 25 | # local env files 26 | .env* 27 | 28 | out/ 29 | build/ 30 | dist/ 31 | 32 | # plasmo - https://www.plasmo.com 33 | .plasmo 34 | 35 | # bpp - http://bpp.browser.market/ 36 | keys.json 37 | 38 | # typescript 39 | .tsbuildinfo 40 | -------------------------------------------------------------------------------- /.prettierrc.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('prettier').Options} 3 | */ 4 | export default { 5 | printWidth: 80, 6 | tabWidth: 2, 7 | useTabs: false, 8 | semi: false, 9 | singleQuote: false, 10 | trailingComma: "none", 11 | bracketSpacing: true, 12 | bracketSameLine: true, 13 | plugins: ["@ianvs/prettier-plugin-sort-imports"], 14 | importOrder: [ 15 | "", // Node.js built-in modules 16 | "", // Imports not matched by other special words or groups. 17 | "", // Empty line 18 | "^@plasmo/(.*)$", 19 | "", 20 | "^@plasmohq/(.*)$", 21 | "", 22 | "^~(.*)$", 23 | "", 24 | "^[./]" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Pintree.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bookmarks Exporter 2 | 3 | ![License](https://img.shields.io/github/license/Pintree-io/bookmarks-exporter) 4 | ![Version](https://img.shields.io/github/v/release/Pintree-io/bookmarks-exporter) 5 | 6 | ## Introduction 7 | 8 | Bookmarks Exporter is an open-source Chrome extension designed to help you effortlessly export your Chrome bookmarks into organized JSON files. 9 | 10 | ## Features 11 | 12 | - **Easy Export**: Quickly export all your Chrome bookmarks with a single click. 13 | - **Organized JSON**: Exports bookmarks in a structured and easy-to-read JSON format. 14 | - **User-Friendly Interface**: Simple and intuitive user interface for a seamless experience. 15 | - **Automatically publish to store**: Automatically publish to Chrome Web Store when a new release is created. 16 | 17 | ## Installation 18 | 19 | ### From Chrome Web Store 20 | 21 | 1. Visit the [Chrome Web Store](https://chrome.google.com/webstore) and search for "Bookmarks Exporter". 22 | 2. Click "Add to Chrome" to install the extension. 23 | 24 | ### From Source 25 | 26 | 1. Clone this repository: 27 | ```sh 28 | git clone https://github.com/Pintree-io/bookmarks-exporter.git 29 | ``` 30 | 2. Navigate to the project directory: 31 | ```sh 32 | cd bookmarks-exporter 33 | ``` 34 | 3. Install dependencies using `pnpm`: 35 | ```sh 36 | pnpm install 37 | ``` 38 | 4. Build the project: 39 | ```sh 40 | pnpm build 41 | ``` 42 | 5. Open Chrome and navigate to `chrome://extensions/`. 43 | 6. Enable "Developer mode" by clicking the toggle switch in the top right corner. 44 | 7. Click "Load unpacked" and select the `dist` folder inside your project directory. 45 | 46 | ## Usage 47 | 48 | 1. Click on the Bookmarks Exporter icon in your Chrome toolbar. 49 | 2. Click the "Export Bookmarks" button. 50 | 3. Save the downloaded JSON file to your desired location. 51 | 52 | ## Development 53 | 54 | To set up the development environment: 55 | 56 | 1. Install dependencies: 57 | ```sh 58 | pnpm install 59 | ``` 60 | 2. Start the development server: 61 | ```sh 62 | pnpm dev 63 | ``` 64 | 3. Open Chrome and navigate to `chrome://extensions/`. 65 | 4. Enable "Developer mode" by clicking the toggle switch in the top right corner. 66 | 5. Click "Load unpacked" and select the `build` folder inside your project directory. 67 | 6. Rename the `example.keys.json` file to `keys.json` and fill in the corresponding fields. 68 | 7. Make your changes and refresh the extension in Chrome to see the updates. 69 | 70 | ## Contributing 71 | 72 | Contributions are welcome! Please fork this repository, create a new branch, and submit a pull request. 73 | 74 | 1. Fork the repository. 75 | 2. Create a new branch: 76 | ```sh 77 | git checkout -b feature/your-feature-name 78 | ``` 79 | 3. Commit your changes: 80 | ```sh 81 | git commit -m 'Add some feature' 82 | ``` 83 | 4. Push to the branch: 84 | ```sh 85 | git push origin feature/your-feature-name 86 | ``` 87 | 5. Open a pull request. 88 | 89 | ## License 90 | 91 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 92 | 93 | ## Contact 94 | 95 | For any inquiries or questions, feel free to open an issue or contact [viggo.zw@gmail.com](mailto:viggo.zw@gmail.com). 96 | 97 | ## Acknowledgements 98 | 99 | - [Plasmo Framework](https://www.plasmo.com) for providing a robust platform for Chrome extension development. 100 | -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pintree-io/bookmarks-exporter/fa38e1f65d94247fb20bbd56701088b22e83b808/assets/icon.png -------------------------------------------------------------------------------- /example.keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://github.com/PlasmoHQ/bpp/raw/main/keys.schema.json", 3 | "chrome": { 4 | "zip": "pintree_plugins_chrome_{version}.zip", 5 | "clientId": "1280623", 6 | "clientSecret": "1!9us4", 7 | "refreshToken": "7&as$a89", 8 | "extId": "akszypg" 9 | }, 10 | "firefox": { 11 | "file": "pintree_plugins_firefox.xpi", 12 | "extId": "aaaaaaa-aaaa-bbbb-cccc-dddddddddddd", 13 | "apiKey": "ab214c4d", 14 | "apiSecret": "e%f253^gh" 15 | }, 16 | "edge": { 17 | "zip": "pintree_plugins_edge.zip", 18 | "clientId": "aaaaaaa-aaaa-bbbb-cccc-dddddddddddd", 19 | "clientSecret": "ab#c4de6fg", 20 | "productId": "aaaaaaa-aaaa-bbbb-cccc-dddddddddddd", 21 | "accessTokenUrl": "https://login.microsoftonline.com/aaaaaaa-aaaa-bbbb-cccc-dddddddddddd/oauth2/v2.0/token", 22 | "notes": "This is a test submission" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pintree-bookmarks-exporter", 3 | "displayName": "Pintree Bookmarks Exporter", 4 | "version": "1.0.0", 5 | "description": "Effortlessly export your Chrome bookmarks to organized JSON files.", 6 | "author": "Pintree. ", 7 | "homepage": "https://pintree.io", 8 | "scripts": { 9 | "dev": "plasmo dev", 10 | "build": "plasmo build", 11 | "package": "plasmo package" 12 | }, 13 | "dependencies": { 14 | "@iconify/react": "^5.0.1", 15 | "@radix-ui/react-accordion": "^1.2.0", 16 | "@radix-ui/react-slot": "^1.1.0", 17 | "antd": "^5.19.0", 18 | "clsx": "^2.1.1", 19 | "plasmo": "0.88.0", 20 | "react": "18.2.0", 21 | "react-dom": "18.2.0", 22 | "react-router-dom": "^6.24.0", 23 | "tailwind-merge": "^2.3.0", 24 | "tailwindcss": "3.4.1" 25 | }, 26 | "devDependencies": { 27 | "@ianvs/prettier-plugin-sort-imports": "4.1.1", 28 | "@types/chrome": "0.0.258", 29 | "@types/node": "20.11.5", 30 | "@types/react": "18.2.48", 31 | "@types/react-dom": "18.2.18", 32 | "postcss": "8.4.33", 33 | "prettier": "3.2.4", 34 | "typescript": "5.3.3" 35 | }, 36 | "manifest": { 37 | "host_permissions": [ 38 | "https://*/*" 39 | ], 40 | "permissions": [ 41 | "bookmarks" 42 | ] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('postcss').ProcessOptions} 3 | */ 4 | module.exports = { 5 | plugins: { 6 | tailwindcss: {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/components/bookmark-tree.tsx: -------------------------------------------------------------------------------- 1 | import { Bookmark, Folder } from "@/components/icons" 2 | import { cn } from "@/lib/utils" 3 | import type { TreeProps as AntdTreeProps } from "antd" 4 | import { ConfigProvider, Tooltip, Tree } from "antd" 5 | import * as React from "react" 6 | 7 | type BookmarkTreeProps = AntdTreeProps & { 8 | className?: string 9 | treeData: any[] 10 | } 11 | 12 | export const BookmarkTree: React.FC = ({ 13 | className, 14 | ...props 15 | }) => { 16 | const MemoTooltip = Tooltip || React.memo(Tooltip) 17 | 18 | return ( 19 | 29 | ( 38 | 39 |
40 |
41 |
42 | {item.type === "folder" ? ( 43 | 44 | ) : ( 45 | !item.url.includes("separator.mayastudios.com") && ( 46 | 47 | ) 48 | )} 49 |
50 |
51 | {item.title} 52 |
53 |
54 | 55 | {item?.children ? ( 56 |
57 | {item.children.length} 58 |
59 | ) : ( 60 | "" 61 | )} 62 |
63 |
64 | )} 65 | /> 66 |
67 | ) 68 | } 69 | -------------------------------------------------------------------------------- /src/components/icons.tsx: -------------------------------------------------------------------------------- 1 | import type { SVGProps } from "react" 2 | 3 | export type Props = SVGProps 4 | 5 | export { Icon } from "@iconify/react" 6 | 7 | const defaultProps = { 8 | width: 24, 9 | height: 24 10 | } as const 11 | 12 | export const Logo = (props: Props) => ( 13 | 14 | 15 | 16 | 17 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | ) 42 | 43 | export const Loading = (props: Props) => ( 44 | 45 | 46 | 47 | 48 | 49 | 56 | 57 | ) 58 | 59 | export const Folder = (props: Props) => ( 60 | 61 | 62 | 63 | ) 64 | 65 | export const Bookmark = (props: Props) => ( 66 | 67 | 71 | 72 | ) 73 | 74 | export const Export = (props: Props) => ( 75 | 76 | 80 | 84 | 88 | 92 | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | 192 | 193 | ) 194 | 195 | export const Finish = (props: Props) => ( 196 | 197 | 201 | 205 | 209 | 213 | 217 | 218 | 222 | 226 | 230 | 234 | 238 | 242 | 243 | 247 | 251 | 255 | 259 | 263 | 267 | 271 | 275 | 279 | 283 | 287 | 291 | 295 | 299 | 303 | 307 | 311 | 315 | 319 | 323 | 327 | 331 | 335 | 339 | 343 | 347 | 348 | ) 349 | -------------------------------------------------------------------------------- /src/components/main-footer.tsx: -------------------------------------------------------------------------------- 1 | import { Icon } from "@/components/icons" 2 | import { getCopyYear } from "@/utils" 3 | 4 | export function MainFooter() { 5 | return ( 6 | 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /src/components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | import { Slot } from "@radix-ui/react-slot" 3 | import * as React from "react" 4 | 5 | export interface ButtonProps 6 | extends React.ButtonHTMLAttributes { 7 | asChild?: boolean 8 | } 9 | 10 | const Button = React.forwardRef( 11 | ({ className, asChild = false, ...props }, ref) => { 12 | const Comp = asChild ? Slot : "button" 13 | return ( 14 | 19 | ) 20 | } 21 | ) 22 | Button.displayName = "Button" 23 | 24 | export { Button } 25 | -------------------------------------------------------------------------------- /src/components/ui/progress.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | import * as React from "react" 3 | 4 | interface ProgressProps extends React.ComponentPropsWithoutRef<"div"> { 5 | value: number 6 | } 7 | 8 | const Progress = React.forwardRef( 9 | ({ className, value, ...props }, ref) => ( 10 |
17 |
21 |
22 | ) 23 | ) 24 | Progress.displayName = "Progress" 25 | 26 | export { Progress } 27 | -------------------------------------------------------------------------------- /src/content.tsx: -------------------------------------------------------------------------------- 1 | // import { Logo } from "@/components/icons" 2 | import cssText from "data-text:~style.css" 3 | import type { PlasmoCSConfig } from "plasmo" 4 | 5 | export const config: PlasmoCSConfig = {} 6 | 7 | export const getStyle = () => { 8 | const style = document.createElement("style") 9 | style.textContent = cssText 10 | return style 11 | } 12 | 13 | const AppOverlay = () => { 14 | return ( 15 |
16 | {/* */} 17 |
18 | ) 19 | } 20 | 21 | export default AppOverlay 22 | -------------------------------------------------------------------------------- /src/context/app-context.tsx: -------------------------------------------------------------------------------- 1 | import type { TreeDataNode } from "@/types/bookmarks" 2 | import type { ReactNode } from "react" 3 | import React, { createContext, useState } from "react" 4 | 5 | interface AppContextProps { 6 | treeData: TreeDataNode[] 7 | setTreeData: React.Dispatch> 8 | } 9 | 10 | export const AppContext = createContext(undefined) 11 | 12 | export const AppProvider = ({ children }: { children: ReactNode }) => { 13 | const [treeData, setTreeData] = useState([]) 14 | 15 | return ( 16 | 17 | {children} 18 | 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /src/hooks/overflow.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef, useState } from "react" 2 | 3 | function useOverflow(ref) { 4 | const [isOverflowing, setIsOverflowing] = useState(false) 5 | const [width, setWidth] = useState(0) 6 | 7 | useEffect(() => { 8 | const checkOverflow = () => { 9 | if (ref.current) { 10 | setIsOverflowing(ref.current.scrollWidth > ref.current.clientWidth) 11 | setWidth(ref.current.clientWidth) 12 | } 13 | } 14 | 15 | checkOverflow() 16 | 17 | window.addEventListener("resize", checkOverflow) 18 | return () => window.removeEventListener("resize", checkOverflow) 19 | }, [ref]) 20 | 21 | return { isOverflowing, width } 22 | } 23 | 24 | export default useOverflow 25 | -------------------------------------------------------------------------------- /src/hooks/use-recursive-progress.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useEffect, useRef, useState } from "react" 2 | 3 | /** 4 | * Recursive change of object array with asynchronous transform function and progress reporting 5 | * @param {Array} target Source array - Required 6 | * @param {Function} transform Async callback function, change the data structure - Required 7 | * @param {Function} onProgress Callback function to report progress - Not required 8 | * @param {String} childName The key name of the child array, the default is children - Not required 9 | * @returns data - The new array after the change 10 | * @example 11 | * // Basic Use 12 | * const [data, progress] = useRecursiveChange([...], async (item:T, index:number) => ({ ...item, test:'test' }), (progress) => console.log(progress)); 13 | */ 14 | export const useRecursiveProgress = ( 15 | target: T[], 16 | transform: (item: T, index: number) => Promise, 17 | onProgress?: (progress: number) => void, 18 | childName: string = "children" 19 | ) => { 20 | const [data, setData] = useState([]) 21 | const [progress, setProgress] = useState(0) 22 | const prevProgressRef = useRef(0) 23 | 24 | const recursiveChange = useCallback( 25 | async ( 26 | target: T[], 27 | transform: (item: T, index: number) => Promise, 28 | childName: string = "children", 29 | onProgress?: (progress: number) => void 30 | ) => { 31 | let totalItems = 0 32 | let processedItems = 0 33 | 34 | // Helper function to count total items 35 | const countItems = (array: T[]) => { 36 | totalItems += array.length 37 | array.forEach((item) => { 38 | if ( 39 | (item as any)[childName] && 40 | Array.isArray((item as any)[childName]) 41 | ) { 42 | countItems((item as any)[childName]) 43 | } 44 | }) 45 | } 46 | 47 | countItems(target) 48 | 49 | const processArray = async (array: T[]) => { 50 | return Promise.all( 51 | array.map(async (item, index) => { 52 | const transformedItem = await transform(item, index) 53 | 54 | if ( 55 | typeof transformedItem !== "object" || 56 | transformedItem === null 57 | ) { 58 | processedItems++ 59 | const currentProgress = (processedItems / totalItems) * 100 60 | if (currentProgress !== prevProgressRef.current) { 61 | prevProgressRef.current = currentProgress 62 | onProgress && onProgress(currentProgress) 63 | } 64 | return transformedItem 65 | } 66 | 67 | let newItem = { ...transformedItem } as unknown as U 68 | 69 | if ( 70 | (item as any)[childName] && 71 | Array.isArray((item as any)[childName]) 72 | ) { 73 | ;(newItem as any)[childName] = await processArray( 74 | (item as any)[childName] 75 | ) 76 | } 77 | 78 | processedItems++ 79 | const currentProgress = (processedItems / totalItems) * 100 80 | if (currentProgress !== prevProgressRef.current) { 81 | prevProgressRef.current = currentProgress 82 | onProgress && onProgress(currentProgress) 83 | } 84 | return newItem 85 | }) 86 | ) 87 | } 88 | 89 | return processArray(target) 90 | }, 91 | [] 92 | ) 93 | 94 | useEffect(() => { 95 | const transformData = async () => { 96 | const result = await recursiveChange( 97 | target, 98 | transform, 99 | childName, 100 | (progress) => { 101 | setProgress(progress) 102 | onProgress && onProgress(progress) 103 | } 104 | ) 105 | setData(result) 106 | } 107 | 108 | transformData() 109 | }, [target, transform, childName, recursiveChange, onProgress]) 110 | 111 | return [data, progress] as [U[], number] 112 | } 113 | -------------------------------------------------------------------------------- /src/lib/utils.tsx: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export const cn = (...inputs: ClassValue[]) => { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /src/popup/bookmark.tsx: -------------------------------------------------------------------------------- 1 | import { BookmarkTree } from "@/components/bookmark-tree" 2 | import { Icon, Loading } from "@/components/icons" 3 | import { Button } from "@/components/ui/button" 4 | import { AppContext } from "@/context/app-context" 5 | import type { ChangedTreeData, TreeDataNode } from "@/types/bookmarks" 6 | import { getChromeBookmarks } from "@/utils/bookmark/chrome" 7 | import { recursiveChange, recursiveFind } from "@/utils/tree" 8 | import type { TreeProps } from "antd" 9 | import { useContext, useEffect, useState } from "react" 10 | import { useNavigate } from "react-router-dom" 11 | 12 | function BookmarkPopup() { 13 | const navigate = useNavigate() 14 | const { setTreeData } = useContext(AppContext) 15 | 16 | const [loading, setLoading] = useState(true) 17 | const [data, setData] = useState([]) 18 | const [checkedKeys, setCheckedKeys] = useState([]) 19 | 20 | const onCheck: TreeProps["onCheck"] = (selectedKeys: string[], _info) => { 21 | setCheckedKeys(selectedKeys) 22 | } 23 | 24 | const getBookmarks = async () => { 25 | try { 26 | const result = await getChromeBookmarks() 27 | const bookmarks = await recursiveChange( 28 | result[0].children, 29 | async (item, _index: number) => ({ 30 | ...item, 31 | type: item?.children ? "folder" : "link" 32 | }) 33 | ) 34 | console.log(bookmarks) 35 | 36 | setData(bookmarks) 37 | } catch (error) { 38 | console.error(error) 39 | } finally { 40 | setLoading(false) 41 | } 42 | } 43 | 44 | const handleExportBookmarks = () => { 45 | const result = recursiveFind(data, (item, _index: number) => 46 | checkedKeys.includes(item.id) 47 | ) 48 | setTreeData(result) 49 | navigate("/export") 50 | } 51 | 52 | useEffect(() => { 53 | getBookmarks() 54 | }, []) 55 | 56 | return ( 57 |
58 |

Select Bookmarks

59 | {loading ? ( 60 |
61 | 62 |
Loading...
63 |
64 | ) : ( 65 |
66 | 73 |
74 | )} 75 | 76 |
77 | 84 |
85 |
86 | ) 87 | } 88 | 89 | export default BookmarkPopup 90 | -------------------------------------------------------------------------------- /src/popup/export.tsx: -------------------------------------------------------------------------------- 1 | import { Export } from "@/components/icons" 2 | import { Progress } from "@/components/ui/progress" 3 | import { AppContext } from "@/context/app-context" 4 | import type { ChangedTreeData } from "@/types/bookmarks" 5 | import { delay, getClearbitLogoUrl } from "@/utils" 6 | import { recursiveChange } from "@/utils/tree" 7 | import { useContext, useEffect, useState } from "react" 8 | import { useNavigate } from "react-router-dom" 9 | 10 | interface ExportTreeDataProps { 11 | type: "folder" | "link" 12 | addDate: number 13 | title: string 14 | icon?: string 15 | url: string 16 | } 17 | 18 | function ExportPopup() { 19 | const navigate = useNavigate() 20 | const { treeData, setTreeData } = useContext(AppContext) 21 | const [progress, setProgress] = useState(0) 22 | 23 | const exportData = async () => { 24 | // 处理数据 25 | const bookmarks = await recursiveChange< 26 | ChangedTreeData, 27 | ExportTreeDataProps 28 | >(treeData as ChangedTreeData[], async (item, _index: number) => { 29 | if (item.type === "link") { 30 | const logoUrl = await getClearbitLogoUrl(item.url) 31 | return { 32 | type: item.type, 33 | addDate: item.dateAdded, 34 | title: item.title, 35 | icon: logoUrl, 36 | url: item.url 37 | } 38 | } 39 | return { 40 | type: item.type, 41 | addDate: item.dateAdded, 42 | title: item.title, 43 | url: item.url 44 | } 45 | }) 46 | 47 | setTreeData(bookmarks) 48 | } 49 | 50 | useEffect(() => { 51 | const timer = setTimeout(async () => { 52 | setProgress(30) 53 | await delay() 54 | await exportData() 55 | await delay() 56 | setProgress(60) 57 | await delay() 58 | setProgress(100) 59 | }, 500) 60 | 61 | return () => clearTimeout(timer) 62 | }, []) 63 | 64 | useEffect(() => { 65 | const timer = setTimeout(() => { 66 | if (progress === 100) { 67 | navigate("/finish") 68 | } 69 | }, 500) 70 | 71 | return () => clearTimeout(timer) 72 | }, [progress]) 73 | 74 | return ( 75 |
76 | 77 | 78 |
79 | 80 |
81 | 82 |
83 |

Exporting...

84 |

85 | Seat comfortable, this can take a while. 86 |

87 |
88 |
89 | ) 90 | } 91 | 92 | export default ExportPopup 93 | -------------------------------------------------------------------------------- /src/popup/finish.tsx: -------------------------------------------------------------------------------- 1 | import { Finish, Icon } from "@/components/icons" 2 | import { MainFooter } from "@/components/main-footer" 3 | import { Button } from "@/components/ui/button" 4 | import { AppContext } from "@/context/app-context" 5 | import { useContext } from "react" 6 | import { useNavigate } from "react-router-dom" 7 | 8 | function FinishPopup() { 9 | const navigate = useNavigate() 10 | const { treeData } = useContext(AppContext) 11 | 12 | // 点击导出按钮后,将数据处理为 JSON 格式 13 | const onDownload = () => { 14 | const data = JSON.stringify(treeData, null, 2) 15 | const blob = new Blob([data], { type: "application/json" }) 16 | const url = URL.createObjectURL(blob) 17 | const a = document.createElement("a") 18 | a.href = url 19 | a.download = "pintree.json" 20 | a.click() 21 | URL.revokeObjectURL(url) 22 | } 23 | 24 | return ( 25 |
26 | 27 |
28 |

Export Successful !

29 |

30 | Click the button to download the json file 31 |

32 |
33 | 34 |
35 | 44 | 45 |
46 |
47 | ) 48 | } 49 | 50 | export default FinishPopup 51 | -------------------------------------------------------------------------------- /src/popup/home.tsx: -------------------------------------------------------------------------------- 1 | import { Logo } from "@/components/icons" 2 | import { MainFooter } from "@/components/main-footer" 3 | import { Button } from "@/components/ui/button" 4 | import { useNavigate } from "react-router-dom" 5 | 6 | function HomePopup() { 7 | const navigate = useNavigate() 8 | 9 | return ( 10 |
11 | 12 |
13 |

14 | Pintree Bookmarks Exporter 15 |

16 |

17 | Export Your Bookmarks to JSON File 18 |

19 |
20 | 21 |
22 | 27 | 28 |
29 |
30 | ) 31 | } 32 | 33 | export default HomePopup 34 | -------------------------------------------------------------------------------- /src/popup/index.tsx: -------------------------------------------------------------------------------- 1 | import "@/style.css" 2 | 3 | import { AppProvider } from "@/context/app-context" 4 | import { Route, HashRouter as Router, Routes } from "react-router-dom" 5 | 6 | import Bookmark from "./bookmark" 7 | import Export from "./export" 8 | import Finish from "./finish" 9 | import Home from "./home" 10 | 11 | function IndexPopup() { 12 | return ( 13 | 14 | 15 | 16 | } /> 17 | } /> 18 | } /> 19 | } /> 20 | 21 | 22 | 23 | ) 24 | } 25 | 26 | export default IndexPopup 27 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | .ant-tree-node-content-wrapper { 6 | overflow: hidden; 7 | text-overflow: ellipsis; 8 | white-space: nowrap; 9 | } 10 | -------------------------------------------------------------------------------- /src/types/bookmarks.ts: -------------------------------------------------------------------------------- 1 | export type TreeDataNode = chrome.bookmarks.BookmarkTreeNode 2 | 3 | 4 | export interface ChangedTreeData extends TreeDataNode { 5 | type: "folder" | "link" 6 | } 7 | -------------------------------------------------------------------------------- /src/utils/bookmark/chrome.ts: -------------------------------------------------------------------------------- 1 | export const getChromeBookmarks = async () => { 2 | try { 3 | const bookmarks = await new Promise((resolve, reject) => { 4 | chrome.bookmarks.getTree((bookmarks) => { 5 | if (chrome.runtime.lastError) { 6 | reject(chrome.runtime.lastError) 7 | } else { 8 | resolve(bookmarks) 9 | } 10 | }); 11 | }); 12 | return bookmarks 13 | } catch (error) { 14 | console.error('Error fetching bookmarks:', error) 15 | throw error 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /src/utils/index.ts: -------------------------------------------------------------------------------- 1 | import { fetchWrapper } from "@/utils/wrapper" 2 | 3 | export const getCopyYear = () => { 4 | const currentYear = new Date().getFullYear() 5 | const year = currentYear === 2024 ? "2024" : `2024 - ${currentYear}` 6 | return year 7 | } 8 | 9 | // Clearbit API 获取 logo URL 10 | export const getClearbitLogoUrl = async (url: string) => { 11 | const parsedUrl = new URL(url); 12 | const domain = parsedUrl.hostname; 13 | return `https://logo.clearbit.com/${domain}`; 14 | } 15 | 16 | // Google S2 Converter 获取 favicon URL 17 | export const getGoogleLogoUrl = async (url: string) => { 18 | const parsedUrl = new URL(url); 19 | return `https://www.google.com/s2/favicons?sz=64&domain_url=${parsedUrl}`; 20 | } 21 | 22 | // 获取网站的 logo 或 favicon,并进行容错处理 23 | export const getLogoUrl = async (url: string) => { 24 | try { 25 | // 尝试使用 Clearbit 获取 logo 26 | const clearbitLogoUrl = await getClearbitLogoUrl(url); 27 | await fetchWrapper(clearbitLogoUrl); // 检查是否能成功获取 28 | return clearbitLogoUrl; 29 | } catch (error) { 30 | console.warn(`Clearbit logo not found for ${url}, trying Google Favicon.`); 31 | 32 | try { 33 | // 尝试使用 Google S2 Converter 获取 favicon 34 | const googleFaviconUrl = await getGoogleLogoUrl(url); 35 | await fetchWrapper(googleFaviconUrl); // 检查是否能成功获取 36 | return googleFaviconUrl; 37 | } catch (error) { 38 | console.warn(`Google favicon not found for ${url}, using default favicon.`); 39 | 40 | // 返回默认的 favicon 41 | return undefined; 42 | } 43 | } 44 | } 45 | 46 | // 将 Logo 图标转换为 base64 编码 47 | export const logoToBase64 = async (logoUrl: string) => { 48 | try { 49 | const response = await fetchWrapper(logoUrl); 50 | const arrayBuffer = await response.arrayBuffer(); 51 | const base64 = Buffer.from(arrayBuffer).toString('base64'); 52 | const mimeType = response.headers.get('content-type')!; 53 | return `data:${mimeType};base64,${base64}`; 54 | } catch (error) { 55 | throw new Error(`Failed to convert logo to base64: ${error}`); 56 | } 57 | } 58 | 59 | /** 60 | * @description: Delayed execution 61 | * @param {number} time delay 62 | * @return Promise 63 | */ 64 | export const delay = (time: number = 500): Promise => 65 | new Promise(resolve => setTimeout(resolve, time)); 66 | -------------------------------------------------------------------------------- /src/utils/tree.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Recursive change of object array with asynchronous transform function 3 | * @param {Array} target Source array - Required 4 | * @param {Function} transform Async callback function, change the data structure - Required 5 | * @param {String} childName The key name of the child array, the default is children - Not required 6 | * @returns data - The new array after the change 7 | * @example 8 | * // Basic Use 9 | * await recursiveChange([...], async (item:T, index:number) => ({ ...item, test:'test' })) 10 | */ 11 | export const recursiveChange = async ( 12 | target: T[], 13 | transform: (item: T, index: number) => Promise, 14 | childName: string = 'children', 15 | ) => { 16 | return Promise.all(target.map(async (item, index) => { 17 | // Apply the transform function and await its result 18 | const transformedItem = await transform(item, index); 19 | 20 | // If the transformed item is not an object, return it directly 21 | if (typeof transformedItem !== 'object' || transformedItem === null) { 22 | return transformedItem; 23 | } 24 | 25 | // Create a new object only with the transformed item 26 | let newItem = { ...transformedItem } as unknown as U; 27 | 28 | // Check if a subarray exists in the original item and recurse 29 | if ((item as any)[childName] && Array.isArray((item as any)[childName])) { 30 | // Await the result of the recursive call to ensure it's properly resolved 31 | (newItem as any)[childName] = await recursiveChange((item as any)[childName], transform, childName); 32 | } 33 | 34 | return newItem; 35 | })); 36 | }; 37 | 38 | /** 39 | * Recursive flattening of a nested array 40 | * @param {Array} target Source array - Required 41 | * @returns data - The flattened array 42 | * @example 43 | * // Basic Use 44 | * const flatArray = flatten([1, [2, [3, [4, [5]]]]]); 45 | * console.log(flatArray); // Output: [1, 2, 3, 4, 5] 46 | */ 47 | export const flatten = (target: any[]): T[] => { 48 | const result: T[] = []; 49 | 50 | /** 51 | * Helper function to recursively flatten the array 52 | * @param {Array} subArray Sub-array to flatten - Required 53 | */ 54 | const recurse = (subArray: any[]): void => { 55 | subArray.forEach(el => { 56 | if (Array.isArray(el)) { 57 | recurse(el); 58 | } else { 59 | result.push(el); 60 | } 61 | }); 62 | }; 63 | 64 | recurse(target); 65 | return result; 66 | }; 67 | 68 | interface TreeNode { 69 | id: string; 70 | [key: string]: any; 71 | } 72 | 73 | /** 74 | * Recursively search for an object in an array of objects 75 | * @param {Array} sourceArray Source array - Required 76 | * @param {Function} predicate Callback function, find the target object - Required 77 | * @param {String} childKey The key name of the child array, the default is 'children' - Not required 78 | * @returns data - The target object 79 | * @example 80 | * // Basic Use 81 | * recursiveFind([...], (item:T, index:number) => item.id === 1) 82 | */ 83 | export const recursiveFind = ( 84 | sourceArray: T[], 85 | predicate: (item: T, index: number) => boolean, 86 | childKey: string = 'children', 87 | ): T[] => { 88 | const result: T[] = []; 89 | 90 | sourceArray.forEach((item, index) => { 91 | if (predicate(item, index)) { 92 | const newItem = { ...item }; 93 | if (item[childKey] && Array.isArray(item[childKey])) { 94 | (newItem[childKey] as T[]) = recursiveFind(item[childKey] as T[], predicate, childKey); 95 | } 96 | result.push(newItem); 97 | } else if (item[childKey] && Array.isArray(item[childKey])) { 98 | const children = recursiveFind(item[childKey] as T[], predicate, childKey); 99 | if (children.length > 0) { 100 | const newItem = { ...item, [childKey]: children }; 101 | result.push(newItem); 102 | } 103 | } 104 | }); 105 | 106 | return result; 107 | }; 108 | -------------------------------------------------------------------------------- /src/utils/wrapper.ts: -------------------------------------------------------------------------------- 1 | type FetchOptions = { 2 | method?: string; 3 | headers?: { [key: string]: string }; 4 | body?: any; 5 | }; 6 | 7 | export async function fetchWrapper(url: string, options: FetchOptions = {}) { 8 | const response = await fetch(url, { 9 | method: options.method || 'GET', 10 | headers: options.headers, 11 | body: options.body 12 | }); 13 | 14 | if (!response.ok) { 15 | throw new Error(`Fetch error: ${response.statusText}`); 16 | } 17 | 18 | return response; 19 | } 20 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./src/**/*.{tsx,html}"], 4 | darkMode: "class", 5 | theme: { 6 | extend: { 7 | colors: { 8 | primary: "#2D9C6C", 9 | secondary: { 10 | 100: "#F5FAF8", 11 | }, 12 | } 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plasmo/templates/tsconfig.base", 3 | "exclude": [ 4 | "node_modules" 5 | ], 6 | "include": [ 7 | ".plasmo/index.d.ts", 8 | "./**/*.ts", 9 | "./**/*.tsx" 10 | ], 11 | "compilerOptions": { 12 | "paths": { 13 | "@/*": [ 14 | "./src/*" 15 | ] 16 | }, 17 | "baseUrl": "." 18 | } 19 | } 20 | --------------------------------------------------------------------------------