ChatGPT Tự Động Tiếp Tục ⏩

⚡ Tiếp tục tạo ra nhiều câu trả lời ChatGPT một cách tự động

Cài đặt script này?
Script được tác giả gợi ý

Bạn có thế thích ChatGPT Vô cùng ∞

Cài đặt script này
// ==UserScript==
// @name                ChatGPT Auto-Continue ⏩
// @name:af             ChatGPT Auto-Aangaan ⏩
// @name:am             ChatGPT Auto-ተጨባጭ ማሳያ ⏩
// @name:ar             ChatGPT الاستمرار التلقائي ⏩
// @name:az             ChatGPT Avtomatik Davam et ⏩
// @name:be             ChatGPT Аўтаматычнае Працягванне ⏩
// @name:bg             ChatGPT Автоматично Продължаване ⏩
// @name:bn             ChatGPT স্বয়ংক্রিয় চালিয়ে যাওয়া ⏩
// @name:bo             ChatGPT རེད་འཐུམ་བཅོས་པ། ⏩
// @name:bs             ChatGPT Automatski Nastavi ⏩
// @name:ca             ChatGPT Auto-Continua ⏩
// @name:ceb            ChatGPT Auto-Padayon ⏩
// @name:ckb            ChatGPT دهستكاری خۆکار ⏩
// @name:cs             ChatGPT Automatické Pokračování ⏩
// @name:cy             ChatGPT Auto-Parhau ⏩
// @name:da             ChatGPT Auto-Fortsæt ⏩
// @name:de             ChatGPT Automatisches Fortfahren ⏩
// @name:dv             ChatGPT އައިނާދު ހިސާބަތް ⏩
// @name:dz             ChatGPT རེད་འཐུམ་གཅིག་ཁྱེར། ⏩
// @name:el             ChatGPT Αυτόματη Συνέχιση ⏩
// @name:eo             ChatGPT Aŭtomata Daŭrigado ⏩
// @name:es             ChatGPT Auto-Continuar ⏩
// @name:et             ChatGPT Automaatne Jätkamine ⏩
// @name:eu             ChatGPT Auto-Jarraitu ⏩
// @name:fa             ChatGPT ادامه خودکار ⏩
// @name:fi             ChatGPT Automaattinen Jatkaminen ⏩
// @name:fo             ChatGPT Auto-Verða ⏩
// @name:fr             ChatGPT Auto-Continuer ⏩
// @name:fr-CA          ChatGPT Auto-Continuer ⏩
// @name:gd             ChatGPT Auto-Leantainn ⏩
// @name:gl             ChatGPT Auto-Continuar ⏩
// @name:gu             ChatGPT સ્વચાલિત-ચાલુ રાખો ⏩
// @name:haw            ChatGPT Auto-Kōkua ⏩
// @name:he             ChatGPT המשך אוטומטי ⏩
// @name:hi             ChatGPT स्वचालित-प्रचालित रखें ⏩
// @name:hr             ChatGPT Auto-Nastavi ⏩
// @name:ht             ChatGPT Otomatik Kontinye ⏩
// @name:hu             ChatGPT Automatikus Folytatás ⏩
// @name:hy             ChatGPT Ինքնաշխատում Շարունակումը ⏩
// @name:id             ChatGPT Lanjut Otomatis ⏩
// @name:is             ChatGPT Sjálfvirk Framhald ⏩
// @name:it             ChatGPT Auto-Continua ⏩
// @name:ja             ChatGPT 自動継続 ⏩
// @name:jv             ChatGPT Lanjut Otomatis ⏩
// @name:ka             ChatGPT ავტომატური გაგრძელება ⏩
// @name:kab            ChatGPT Yemmeslayen Avrid n Tizwaru ⏩
// @name:kk             ChatGPT Автоматты Жалғастыру ⏩
// @name:km             ChatGPT បន្តទៅមកដល់ដោយស្វ័យប្រវត្តិ ⏩
// @name:kn             ChatGPT ಸ್ವಯಂಚಾಲಿತ ಮುಂದುವರಿಕೆ ⏩
// @name:ko             ChatGPT 자동 계속 ⏩
// @name:ku             ChatGPT Berdewamkirina Auto ⏩
// @name:ky             ChatGPT Автоматтык Жалгастыруу ⏩
// @name:la             ChatGPT Auto-Continuare ⏩
// @name:lb             ChatGPT Auto-Weiderginn ⏩
// @name:lo             ChatGPT ດຽວນີ້ບໍ່ຮອດຄວາມເລີຍ ⏩
// @name:lt             ChatGPT Automatinis Tęsti ⏩
// @name:lv             ChatGPT Automātiska Turpināšana ⏩
// @name:mg             ChatGPT Miverina Automatically ⏩
// @name:mi             ChatGPT Whakareri Tūmau ⏩
// @name:mk             ChatGPT Автоматско Продолжување ⏩
// @name:ml             ChatGPT ഓട്ടോ-തുടരുക ⏩
// @name:mn             ChatGPT Автомат Үргэлжлүүлэх ⏩
// @name:ms             ChatGPT Auto-Sambung ⏩
// @name:mt             ChatGPT Awto-Kontinwa ⏩
// @name:my             ChatGPT အလိုအလျောက်-ဆက်လက်လုပ်ကိုင်တယ် ⏩
// @name:ne             ChatGPT स्वचालित-तत्परता ⏩
// @name:nl             ChatGPT Auto-Doorgaan ⏩
// @name:no             ChatGPT Auto-Fortsette ⏩
// @name:ny             ChatGPT Auto-Endeleza ⏩
// @name:pa             ChatGPT ਸਵੈ-ਚਲੋ ⏩
// @name:pap            ChatGPT Sigui Automátikamente ⏩
// @name:pl             ChatGPT Automatyczne Kontynuowanie ⏩
// @name:ps             ChatGPT خپلکار تسلیم ⏩
// @name:pt             ChatGPT Auto-Continuar ⏩
// @name:ro             ChatGPT Auto-Continuare ⏩
// @name:ru             ChatGPT Авто-Продолжение ⏩
// @name:rw             ChatGPT Kugerageza Auto ⏩
// @name:si             ChatGPT ස්වයංක්‍රීය-දියවැඩියාව ⏩
// @name:sk             ChatGPT Auto-Pokračovať ⏩
// @name:sl             ChatGPT Samodejno Nadaljuj ⏩
// @name:sm             ChatGPT Aunoa'i-Taulaga ⏩
// @name:so             ChatGPT Isdhaaf Caruureed ⏩
// @name:sr             ChatGPT Аутоматски Настави ⏩
// @name:sv             ChatGPT Auto-Fortsätt ⏩
// @name:sw             ChatGPT Kusonga Kiotomatiki ⏩
// @name:ta             ChatGPT தானியங்கி தொடர்ந்து செல்லுங்கள் ⏩
// @name:te             ChatGPT ఆటో-కంటిన్యూ ⏩
// @name:tg             ChatGPT Давомоти автоматӣ ⏩
// @name:th             ChatGPT ดำเนินการต่ออย่างอัตโนมัติ ⏩
// @name:ti             ChatGPT ኣበይቲ ድሕሪ ተረኺቡ ⏩
// @name:tk             ChatGPT Avtomatik Dowam etmek ⏩
// @name:to             ChatGPT Tonu-'Aofa ⏩
// @name:tpi            ChatGPT Otomatik Kontinyu ⏩
// @name:tr             ChatGPT Otomatik Devam ⏩
// @name:uk             ChatGPT Автоматичне Продовження ⏩
// @name:ur             ChatGPT خودکار جاری رکھیں ⏩
// @name:uz             ChatGPT Avtomatik Davom ⏩
// @name:vi             ChatGPT Tự Động Tiếp Tục ⏩
// @name:xh             ChatGPT Ukuphela Okuqukethweyo ⏩
// @name:yi             ChatGPT אַווטאָ-קאַנטיניוירן ⏩
// @name:zh             ChatGPT 自动继续 ⏩
// @name:zh-CN          ChatGPT 自动继续 ⏩
// @name:zh-HK          ChatGPT 自動繼續 ⏩
// @name:zh-SG          ChatGPT 自动继续 ⏩
// @name:zh-TW          ChatGPT 自動繼續 ⏩
// @name:zu             ChatGPT Ngokugcwele Ukuphela ⏩
// @description         ⚡ Automatically continue generating multiple ChatGPT responses
// @description:af      ⚡ Outomaties voortgaan met die opwekking van meerdere ChatGPT-antwoorde
// @description:am      ⚡ እንዴትስ እንዲደርስ ያለብሳል የተወሰነ ምርጫዎች ለChatGPT
// @description:ar      ⚡ استمر في توليد استجابات متعددة لـ ChatGPT تلقائيًا
// @description:az      ⚡ ChatGPT cavablarını avtomatik olaraq çoxaldmağa davam edin
// @description:be      ⚡ Аўтаматычна працягвайце генерацыю некалькіх адказаў ChatGPT
// @description:bem     ⚡ Tontonkanyani kupitika kuwambo wanthu wokha-wokha wa ChatGPT
// @description:bg      ⚡ Продължете автоматично да генерирате множество отговори от ChatGPT
// @description:bn      ⚡ ChatGPT প্রতিক্রিয়া উত্পাদন অটোমেটিকভাবে চালিয়ে যান
// @description:bo      ⚡ ཡིག་ཆ་འཚོལ་ལག་སྤྱོད་རོགས་བྱུང་གནང་ནུས་པའི་ChatGPTལྕེབ་གསོར་བརྡ་འཕྲོ་ཤོག་ནང་བསྐྱོད་པ།
// @description:bs      ⚡ Nastavite automatski generirati više odgovora ChatGPT-a
// @description:ca      ⚡ Continua generant automàticament múltiples respostes de ChatGPT
// @description:ceb     ⚡ Magpadayon sa pag-generate og daghang mga Tugbang sa ChatGPT nga Otomatik
// @description:ckb     ⚡ بەردەوامبوون بە سەرجەم وەڵامەکانی ChatGPT
// @description:cs      ⚡ Automaticky pokračujte v generování více odpovědí ChatGPT
// @description:cy      ⚡ Parhewch i gynhyrchu nifer o ymatebion ChatGPT yn awtomatig
// @description:da      ⚡ Forsæt automatisk med at generere flere ChatGPT-responser
// @description:de      ⚡ Generieren Sie automatisch mehrere ChatGPT-Antworten weiterhin
// @description:dv      ⚡ އައުތީ ހުންނަވާ މެއިންމު ChatGPT އަޕް ކޮންޓެއް ބަދަލުކުރުމުގެ ރަނގަޅަ
// @description:dz      ⚡ འཕྲོས་མེད་པར་དུག་ཞིབ་པ་བསྐུགས་པར་ཡོད་མི་ChatGPTལྕེབ་གསོར་བརྡ་འཕྲོ་ཤོག་ནང་བསྐྱོད་པ།
// @description:el      ⚡ Συνεχίστε αυτόματα να δημιουργείτε πολλαπλές απαντήσεις ChatGPT
// @description:eo      ⚡ Daŭrigu aŭtomate generi plurajn respondojn ChatGPT
// @description:es      ⚡ Continúa generando automáticamente múltiples respuestas de ChatGPT
// @description:et      ⚡ Jätkake automaatselt mitme ChatGPT-vastuse genereerimist
// @description:eu      ⚡ Jarraitu automatikoki ChatGPT erantzun anitzak sortzen
// @description:fa      ⚡ ادامه تولید خودکار چندین پاسخ ChatGPT
// @description:fi      ⚡ Jatka automaattisesti useiden ChatGPT-vastausten generointia
// @description:fo      ⚡ Halda áfram við at framleiða fleiri ChatGPT svar
// @description:fr      ⚡ Continuez automatiquement à générer plusieurs réponses ChatGPT
// @description:fr-CA   ⚡ Continuez automatiquement à générer plusieurs réponses ChatGPT
// @description:gd      ⚡ Lean air adhart a' gabhail air adhart na freagairtean ChatGPT le bhith a' riochdachadh nas mòr
// @description:gl      ⚡ Continúa xerando automaticamente múltiples respostas de ChatGPT
// @description:gu      ⚡ આપોઆપ વધતા ચાર્જો આપતી કરો ChatGPT પ્રતિભાઓ
// @description:haw     ⚡ E mālama i ka hōʻoluʻolu ʻana i nā pane ʻelua a i ʻole iā ChatGPT
// @description:he      ⚡ המשך ליצור באופן אוטומטי מספר תגובות ChatGPT
// @description:hi      ⚡ स्वचालित रूप से बहुत सारे ChatGPT प्रतिक्रियाएँ उत्पन्न करना जारी रखें
// @description:hr      ⚡ Automatski nastavite generirati više ChatGPT odgovora
// @description:ht      ⚡ Kontinye otomatikman kontinye jenerasyon plizyè repons ChatGPT
// @description:hu      ⚡ Folytassa automatikusan több ChatGPT-válasz generálását
// @description:hy      ⚡ Շարունակեք ավտոմատ ստեղծել մեկից ավելի ChatGPT պատասխաններ
// @description:id      ⚡ Lanjutkan secara otomatis menghasilkan beberapa respons ChatGPT
// @description:is      ⚡ Halda áfram að framleiða fjölda ChatGPT-svara sjálfkrafa
// @description:it      ⚡ Continua automaticamente a generare più risposte di ChatGPT
// @description:ja      ⚡ ChatGPTの複数の応答を自動的に継続的に生成し続ける
// @description:jv      ⚡ Terus ngasilake balasan multipel ChatGPT kasebut otomatis
// @description:ka      ⚡ გაგრძელეთ ავტომატურად გენერირებას რამდენიმე ChatGPT პასუხის
// @description:kab     ⚡ Sekcem seg yilmeẓyen deg usefru n tufat ChatGPT
// @description:kk      ⚡ ChatGPT-ның бірнеше жауаптарын автоматты түрде жалғастыруға жалғастырыңыз
// @description:km      ⚡ បន្តទៀតហើយបន្តការបង្កើតចម្លើយជាច្រើននៃ ChatGPT ដោយស្វ័យប្រវត្តិ
// @description:kn      ⚡ ಸ್ವಯಂಚಾಲಿತವಾಗಿ ChatGPT ಪ್ರತಿಕ್ರಿಯೆಗಳನ್ನು ಮುಂದುವರಿಸಿ
// @description:ko      ⚡ ChatGPT 응답을 자동으로 계속 생성하세요
// @description:ku      ⚡ Parvekirina otomatîk a berdevkêya çêkirina gelek bersivên ChatGPT
// @description:ky      ⚡ Тууралуу даярдалган көптөгөн ChatGPT каражаттарын жалгастыр
// @description:la      ⚡ Automatica continua generatio plurium responsionum ChatGPT
// @description:lb      ⚡ Fuert mat der Automatiséierung vum generéieren vun méi ChatGPT Äntwerten
// @description:lo      ⚡ ຕະຫຼາດໃນການຜະລິດທັງເຫລົ່າຂອງການສ້າງຄໍາອະທິບາຍຂອງ ChatGPT
// @description:lt      ⚡ Tęskite automatiškai generuoti daugelį ChatGPT atsakymų
// @description:lv      ⚡ Turpiniet automātiski ģenerēt vairākas ChatGPT atbildes
// @description:mg      ⚡ Mihatra ny famokarana an-taonana momba ny fijery maromaro amin'ny ChatGPT
// @description:mi      ⚡ Whakapau tonu i te whakaputa i ngā whakahoki ā-ipurangi maha mō te ChatGPT
// @description:mk      ⚡ Настани се автоматски да генерираш повеќе одговори на ChatGPT
// @description:ml      ⚡ ChatGPT പ്രതികരണങ്ങൾക്ക് സ്വയംഭാവതന്നെ തുടങ്ങുക
// @description:mn      ⚡ ChatGPT хариултуудыг автоматаар үүсгэнэ үү
// @description:ms      ⚡ Terus menghasilkan beberapa respons ChatGPT secara automatik
// @description:mt      ⚡ Kompluta b'mod awtomatiku jipproduċi iktar risposti tal-ChatGPT
// @description:my      ⚡ ချောတောင်းကိုလည်း ChatGPT အတွက် အလိုအလျောက် ထပ်တိုးထားသည်ကိုနှိပ်ပါ
// @description:ne      ⚡ क्याटजीपीटी प्रतिक्रियाहरूलाई स्वतः सार्नुहोस्
// @description:nl      ⚡ Ga automatisch door met het genereren van meerdere ChatGPT-reacties
// @description:no      ⚡ Fortsett automatisk med å generere flere ChatGPT-responser
// @description:ny      ⚡ Kwezalitsa mabuku achinsinsi amakono apamwamba a ChatGPT
// @description:pa      ⚡ ਆਪਣੇ ਆਪ ਕਈ ChatGPT ਜਵਾਬਾਂ ਨੂੰ ਜਾਰੀ ਰੱਖਣ ਦੇ ਨਾਲ ਜਾਰੀ ਰੱਖੋ
// @description:pap     ⚡ Kontinua generando automaticamente varios respondenan di ChatGPT
// @description:pl      ⚡ Kontynuuj automatyczne generowanie wielu odpowiedzi ChatGPT
// @description:ps      ⚡ په خپله خوښه خپور شه کړه چې د ChatGPT پاسخونه وویشتل
// @description:pt      ⚡ Continue gerando automaticamente várias respostas do ChatGPT
// @description:pt-BR   ⚡ Continue gerando automaticamente várias respostas do ChatGPT
// @description:rn      ⚡ Komeza automatik kugenera ibyanditswe byinshi bya ChatGPT
// @description:ro      ⚡ Continuați să generați automat mai multe răspunsuri ChatGPT
// @description:ru      ⚡ Продолжайте автоматически генерировать несколько ответов ChatGPT
// @description:rw      ⚡ Angana gusuzumira kongera amakuru adahindurwa ya ChatGPT
// @description:sg      ⚡ Kwâandâ mbele mbanzi mêlêba mêvâmba ya tâ ChatGPT
// @description:si      ⚡ ChatGPT හි බහුතරක් ස්වයංක්රීයව පවතී
// @description:sk      ⚡ Automaticky pokračujte v generovaní viacerých odpovedí ChatGPT
// @description:sl      ⚡ Samodejno nadaljujte z generiranjem več odgovorov ChatGPT
// @description:sm      ⚡ Alofa faauaogaina ona faaaogāina ni tali i le mafaufau ChatGPT
// @description:sn      ⚡ Enda kusvika pachigadzirwa chekugadzirisa vashandisi vairambidzwi vechi ChatGPT
// @description:so      ⚡ Sii wadnaansho badan oo ChatGPT ka heli
// @description:sr      ⚡ Настави аутоматски да генеришеш више ChatGPT одговора
// @description:sv      ⚡ Fortsätt att automatiskt generera flera ChatGPT-svar
// @description:sw      ⚡ Endelea kuzalisha majibu mengi ya ChatGPT kiotomatiki
// @description:ta      ⚡ தானியங்கி மீண்டும் பல விளக்கங்களை உருவாக்கத் தொடர்ந்துவிடுங்கள் ChatGPT
// @description:te      ⚡ ఆటోమేటిక్గా మరియు మరిన్ని ChatGPT సమాధానాలను రచించండి
// @description:tg      ⚡ Идомаи автоматӣ барои иҷод кардани чанд ҷавоби ChatGPT
// @description:th      ⚡ ดำเนินการสร้างคำตอบหลาย ๆ ของ ChatGPT อัตโนมัติ
// @description:ti      ⚡ ደቂቃዎት የሚጠፋ ኮድ ብቻ በኮስታኒክስ በሚገባ ጥሩ ጥያቄዎች ይሰጣል
// @description:tk      ⚡ Tölegiňizde ChatGPT-e hasapla otomatik toplum
// @description:tn      ⚡ Koisa ha maele a ChatGPT ho ngola ho tlaleletsa
// @description:to      ⚡ Tonu ki hono fakahoko ki he fakafofonga ha nonga ai he ChatGPT
// @description:tpi     ⚡ Kontinyu genaratim planti respons bilong ChatGPT bi autometik
// @description:tr      ⚡ Otomatik olarak çoklu ChatGPT yanıtları üretmeye devam edin
// @description:uk      ⚡ Продовжуйте автоматично генерувати багато відповідей ChatGPT
// @description:ur      ⚡ ChatGPT جو جوابات خودکار طور پر تیار کرنا جاری رکھیں
// @description:uz      ⚡ Ko'plab ChatGPT javoblarni avtomatik ravishda yaratishni davom ettirish
// @description:vi      ⚡ Tiếp tục tạo ra nhiều câu trả lời ChatGPT một cách tự động
// @description:xh      ⚡ Qhubeka ukuqhuba okuqukethweyo lwezibalo eziningi zikaChatGPT
// @description:yi      ⚡ פֿאָרטזעצן ווײַטער גענערירן מיינערע אַנטוואָרטן פֿון ChatGPT אַװטאָמאַטיש
// @description:zh      ⚡ 自动继续生成多个 ChatGPT 响应
// @description:zh-CN   ⚡ 自动继续生成多个 ChatGPT 响应
// @description:zh-HK   ⚡ 自動繼續生成多個 ChatGPT 響應
// @description:zh-SG   ⚡ 自动继续生成多个 ChatGPT 响应
// @description:zh-TW   ⚡ 自動繼續生成多個 ChatGPT 響應
// @description:zu      ⚡ Terus menghasilkan imibuzo eminingi ye-ChatGPT ngokwesizulu
// @author              Adam Lui
// @namespace           https://github.com/adamlui
// @version             2024.5.14
// @license             MIT
// @match               *://chatgpt.com/*
// @match               *://chat.openai.com/*
// @icon                https://cdn.jsdelivr.net/gh/adamlui/userscripts/chatgpt/media/icons/openai-favicon48.png
// @icon64              https://cdn.jsdelivr.net/gh/adamlui/userscripts/chatgpt/media/icons/openai-favicon64.png
// @require             https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.7.1/dist/chatgpt.min.js#sha256-zllbMzfHw6JSOq+A7od7mubiVsZPybZSHJpE+syw6mk=
// @connect             cdn.jsdelivr.net
// @connect             greasyfork.org
// @grant               GM_setValue
// @grant               GM_getValue
// @grant               GM_registerMenuCommand
// @grant               GM_unregisterMenuCommand
// @grant               GM_openInTab
// @grant               GM.xmlHttpRequest
// @noframes
// @homepageURL         https://github.com/adamlui/chatgpt-auto-continue
// @supportURL          https://github.com/adamlui/chatgpt-auto-continue/issues
// ==/UserScript==

// Documentation: https://docs.chatgptautocontinue.com
// NOTE: This script relies on the powerful chatgpt.js library @ https://chatgpt.js.org © 2023–2024 KudoAI & contributors under the MIT license.

(async () => {

    // Init config
    const config = {
        appName: 'ChatGPT Auto-Continue', appSymbol: '≫',
        keyPrefix: 'chatGPTautoContinue', userLanguage: chatgpt.getUserLanguage(),
        gitHubURL: 'https://github.com/adamlui/chatgpt-auto-continue',
        greasyForkURL: 'https://greasyfork.org/scripts/466789-chatgpt-auto-continue' }
    config.updateURL = config.greasyForkURL.replace('https://', 'https://update.')
        .replace(/(\d+)-?([a-zA-Z-]*)$/, (_, id, name) => `${ id }/${ !name ? 'script' : name }.meta.js`)
    config.supportURL = config.gitHubURL + '/issues/new'
    config.assetHostURL = config.gitHubURL.replace('github.com', 'cdn.jsdelivr.net/gh') + '@68f3c3d/'
    loadSetting('notifDisabled')

    // Define messages
    let msgs = {};
    const msgsLoaded = new Promise(resolve => {
        const msgHostDir = config.assetHostURL + 'greasemonkey/_locales/',
              msgLocaleDir = ( config.userLanguage ? config.userLanguage.replace('-', '_') : 'en' ) + '/'
        let msgHref = msgHostDir + msgLocaleDir + 'messages.json', msgXHRtries = 0
        GM.xmlHttpRequest({ method: 'GET', url: msgHref, onload: onLoad })
        function onLoad(resp) {
            try { // to return localized messages.json
                const msgs = JSON.parse(resp.responseText), flatMsgs = {}
                for (const key in msgs)  // remove need to ref nested keys
                    if (typeof msgs[key] == 'object' && 'message' in msgs[key])
                        flatMsgs[key] = msgs[key].message
                resolve(flatMsgs)
            } catch (err) { // if bad response
                msgXHRtries++ ; if (msgXHRtries == 3) return resolve({}) // try up to 3X (original/region-stripped/EN) only
                msgHref = config.userLanguage.includes('-') && msgXHRtries == 1 ? // if regional lang on 1st try...
                    msgHref.replace(/([^_]*)_[^/]*(\/.*)/, '$1$2') // ...strip region before retrying
                        : ( msgHostDir + 'en/messages.json' ) // else use default English messages
                GM.xmlHttpRequest({ method: 'GET', url: msgHref, onload: onLoad })
            }
        }
    }) ; if (!/^en/.test(config.userLanguage)) try { msgs = await msgsLoaded; } catch (err) {}

    // Init/register menu
    let menuIDs = [], state = { symbol: ['✔️', '❌'], word: ['ON', 'OFF'],
                                separator: getUserscriptManager() == 'Tampermonkey' ? ' — ' : ': ' }
    registerMenu() // create browser toolbar menu

    // Stylize alerts
    if (!document.getElementById('chatgpt-alert-override-style')) {
        const chatgptAlertStyle = document.createElement('style')
        chatgptAlertStyle.id = 'chatgpt-alert-override-style'
        chatgptAlertStyle.innerText = '.chatgpt-modal button {'
                + 'font-size: 0.77rem ; text-transform: uppercase ;'
                + 'border-radius: 0 !important ; padding: 5px !important ; min-width: 102px }'
            + '.modal-buttons { margin-left: -13px !important }'
        document.head.append(chatgptAlertStyle)
    }

    // Observe DOM for need to continue generating response
    await chatgpt.isLoaded()
    const continueObserver = new MutationObserver(mutations => mutations.forEach(mutation => {
        if (mutation.attributeName == 'style' && mutation.target.style.opacity == '1') {
            chatgpt.getContinueGeneratingButton().click()
            notify(msgs.notif_chatAutoContinued || 'Chat Auto-Continued', 'bottom-right')
    }}))
    continueObserver.observe(document.querySelector('main'), { attributes: true, subtree: true })

    // Notify of status on load
    if (!config.notifDisabled) notify(( msgs.mode_autoContinue || 'Auto-Continue' ) + ': ON')

    // Define SCRIPT functions

    function loadSetting(...keys) { keys.forEach(key => config[key] = GM_getValue(config.keyPrefix + '_' + key, false)) }
    function saveSetting(key, value) { GM_setValue(config.keyPrefix + '_' + key, value) ; config[key] = value }
    function safeWindowOpen(url) { window.open(url, '_blank', 'noopener') } // to prevent backdoor vulnerabilities
    function getUserscriptManager() { try { return GM_info.scriptHandler } catch (err) { return 'other' }}

    // Define MENU functions

    function registerMenu() {
        menuIDs = [] // empty to store newly registered cmds for removal while preserving order

        // Add command to hide/show notifications on load
        const mnLabel = state.symbol[+config.notifDisabled] + ' '
                      + ( msgs.menuLabel_modeNotifs || 'Mode Notifications' )
                      + state.separator + state.word[+config.notifDisabled]
        menuIDs.push(GM_registerMenuCommand(mnLabel, function() {
            saveSetting('notifDisabled', !config.notifDisabled)
            notify(( msgs.menuLabel_modeNotifs || 'Mode Notifications' ) + ': ' + state.word[+config.notifDisabled])
            for (const id of menuIDs) { GM_unregisterMenuCommand(id) } registerMenu() // refresh menu
        }))

        // Add command to launch About modal
        const aboutLabel = `💡 ${ msgs.menuLabel_about || 'About' } ${ msgs.appName || config.appName }`
        menuIDs.push(GM_registerMenuCommand(aboutLabel, launchAboutModal))
    }

    function launchAboutModal() {

        // Show alert
        const chatgptJSver = (/chatgpt-([\d.]+)\.min/.exec(GM_info.script.header) || [null, ''])[1],
              headingStyle = 'font-size: 1.15rem',
              pStyle = 'position: relative ; left: 3px',
              pBrStyle = 'position: relative ; left: 4px ',
              aStyle = 'color: ' + ( chatgpt.isDarkMode() ? '#c67afb' : '#8325c4' ) // purple
        const aboutAlertID = alert(
            msgs.appName || config.appName, // title
            `<span style="${ headingStyle }"><b>🏷️ <i>${ msgs.about_version || 'Version' }</i></b>: </span>`
                + `<span style="${ pStyle }">${ GM_info.script.version }</span>\n`
            + `<span style="${ headingStyle }"><b>⚡ <i>${ msgs.about_poweredBy || 'Powered by' }</i></b>: </span>`
                + `<span style="${ pStyle }"><a style="${ aStyle }" href="https://chatgpt.js.org" target="_blank" rel="noopener">`
                + 'chatgpt.js</a>' + ( chatgptJSver ? ( ' v' + chatgptJSver ) : '' ) + '</span>\n'
            + `<span style="${ headingStyle }"><b>📜 <i>${ msgs.about_sourceCode || 'Source code' }</i></b>:</span>\n`
                + `<span style="${ pBrStyle }"><a href="${ config.gitHubURL }" target="_blank" rel="nopener">`
                + config.gitHubURL + '</a></span>',
            [ // buttons
                function checkForUpdates() { updateCheck() },
                function getSupport() { safeWindowOpen(config.supportURL) },
                function leaveAReview() { safeWindowOpen(config.greasyForkURL + '/feedback#post-discussion') },
                function moreChatGPTapps() { safeWindowOpen('https://github.com/adamlui/chatgpt-apps') }
            ], '', 478 // set width
        )

        // Re-format buttons to include emoji + localized label + hide Dismiss button
        for (const button of document.getElementById(aboutAlertID).querySelectorAll('button')) {
            if (/updates/i.test(button.textContent)) button.textContent = (
                '🚀 ' + ( msgs.buttonLabel_updateCheck || 'Check for Updates' ))
            else if (/support/i.test(button.textContent)) button.textContent = (
                '🧠 ' + ( msgs.buttonLabel_getSupport || 'Get Support' ))
            else if (/review/i.test(button.textContent)) button.textContent = (
                '⭐ ' + ( msgs.buttonLabel_leaveReview || 'Leave a Review' ))
            else if (/apps/i.test(button.textContent)) button.textContent = (
                '🤖 ' + ( msgs.buttonLabel_moreApps || 'More ChatGPT Apps' ))
            else button.style.display = 'none' // hide Dismiss button
        }
    }

    function updateCheck() {

        // Fetch latest meta
        const currentVer = GM_info.script.version
        GM.xmlHttpRequest({
            method: 'GET', url: config.updateURL + '?t=' + Date.now(),
            headers: { 'Cache-Control': 'no-cache' },
            onload: response => { const updateAlertWidth = 377

                // Compare versions
                const latestVer = /@version +(.*)/.exec(response.responseText)[1]
                for (let i = 0 ; i < 4 ; i++) { // loop thru subver's
                    const currentSubVer = parseInt(currentVer.split('.')[i], 10) || 0,
                          latestSubVer = parseInt(latestVer.split('.')[i], 10) || 0
                    if (currentSubVer > latestSubVer) break // out of comparison since not outdated
                    else if (latestSubVer > currentSubVer) { // if outdated

                        // Alert to update
                        const updateAlertID = alert(( msgs.alert_updateAvail || 'Update available' ) + '! 🚀', // title
                            ( msgs.alert_newerVer || 'An update to' ) + ' ' // msg
                                + ( msgs.appName || config.appName ) + ' '
                                + `(v ${ latestVer }) ${ msgs.alert_isAvail || 'is available' }!   `
                                + '<a target="_blank" rel="noopener" style="font-size: 0.7rem" '
                                    + 'href="' + config.gitHubURL + '/commits/main/greasemonkey/'
                                    + config.updateURL.replace(/.*\/(.*)meta\.js/, '$1user.js') + '" '
                                    + `> ${ msgs.link_viewChanges || 'View changes' }</a>`,
                            function update() { // button
                                GM_openInTab(config.updateURL.replace('meta.js', 'user.js') + '?t=' + Date.now(),
                                    { active: true, insert: true })}, // focus, make adjacent                            
                            '', updateAlertWidth
                        )

                        // Localize button labels if needed
                        if (!config.userLanguage.startsWith('en')) {
                            const updateAlert = document.querySelector(`[id="${ updateAlertID }"]`),
                                  updateBtns = updateAlert.querySelectorAll('button')
                            updateBtns[1].textContent = msgs.buttonLabel_update || 'Update'
                            updateBtns[0].textContent = msgs.buttonLabel_dismiss || 'Dismiss'
                        }

                        return
                }}

                // Alert to no update, return to About alert
                alert(( msgs.alert_upToDate || 'Up-to-date' ) + '!', // title
                    `${ msgs.appName || 'ChatGPT Widescreen Mode' } (v${ currentVer }) ` // msg
                        + ( msgs.alert_isUpToDate || 'is up-to-date' ) + '!',
                    '', '', updateAlertWidth
                )
                launchAboutModal()
    }})}

    // Define FEEDBACK functions

    function notify(msg, position = '', notifDuration = '', shadow = '') {
        chatgpt.notify(`${ config.appSymbol } ${ msg }`, position, notifDuration, shadow || chatgpt.isDarkMode() ? '' : 'shadow') }

    function alert(title = '', msg = '', btns = '', checkbox = '', width = '') {
        return chatgpt.alert(`${ config.appSymbol } ${ title }`, msg, btns, checkbox, width )}

})()