js实现支持暗黑模式切换语音识别聊天记录会话、自己设置openaikey的chatgpt web网页代码
代码语言:html
所属分类:其他
代码描述:js实现支持暗黑模式切换语音识别聊天记录会话、自己设置openaikey的chatgpt web网页代码,自定设置openai key,保留包本地,不存放在服务器上,直接调用openai的官方接口,需要科学上网,自适应兼容手机端、可设置azure的语音识别key等多种语音识别方式,支持不同的角色prompt预设选择,支持打字速度设置、回答质量设置,支持key的额度查询,支持文件夹。
代码标签: js 暗黑 模式 切换 语音 识别 聊天 记录 会话 设置 openai key chatgpt
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="使用ChatGPT接口,实现简单HTML网页版在线聊天" />
<head>
<meta charset="utf-8">
<title>ChatGPT</title>
<style>
* {
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji" !important;
}
html {
width: 100%;
height: 100%;
}
:root {
--background: #edeff2;
--chat-back: #fff;
--main-back: #f6f6f6;
--active-btn: #e0e0e0;
--lighter-active: #eaeaea;
--sel-btn: #d0d0d0;
--btn-color: #404040;
--text-color: #909090;
--chat-text-color: #24292f;
--response-color: #f7f7f8;
--lighter-active-color: #e8e8e8;
--lighter-text-color: #555;
--svg-color: #808080;
--lighter-svg-color: #c0c0c0;
--code-color: #f0f0f0;
--black-color: #000;
}
[data-theme="dark"] {
--background: #1f1f1f;
--chat-back: #3c3c3c;
--main-back: #333;
--active-btn: #1f1f1f;
--lighter-active: #151515;
--sel-btn: #1e1e1e;
--btn-color: #bfbfbf;
--text-color: #8f8f8f;
--chat-text-color: #c9d1d9;
--response-color: #2f2f2f;
--lighter-active-color: #171717;
--lighter-text-color: #aaa;
--svg-color: #7f7f7f;
--lighter-svg-color: #3f3f3f;
--code-color: #101010;
--black-color: #fff;
}
body {
background-color: var(--background);
width: 100%;
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.chat_window {
position: absolute;
width: 100%;
max-width: 1188px;
height: 100%;
max-height: 888px;
border-radius: 8px;
background-color: var(--chat-back);
overflow: hidden;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}
.overlay {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, .3);
z-index: 90;
opacity: 0;
visibility: hidden;
cursor: pointer;
transition: all 120ms ease-in-out;
}
@media screen and (max-width: 1188px) and (max-height: 888px) {
#toggleFull {
display: none;
}
}
@media screen and (min-width: 800px) {
.chat_window {
display: flex;
}
.mainContent {
width: calc(100% - 250px);
}
.nav {
position: relative;
margin-left: -250px;
transition: margin-left 120ms ease-in-out;
}
.show-nav .nav {
margin-left: 0;
}
}
@media screen and (max-width: 800px) {
.chat_window {
display: block;
}
.nav {
position: absolute !important;
left: -250px;
transition: left 120ms ease-in-out;
}
.show-nav .nav {
left: 0;
box-shadow: rgba(0, 0, 0, 0.2) 0px 8px 10px -5px, rgba(0, 0, 0, 0.14) 0px 16px 24px 2px, rgba(0, 0, 0, 0.12) 0px 6px 30px 5px;
}
.show-nav .overlay {
opacity: 1;
visibility: visible;
}
}
.full_window {
max-width: none;
max-height: none;
}
.nav {
width: 250px;
height: 100%;
border-right: 1px solid var(--active-btn);
background-color: var(--main-back);
top: 0;
z-index: 99;
flex-shrink: 0;
display: flex;
flex-direction: column;
}
.mainContent {
height: 100%;
position: relative;
display: flex;
flex-direction: column;
flex: 1;
}
.top_menu {
background-color: var(--main-back);
width: 100%;
height: 50px;
padding: 5px 0;
}
.top_menu .toggler {
margin-left: 10px;
width: 40px;
height: 40px;
float: left;
padding: 5px 7px;
border-radius: 4px;
cursor: pointer;
}
.top_menu .toggler:hover {
background: var(--active-btn);
}
.top_menu .toggler .button {
width: 26px;
height: 4px;
border-radius: 4px;
position: absolute;
pointer-events: none;
}
.top_menu .toggler .button.close {
margin-top: 3px;
background-color: #99c959;
}
.top_menu .toggler .button.minimize {
margin-top: 13px;
background-color: #f8b26a;
}
.top_menu .toggler .button.maximize {
margin-top: 23px;
background-color: #e15b64;
}
.top_menu .title {
color: var(--text-color);
font-size: 20px;
height: 40px;
line-height: 40px;
position: relative;
pointer-events: none;
}
.title>span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.messages {
position: relative;
flex: 1;
overflow-x: hidden;
overflow-y: auto;
font-size: 16px;
color: var(--chat-text-color);
text-align: center;
}
.messages::-webkit-scrollbar,
#chatlog .markdown-body>pre::-webkit-scrollbar,
#setDialog::-webkit-scrollbar,
.allList::-webkit-scrollbar,
.sysDetail::-webkit-scrollbar {
width: 10px;
height: 10px;
}
.messages::-webkit-scrollbar-track,
#chatlog .markdown-body>pre::-webkit-scrollbar-track,
#setDialog::-webkit-scrollbar-track,
.allList::-webkit-scrollbar-track,
.sysDetail::-webkit-scrollbar-track {
background-clip: padding-box;
background: transparent;
border: none;
}
.messages::-webkit-scrollbar-corner,
#chatlog .markdown-body>pre::-webkit-scrollbar-corner,
#setDialog::-webkit-scrollbar-corner,
.allList::-webkit-scrollbar-corner,
.sysDetail::-webkit-scrollbar-corner {
background-color: transparent;
}
.messages::-webkit-scrollbar-thumb,
#chatlog .markdown-body>pre::-webkit-scrollbar-thumb,
#setDialog::-webkit-scrollbar-thumb,
.allList::-webkit-scrollbar-thumb,
.sysDetail::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.1);
background-clip: padding-box;
border: solid transparent;
border-radius: 10px;
}
.messages::-webkit-scrollbar-thumb:hover,
#chatlog .markdown-body>pre::-webkit-scrollbar-thumb:hover,
#setDialog::-webkit-scrollbar-thumb:hover,
.allList::-webkit-scrollbar-thumb:hover,
.sysDetail::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.4);
}
.messages .message {
clear: both;
overflow: hidden;
margin-bottom: 20px;
transition: all 0.5s linear;
opacity: 0;
}
#chatlog {
word-wrap: break-word;
text-align: start;
}
#chatlog>div {
padding: 18px 30px 18px 54px;
}
.chatAvatar {
position: absolute;
top: 14px;
left: 13px;
width: 30px;
height: 30px;
border-radius: 2px;
}
.response>.chatAvatar {
background: #10a37f;
top: 18px;
}
.chatAvatar>img {
display: block;
width: 100%;
height: 100%;
border-radius: 2px;
}
.chatAvatar>svg {
display: block;
margin-top: 4px;
margin-left: 4px;
}
#chatlog .request {
position: relative;
}
.requestBody {
white-space: pre-wrap;
}
#chatlog .response {
background: var(--response-color);
position: relative;
}
.response .markdown-body {
background: var(--response-color) !important;
}
#chatlog .markdown-body>pre {
overflow-x: auto;
padding: 10px;
position: relative;
background: var(--code-color);
}
.m-mdic-copy-wrapper {
position: absolute;
top: 5px;
right: 16px;
-webkit-user-select: none;
user-select: none;
}
.m-mdic-copy-wrapper span.u-mdic-copy-code_lang {
position: absolute;
top: 3px;
right: calc(100% + 4px);
font-family: system-ui;
font-size: 12px;
line-height: 18px;
color: #bbb;
}
.m-mdic-copy-wrapper div.u-mdic-copy-notify {
position: absolute;
top: 0;
right: 0;
padding: 3px 6px;
border: 0;
border-radius: 3px;
background: none;
font-family: system-ui;
font-size: 12px;
line-height: 18px;
color: var(--lighter-text-color);
outline: none;
right: 100%;
padding-right: 4px;
}
.m-mdic-copy-wrapper button.u-mdic-copy-btn {
position: relative;
top: 0;
right: 0;
padding: 3px 6px;
border: 0;
border-radius: 3px;
background: none;
font-family: system-ui;
font-size: 12px;
line-height: 18px;
color: #bbb;
outline: none;
cursor: pointer;
transition: color 0.2s;
}
.m-mdic-copy-wrapper button.u-mdic-copy-btn:hover {
color: var(--lighter-text-color);
}
#stopChat {
display: none;
margin: 0 auto;
margin-top: 3px;
width: 80px;
height: 32px;
text-align: center;
line-height: 32px;
color: white;
background: #f8b26a;
cursor: pointer;
border-radius: 3px;
position: sticky;
bottom: 2px;
justify-content: center;
align-items: center;
}
#stopChat>svg {
margin-right: 8px;
}
#stopChat:hover {
background: #f0aa60;
}
.bottom_wrapper {
position: relative;
width: 100%;
padding: 10px 10px;
}
.bottom_wrapper .message_input_wrapper {
border: none;
width: calc(100% - 143px);
position: relative;
text-align: left;
}
.bottom_wrapper .message_input_wrapper .message_input_text {
border-radius: 4px;
border: none;
outline: none;
resize: none;
background: var(--main-back);
color: var(--chat-text-color);
height: 47px;
font-size: 16px;
max-height: 200px;
padding: 13px 0 13px 16px;
width: 100%;
display: block;
transition: background 0.3s;
}
.bottom_wrapper .message_input_wrapper .message_input_text:focus {
background: var(--code-color);
}
.bottom_wrapper .message_input_wrapper .message_input_text::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
#sendbutton {
width: 80px;
height: 47px;
font-size: 18px;
font-weight: bold;
border-radius: 3px;
background-color: #b8da8b;
border: none;
padding: 0;
color: #fff;
cursor: pointer;
transition: all 0.2s linear;
text-align: center;
float: right;
position: absolute;
right: 65px;
bottom: 10px;
cursor: not-allowed;
}
.activeSendBtn {
background-color: #99c959 !important;
cursor: pointer !important;
}
.activeSendBtn:hover {
background-color: #90c050 !important;
}
.clearConv {
position: absolute;
right: 10px;
bottom: 10px;
width: 47px;
height: 47px;
border-radius: 3px;
background: var(--text-color);
border: none;
color: #fff;
cursor: pointer;
}
.clearConv>svg {
margin: 0 auto;
}
.clearConv:hover {
background: var(--svg-color);
}
.clearConv svg:first-child {
display: none;
}
.clearConv svg:nth-child(2) {
display: block;
}
.closeConv {
background: var(--active-btn);
}
.closeConv:hover {
background: var(--lighter-active-color);
}
.closeConv svg:first-child {
display: block;
}
.closeConv svg:nth-child(2) {
display: none;
}
.loaded>span {
display: inline-block;
}
.loaded>svg {
display: none;
}
.loading {
background: var(--active-btn) !important;
}
.loading>span {
display: none;
}
.loading>svg {
display: block;
}
.switch-slide {
display: inline-block;
vertical-align: middle;
}
.switch-slide-label {
display: block;
width: 38px;
height: 18px;
background: var(--text-color);
border-radius: 30px;
cursor: pointer;
position: relative;
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.switch-slide-label:after {
content: "";
display: block;
width: 16px;
height: 16px;
border-radius: 100%;
background: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
position: absolute;
left: 1px;
top: 1px;
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-transition: 0.3s ease;
transition: 0.3s ease;
}
.switch-slide input:checked+label {
background: #99c959;
transition: 0.3s ease;
}
.switch-slide input:checked+label:after {
left: 21px;
}
.settings {
margin-right: 10px;
display: flex;
position: absolute;
right: 0;
top: 5px;
}
.setBtn {
margin-left: 2px;
cursor: pointer;
padding: 5px;
border: none;
background-color: transparent;
border-radius: 4px;
}
.setBtn>svg {
display: block;
color: var(--text-color);
}
.setBtn:hover {
background: var(--active-btn);
}
#setting {
right: 15px;
}
#toggleFull {
right: 56px;
}
#toggleLight *,
#toggleFull * {
pointer-events: none;
}
.showSetting {
background: var(--lighter-svg-color) !important;
}
#setDialog {
color: var(--btn-color);
position: absolute;
z-index: 2;
background: var(--main-back);
width: 320px;
right: 6px;
top: 46px;
overflow-y: auto;
max-height: calc(100% - 55px);
-webkit-user-select: none;
user-select: none;
border-radius: 5px;
padding: 8px 12px 8px 12px;
box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
}
#setDialog input {
width: 100%;
}
#setDialog .inlineTitle {
display: inline-block;
width: 80px;
line-height: 16px;
vertical-align: middle;
}
#convOption,
#speechOption,
#speechDetail,
#recOption {
margin-bottom: 6px;
}
#convOption>div,
#speechOption>div,
#speechDetail>div,
#recOption div {
margin-top: 10px;
}
#voiceRecSetting select,
#speechDetail select {
background: var(--chat-back);
color: var(--chat-text-color);
}
.inputTextClass {
outline: none;
border-radius: 2px;
margin-top: 2px;
height: 32px;
font-size: 15px;
padding-left: 6px;
background: var(--chat-back);
color: var(--chat-text-color);
border: none;
}
.areaTextClass {
width: 100%;
height: 80px;
display: block;
resize: none;
padding: 6px;
}
input[type="range"] {
-webkit-appearance: none;
appearance: none;
display: block;
margin: 6px 0 3px 0;
height: 8px;
background: var(--text-color);
border-radius: 5px;
background-image: linear-gradient(#99c959, #99c959);
background-size: 100% 100%;
background-repeat: no-repeat;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 15px;
width: 15px;
border-radius: 50%;
background: #99c959;
cursor: ew-resize;
}
input[type=range]::-webkit-slider-runnable-track {
-webkit-appearance: none;
box-shadow: none;
border: none;
background: transparent;
}
.justSetLine {
display: flex;
justify-content: space-between;
}
.presetSelect>div {
display: inline-block;
}
.presetSelect select {
outline: none;
border-radius: 3px;
width: 120px;
border-color: rgba(0, 0, 0, .3);
background: var(--chat-back);
color: var(--chat-text-color);
}
.selectDef {
display: flex;
justify-content: space-between;
font-size: 13px;
color: var(--text-color);
}
#preSetSpeech {
width: 100%;
outline: none;
height: 30px;
font-size: 14px;
margin-top: 5px;
border-radius: 3px;
border-color: rgba(0, 0, 0, .3);
}
.mdOption {
position: absolute;
right: 0px;
top: 0;
width: 30px;
height: 100%;
pointer-events: none;
}
.mdOption>div {
pointer-events: auto;
cursor: pointer;
}
.mdOption svg * {
pointer-events: none;
}
.refreshReq svg:not(:first-child) {
display: none;
}
.halfRefReq svg:not(:nth-child(2)) {
display: none;
}
.optionItems {
position: absolute;
bottom: -12px;
display: flex;
justify-content: space-between;
visibility: hidden;
z-index: 1;
color: var(--svg-color);
}
.optionItems:hover {
visibility: visible;
}
.request:hover .optionItems,
.request:hover .voiceCls,
.response:hover .optionItems,
.response:hover .voiceCls {
visibility: visible;
}
.optionItem {
border-radius: 10px;
height: 24px;
width: 32px;
border: 1px solid var(--active-btn);
background-color: var(--response-color);
display: flex !important;
justify-content: center;
align-items: center;
}
.optionItem * {
pointer-events: none;
}
.optionItem:hover {
background: var(--active-btn);
}
.voiceCls {
position: relative;
height: 100%;
visibility: hidden;
display: flex;
align-items: center;
}
.voiceCls>svg {
color: var(--lighter-svg-color);
display: block;
margin-left: 5px;
position: relative;
pointer-events: none;
}
.voiceCls:hover>svg {
color: var(--svg-color);
}
.showVoiceCls,
.showVoiceCls .markdown-body {
background: var(--active-btn) !important;
}
.showVoiceCls .voiceCls {
visibility: visible !important;
}
.showEditReq {
position: sticky !important;
top: 0;
bottom: 0;
z-index: 1;
}
.showEditReq,
.showEditReq .markdown-body {
background: var(--active-btn) !important;
}
.readyVoice svg:not(:first-child) {
display: none;
}
.pauseVoice svg:not(:nth-child(2)) {
display: none;
}
.resumeVoice svg:not(:nth-child(3)) {
display: none;
}
#voiceTypes>span {
border-radius: 3px;
margin-left: 4px;
cursor: pointer;
padding: 1px 5px;
}
#voiceTypes>span:hover {
background: var(--active-btn);
}
.selVoiceType {
background: var(--sel-btn) !important;
}
.navHeader {
width: 100%;
padding: 5px 10px;
display: flex;
justify-content: space-between;
}
#newChat {
text-align: center;
width: 80%;
height: 40px;
border-radius: 3px;
background: var(--lighter-active-color);
color: var(--btn-color);
display: flex;
align-items: center;
justify-content: center;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
flex: 1;
}
.navHeader>div:hover {
background: var(--active-btn) !important;
}
#newChat>svg {
margin-right: 2px;
}
#newFolder {
height: 40px;
width: 40px;
margin-left: 10px;
border-radius: 3px;
color: var(--btn-color);
cursor: pointer;
position: relative;
background: var(--lighter-active-color);
-webkit-user-select: none;
user-select: none;
}
#newFolder>svg {
display: block;
margin: 8px auto;
}
.extraChat {
padding: 2px 10px 6px 10px;
position: relative;
}
#searchChat {
width: 100%;
height: 36px;
padding-left: 10px;
padding-right: 16px;
font-size: 16px;
outline: none;
border: none;
color: var(--chat-text-color);
background: var(--lighter-active-color);
border-radius: 3px;
}
#searchChat:focus {
background: var(--active-btn)
}
#searc.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0