Skip to content

Commit 0340a5c

Browse files
committed
feat(ui): improve "Get Plus" button relocation logic for multiple class variants
- Support multiple possible `Get Plus` class names when querying the element - Assign detected styling class to the injected model switcher - Move the `Get Plus` button next to the native model switcher and clear its original classes
1 parent c8f5eea commit 0340a5c

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

ChatGPT-Zero.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name ChatGPT Zero
33
// @namespace https://github.com/NextDev65/
4-
// @version 0.58
4+
// @version 0.59
55
// @description Enhancements for ChatGPT
66
// @author NextDev65
77
// @downloadURL https://raw.githubusercontent.com/NextDev65/ChatGPT-0/main/ChatGPT-Zero.js
@@ -506,26 +506,32 @@
506506
const checkInterval = setInterval(() => {
507507
const nativeModelSwitchers = document.querySelectorAll('[data-testid="model-switcher-dropdown-button"]');
508508
let switcher = document.getElementById('chatgpt-model-switcher');
509-
509+
const getPlusClassName = ['absolute start-1/2 flex flex-col items-center gap-2 ltr:-translate-x-1/2 rtl:translate-x-1/2',
510+
'pointer-events-none absolute start-0 flex flex-col items-center gap-2 lg:start-1/2 ltr:-translate-x-1/2 rtl:translate-x-1/2'];
510511
// Create switcher
511512
if (!switcher) {
512-
const getPlusClassName = 'absolute start-1/2 flex flex-col items-center gap-2 ltr:-translate-x-1/2 rtl:translate-x-1/2';
513-
514513
const savedModel = localStorage.getItem(PREFERRED_MODEL_KEY) || DEFAULT_MODEL;
515514
switcher = createModelSwitcher(savedModel);
516-
switcher.className = getPlusClassName;
517-
518-
// move "Get Plus" button
519-
let getPlus = document.getElementsByClassName(getPlusClassName)[0];
520-
//document.getElementById('page-header').childNodes[1].appendChild(getPlus); // 2nd child of page header
521-
nativeModelSwitchers[0].parentNode.appendChild(getPlus); // first nativeModelSwitcher
522-
getPlus.className = '';
523515
}
524516
// Insert switcher next to the first visible native button
525517
if (!switcher.parentNode) {
526518
for (let nativeModelSwitcher of nativeModelSwitchers) {
527519
if (nativeModelSwitcher.checkVisibility && nativeModelSwitcher.checkVisibility()) {
528520
nativeModelSwitcher.parentNode.after(switcher);
521+
522+
// move "Get Plus" button
523+
let getPlus = null;
524+
for (let className of getPlusClassName) {
525+
let elements = document.getElementsByClassName(className);
526+
if (elements.length > 0) {
527+
// give getPlus styling to switcher
528+
switcher.className = getPlusClassName;
529+
getPlus = elements[0];
530+
break;
531+
}
532+
}
533+
nativeModelSwitcher.parentNode.appendChild(getPlus);
534+
getPlus.className = '';
529535
break;
530536
}
531537
}

0 commit comments

Comments
 (0)