Skip to content

Commit 0df1fe2

Browse files
committed
Add hashchange event listener to content script to improve tab reuse support
1 parent b9a6d0d commit 0df1fe2

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/ai-studio.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ export const ai_studio: Chatbot = {
424424
// AI Studio is quite sluggish with showing already generated tokens,
425425
// therefore we handle waiting for finished response differently than
426426
// in other chatbots.
427-
let has_sent_finished_responding = true
428427
let debounce_timer: NodeJS.Timeout
429428
const observer = new MutationObserver(() => {
430429
clearTimeout(debounce_timer)

‎apps/browser/src/content-scripts/send-prompt-content-script/send-prompt-content-script.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ import {
2727
// In case url changes on load
2828
const current_url = window.location.href
2929

30-
const hash = window.location.hash
3130
const hash_prefix_new = '#cwc'
32-
const is_cwc_hash = hash.startsWith(hash_prefix_new)
33-
34-
const batch_id = hash.substring(hash_prefix_new.length + 1)
3531

3632
const ai_studio_url = 'https://aistudio.google.com/'
3733
const is_ai_studio = current_url.startsWith(ai_studio_url)
@@ -177,6 +173,10 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
177173
const main = async () => {
178174
const session_data_key = 'cwc-session-data'
179175

176+
const hash = window.location.hash
177+
const is_cwc_hash = hash.startsWith(hash_prefix_new)
178+
const batch_id = hash.substring(hash_prefix_new.length + 1)
179+
180180
if (is_cwc_hash) {
181181
history.replaceState(
182182
null,
@@ -271,6 +271,13 @@ const main = async () => {
271271
}
272272
}
273273

274+
// Hash changes when reusing a tab
275+
window.addEventListener('hashchange', () => {
276+
if (window.location.hash.startsWith(hash_prefix_new)) {
277+
main()
278+
}
279+
})
280+
274281
if (document.readyState == 'loading') {
275282
document.addEventListener('DOMContentLoaded', main)
276283
} else {

‎apps/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Autofill for Code Web Chat",
55
"short_name": "CWC",
66
"description": "Got tired with copy and paste? Enable prompt autofill!",
7-
"version": "1.110.0",
7+
"version": "1.111.0",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

0 commit comments

Comments
 (0)