Waiting for ChatGPT response...
'; - const siderbarContainer = document.getElementById("rhs"); + const siderbarContainer = getPossibleElementByQuerySelector(config[siteName].sidebarContainerQuery); if (siderbarContainer) { siderbarContainer.prepend(container); } else { container.classList.add("sidebar-free"); - document.getElementById("rcnt").appendChild(container); + const appendContainer = getPossibleElementByQuerySelector(config[siteName].appendContainerQuery); + if (appendContainer) + appendContainer.appendChild(container); } const port = Browser.runtime.connect(); @@ -32,7 +36,11 @@ async function run(question) { port.postMessage({ question }); } -const searchInput = document.getElementsByName("q")[0]; +const matchedSites = Object.keys(config); +const siteRegex = new RegExp(`(${matchedSites.join('|')})`); +const siteName = document.location.hostname.match(siteRegex)[0]; + +const searchInput = getPossibleElementByQuerySelector(config[siteName].inputQuery); if (searchInput && searchInput.value) { // only run on first page const startParam = new URL(location.href).searchParams.get("start") || "0"; diff --git a/src/content-script/utils.mjs b/src/content-script/utils.mjs new file mode 100644 index 00000000..73061b36 --- /dev/null +++ b/src/content-script/utils.mjs @@ -0,0 +1,8 @@ +export function getPossibleElementByQuerySelector(queryArray) { + for (const query of queryArray) { + const element = document.querySelector(query); + if (element) { + return element; + } + } +} diff --git a/src/manifest.json b/src/manifest.json index 8aecf95a..5716fede 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,8 +15,22 @@ }, "content_scripts": [ { - "matches": ["https://*/search*"], - "include_globs": ["*.google.*/*"], + "matches": ["https://*/*"], + "include_globs": [ + "https://*.google.*/*", + "https://kagi.*/*", + "https://*.bing.*/*", + "https://*.yahoo.*/*", + "https://*.naver.*/*", + "https://*.brave.*/*", + "https://*.ecosia.org/*", + "https://searx.be/*", + "https://www.searx.be/*", + "https://yandex.*/*", + "https://duckduckgo.*", + "https://*.startpage.*/*", + "https://*.baidu.*" + ], "js": ["content-script.js"], "css": ["github-markdown.css", "styles.css"] } diff --git a/src/manifest.v2.json b/src/manifest.v2.json index 4be92747..8d3b4a55 100644 --- a/src/manifest.v2.json +++ b/src/manifest.v2.json @@ -15,8 +15,22 @@ }, "content_scripts": [ { - "matches": ["https://*/search*"], - "include_globs": ["*.google.*/*"], + "matches": ["https://*/*"], + "include_globs": [ + "https://*.google.*/*", + "https://kagi.*/*", + "https://*.bing.*/*", + "https://*.yahoo.*/*", + "https://*.naver.*/*", + "https://*.brave.*/*", + "https://*.ecosia.org/*", + "https://searx.be/*", + "https://www.searx.be/*", + "https://yandex.*/*", + "https://duckduckgo.*", + "https://*.startpage.*/*", + "https://*.baidu.*" + ], "js": ["content-script.js"], "css": ["github-markdown.css", "styles.css"] }