From ca47ee3e30c2006e075259ea1c57960cfe031426 Mon Sep 17 00:00:00 2001 From: Sangeeth Sudheer Date: Sat, 23 Nov 2024 16:11:52 +0530 Subject: [PATCH] Update ChatGPT script, bump-versions script --- .../ChatGPTChatPrefixer.user.js | 41 ++++++++++--------- scripts/bump-version.sh | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js b/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js index 56ea0bb..9508cb2 100644 --- a/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js +++ b/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @name Prefix ChatGPT chats with "S:" // @namespace http://tampermonkey.net/ -// @version 2024-11-23 +// @version 2024-11-23T16:11:30+05:30 // @description For TOTALLY legit usage reasons... // @author Sangeeth Sudheer -// @match https://chatgpt.com/c/* +// @match https://chatgpt.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=chatgpt.com // @updateURL https://git.sangeeth.dev/x/userscripts/raw/branch/main/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js // @downloadURL https://git.sangeeth.dev/x/userscripts/raw/branch/main/chatgpt-chat-prefixer/ChatGPTChatPrefixer.user.js @@ -17,7 +17,7 @@ const PREFIX = "S: "; const sels = { - activeChatSidebarItem: '[data-testid^="history-item"]:has(> [class*="active"])', + activeChatSidebarItem: '[data-testid^="history-item"]:has(> [class~="bg-token-sidebar-surface-secondary"])', renamePopoverItem: '[data-testid="share-chat-menu-item"] + div', } @@ -60,17 +60,20 @@ _wait(); } - let isRunning = false; + async function getStableLabelText(el) { + while (true) { + const prev = el.textContent.trim(); + await wait(1000); + const curr = el.textContent.trim(); + + if (prev === curr) { + return curr; + } + } + } async function main() { try { - if (isRunning) { - console.log("Script already running"); - return; - } - - isRunning = true; - const menuItem = document.querySelector(sels.activeChatSidebarItem); if (!menuItem) { @@ -78,7 +81,7 @@ return; } - const label = menuItem.querySelector("a").textContent.trim(); + const label = await getStableLabelText(menuItem.querySelector("a")); if (/new chat/i.test(label)) { console.log("Chat label isn't yet autopopulated by LLM"); @@ -91,16 +94,16 @@ } triggerEnterKey(menuItem.querySelector("button")); - await wait(500); + await wait(100); document.querySelector(sels.renamePopoverItem).click(); - await wait(2000); + await wait(500); const input = menuItem.querySelector("input"); const prevValue = input.value; input.focus(); - await wait(500); + await wait(100); input.value = `${PREFIX}${label}`; @@ -112,15 +115,15 @@ input.dispatchEvent(inputEvent); triggerEnterKey(input); - await wait(500); + await wait(100); console.log("Renamed chat"); - isRunning = false; } finally { - isRunning = false; + setTimeout(main, 5000); } } - setInterval(main, 5000); + setTimeout(main, 5000); })(); + diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 41641b0..2ce4470 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -4,4 +4,4 @@ script=$1 echo $script -find . -name "$script" -exec sed -i '' -e "s=\(// @version[ ]*\).*=\\1$(date -I'seconds')=g" {} \; \ No newline at end of file +find . -iname "*$script*.user.js" -type f -exec sed -i '' -e "s=\(// @version[ ]*\).*=\\1$(date -I'seconds')=g" {} \;