Add configurable prefix for chatgpt prefixer (gpt)

This commit is contained in:
Sangeeth Sudheer 2024-11-23 16:20:36 +05:30
parent ca47ee3e30
commit bff9abbf7d
Signed by: x
GPG Key ID: F6D06ECE734C57D1

View File

@ -3,23 +3,34 @@
// @namespace http://tampermonkey.net/
// @version 2024-11-23T16:11:30+05:30
// @description For TOTALLY legit usage reasons...
// @author Sangeeth Sudheer
// @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
// @grant none
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
const PREFIX = "S: ";
GM_registerMenuCommand('Set Prefix', setPrefix);
function setPrefix() {
const currentPrefix = GM_getValue('PREFIX', 'S: ');
const newPrefix = prompt('Enter the new prefix:', currentPrefix);
if (newPrefix !== null) {
GM_setValue('PREFIX', newPrefix);
alert('Prefix set to: ' + newPrefix);
}
}
function getPrefix() {
return GM_getValue('PREFIX', 'S: ');
}
const sels = {
activeChatSidebarItem: '[data-testid^="history-item"]:has(> [class~="bg-token-sidebar-surface-secondary"])',
renamePopoverItem: '[data-testid="share-chat-menu-item"] + div',
}
};
function triggerEnterKey(el) {
const event = new KeyboardEvent('keydown', {
@ -32,32 +43,7 @@
}
function wait(ms) {
const { resolve, reject, promise } = Promise.withResolvers();
setTimeout(resolve, ms);
return promise;
}
function waitFor(sel, el = document) {
const { resolve, reject, promise } = Promise.withResolvers();
let count = 0;
function _wait() {
if (el.querySelector(sel)) {
resolve();
}
++count;
if (count >= 5) {
reject();
}
setTimeout(_wait, 1000);
}
_wait();
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getStableLabelText(el) {
@ -88,7 +74,9 @@
return;
}
if (label.startsWith(PREFIX)) {
const prefix = getPrefix();
if (label.startsWith(prefix)) {
console.log("No need to rename chat");
return;
}
@ -105,7 +93,7 @@
input.focus();
await wait(100);
input.value = `${PREFIX}${label}`;
input.value = `${prefix}${label}`;
if (input._valueTracker) {
input._valueTracker.setValue(prevValue);
@ -123,7 +111,5 @@
}
}
setTimeout(main, 5000);
})();