Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lunamoth/f098edd37fa903e6b42ac6ca1604467f to your computer and use it in GitHub Desktop.

Select an option

Save lunamoth/f098edd37fa903e6b42ac6ca1604467f to your computer and use it in GitHub Desktop.
// manifest.json
{
"manifest_version": 3,
"name": "더블 검색 (자동 수정판)",
"version": "1.3",
"description": "주소창에서 구글 검색 시 자동으로 Google AI 검색 탭을 함께 엽니다.",
"permissions": [
"tabs"
],
"background": {
"service_worker": "background.js"
}
}
// background.js
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// 탭의 URL이 변경되었을 때만 코드를 실행합니다.
if (changeInfo.url) {
try {
const url = new URL(changeInfo.url);
// 변경된 URL이 구글 검색 결과 페이지인지 확인합니다.
if (url.hostname === 'www.google.com' && url.pathname === '/search') {
// URL에서 검색어('q' 파라미터)를 가져옵니다.
const query = url.searchParams.get('q');
// 주소창에서 실행된 '최초의 검색'인지 확인합니다. (무한 루프 방지)
const isFirstSearch = url.searchParams.has('sourceid');
if (query && isFirstSearch) {
// 요청하신 Google AI 검색 URL을 생성합니다.
const aiSearchUrl = `https://google.com/ai?q=${encodeURIComponent(query)}`;
// ★★★ 2초 딜레이 추가 ★★★
// setTimeout 함수를 사용하여 2000밀리초(2초) 후에 코드를 실행합니다.
setTimeout(() => {
// 새 탭에서 AI 검색을 엽니다.
chrome.tabs.create({ url: aiSearchUrl });
}, 2000); // 딜레이 시간 (1000 = 1초)
}
}
} catch (e) {
// 유효하지 않은 URL 형식 등의 오류는 무시합니다.
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment