Skip to content

Firefox:Plugin:TabExporter

AI로 개발한 확장.

manifest.json

{
  "manifest_version": 3,
  "name": "Tab Exporter",
  "version": "1.0",
  "description": "모든 탭의 URL과 제목을 MediaWiki 형식으로 내보내기",
  "permissions": [
    "tabs",
    "activeTab"
  ],
  "action": {
    "default_popup": "popup.html",
    "default_title": "Tab Exporter"
  },
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js"]
    }
  ]
}

popup.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body {
            width: 300px;
            padding: 20px;
            font-family: Arial, sans-serif;
        }

        .header {
            text-align: center;
            margin-bottom: 20px;
        }

        .export-btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 14px;
            margin-bottom: 10px;
        }

        .export-btn:hover {
            background-color: #45a049;
        }

        .copy-btn {
            background-color: #2196F3;
            color: white;
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 12px;
            margin-top: 10px;
        }

        .copy-btn:hover {
            background-color: #0b7dda;
        }

        .output {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background-color: #f9f9f9;
            font-family: monospace;
            font-size: 12px;
            max-height: 300px;
            overflow-y: auto;
            white-space: pre-wrap;
        }

        .status {
            margin-top: 10px;
            padding: 5px;
            text-align: center;
            font-size: 12px;
        }

        .success {
            color: #4CAF50;
        }

        .error {
            color: #f44336;
        }
    </style>
</head>
<body>
    <div class="header">
        <h3>Tab Exporter</h3>
        <p>모든 탭을 MediaWiki 형식으로 내보내기</p>
    </div>

    <button id="exportAllTabs" class="export-btn">모든 탭 내보내기</button>
    <button id="exportCurrentWindow" class="export-btn">현재 창 탭만 내보내기</button>

    <div id="output" class="output" style="display: none;"></div>
    <button id="copyBtn" class="copy-btn" style="display: none;">클립보드에 복사</button>

    <div id="status" class="status"></div>

    <script src="popup.js"></script>
</body>
</html>

popup.js

document.addEventListener('DOMContentLoaded', function() {
    const exportAllTabsBtn = document.getElementById('exportAllTabs');
    const exportCurrentWindowBtn = document.getElementById('exportCurrentWindow');
    const copyBtn = document.getElementById('copyBtn');
    const output = document.getElementById('output');
    const status = document.getElementById('status');

    let currentMarkdown = '';

    // 모든 탭 내보내기
    exportAllTabsBtn.addEventListener('click', function() {
        exportTabs(false);
    });

    // 현재 창 탭만 내보내기
    exportCurrentWindowBtn.addEventListener('click', function() {
        exportTabs(true);
    });

    // 클립보드에 복사
    copyBtn.addEventListener('click', function() {
        navigator.clipboard.writeText(currentMarkdown).then(function() {
            showStatus('클립보드에 복사되었습니다!', 'success');
        }, function(err) {
            showStatus('복사 실패: ' + err, 'error');
        });
    });

    function exportTabs(currentWindowOnly) {
        const queryOptions = currentWindowOnly ? { currentWindow: true } : {};

        chrome.tabs.query(queryOptions, function(tabs) {
            if (chrome.runtime.lastError) {
                showStatus('오류: ' + chrome.runtime.lastError.message, 'error');
                return;
            }

            let markdown = '';
            let groupedTabs = {};

            // 탭을 도메인별로 그룹화
            tabs.forEach(tab => {
                try {
                    const url = new URL(tab.url);
                    const domain = url.hostname;

                    if (!groupedTabs[domain]) {
                        groupedTabs[domain] = [];
                    }

                    groupedTabs[domain].push({
                        title: tab.title || 'Untitled',
                        url: tab.url
                    });
                } catch (e) {
                    // URL 파싱 실패시 기본 그룹에 추가
                    if (!groupedTabs['기타']) {
                        groupedTabs['기타'] = [];
                    }
                    groupedTabs['기타'].push({
                        title: tab.title || 'Untitled',
                        url: tab.url
                    });
                }
            });

            // MediaWiki 포맷 생성
            markdown += `= 탭 목록 (${new Date().toLocaleString()}) =\n\n`;
            markdown += `총 ${tabs.length}개의 탭\n\n`;

            // 도메인별로 정렬하여 출력
            Object.keys(groupedTabs).sort().forEach(domain => {
                markdown += `== ${domain} ==\n\n`;
                groupedTabs[domain].forEach(tab => {
                    // 제목에서 [ ] 를 ( ) 로 변환
                    const escapedTitle = tab.title
                        .replace(/\[/g, '(')
                        .replace(/\]/g, ')');

                    markdown += `* [${tab.url} ${escapedTitle}]\n`;
                });
                markdown += '\n';
            });

            currentMarkdown = markdown;
            output.textContent = markdown;
            output.style.display = 'block';
            copyBtn.style.display = 'block';

            showStatus(`${tabs.length}개의 탭을 내보냈습니다.`, 'success');
        });
    }

    function showStatus(message, type) {
        status.textContent = message;
        status.className = `status ${type}`;
        setTimeout(() => {
            status.textContent = '';
            status.className = 'status';
        }, 3000);
    }
});

content.js

// Content script for Tab Exporter
// 필요한 경우 페이지별 추가 기능을 여기에 구현할 수 있습니다.

console.log('Tab Exporter content script loaded');

// 예시: 페이지의 메타 정보 수집 (필요시 사용)
function getPageMeta() {
    const meta = {
        title: document.title,
        url: window.location.href,
        description: '',
        keywords: ''
    };

    // 메타 태그에서 설명 추출
    const descMeta = document.querySelector('meta[name="description"]');
    if (descMeta) {
        meta.description = descMeta.content;
    }

    // 메타 태그에서 키워드 추출
    const keywordsMeta = document.querySelector('meta[name="keywords"]');
    if (keywordsMeta) {
        meta.keywords = keywordsMeta.content;
    }

    return meta;
}

// 메시지 리스너 (향후 확장용)
chrome.runtime.onMessage?.addListener((request, sender, sendResponse) => {
    if (request.action === 'getPageMeta') {
        sendResponse(getPageMeta());
    }
});

설치 방법

모두 동일 디렉토리에 위치시킨 후 Firefox:Plugin#직접 개발한 플러그인 설치 방법 항목 참조.

See also