Skip to content

Commit

Permalink
fix: compose unavailable
Browse files Browse the repository at this point in the history
fix: compose unavailable
fix: layout misalignment
fix: content issues in exported markdown
fix: invalid shortcuts
  • Loading branch information
dice2o committed Jul 2, 2023
1 parent 04c3819 commit 4a0f100
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
4 changes: 2 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.6',
version: '0.3.7',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand All @@ -56,7 +56,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.6',
version: '0.3.7',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand Down
13 changes: 10 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const createWindow = () => {
// Create window
const mainWindow = new BrowserWindow({
title: 'BingGPT',
backgroundColor: isDarkMode ? '#2b2b2b' : '#f3f3f3',
backgroundColor: isDarkMode ? '#1c1c1c' : '#eeeeee',
icon: 'icon.png',
width: 601,
height: 800,
titleBarStyle: 'hidden',
titleBarOverlay: true,
titleBarOverlay: {
color: isDarkMode ? '#3b3b3b' : '#ffffff',
symbolColor: isDarkMode ? '#f3f3f3' : '#2b2b2b',
symbolColor: isDarkMode ? '#eeeeee' : '#1c1c1c',
},
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
Expand Down Expand Up @@ -214,7 +214,7 @@ const createWindow = () => {
},
},
{
label: 'BingGPT v0.3.6',
label: 'BingGPT v0.3.7',
visible: parameters.selectionText.trim().length === 0,
click: () => {
shell.openExternal('https://github.com/dice2o/BingGPT/releases')
Expand Down Expand Up @@ -353,6 +353,13 @@ const createWindow = () => {
}
}
})
// Replace compose page
mainWindow.webContents.on('dom-ready', () => {
const url = mainWindow.webContents.getURL()
if (url === bingUrl) {
mainWindow.webContents.send('replace-compose-page', isDarkMode)
}
})
}

app.whenReady().then(() => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "binggpt",
"productName": "BingGPT",
"version": "0.3.6",
"version": "0.3.7",
"description": "AI-powered copilot",
"author": "dice2o",
"license": "Apache-2.0",
Expand Down
82 changes: 49 additions & 33 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ window.addEventListener('DOMContentLoaded', () => {
'https://www.bing.com/rewards/authcheck?ru=%2Fmsrewards%2Fapi%2Fv1%2Fenroll%3Fpubl%3DBINGIP%26crea%3DMY00IA%26pn%3Dbingcopilotwaitlist%26partnerId%3DBingRewards%26pred%3Dtrue%26wtc%3Dshoreline/discover%26ru%3Dhttps%253a%252f%252fedgeservices.bing.com%252fedgesvc%252furlredirect%253fscenario%253dwaitlist'
)
}
if (previewBanner) {
previewBanner.style.cssText = 'margin-top: 44px'
}
if (previewCloseBtn) {
previewCloseBtn.style.cssText = 'display: none'
}
Expand All @@ -55,19 +52,28 @@ window.addEventListener('DOMContentLoaded', () => {
const headerWrapper = document.getElementsByClassName('wrapper-unfixed')[0]
const tabWrapper = document.getElementsByClassName('uds-hdr-wrapper')[0]
const tabs = document.getElementsByClassName('uds_tab_hdr')[0]
const insightsTab = document.getElementById('insights')
const aboutTab = document.getElementById('about')
const synopsisTab = document.getElementById('synopsis')
const siteinfoTab = document.getElementById('siteinfo')
if (headerWrapper) {
headerWrapper.style.cssText = 'height: 64px'
}
if (tabWrapper) {
tabWrapper.style.cssText =
'height: 64px; display: flex; justify-content: center; align-items: end; -webkit-user-select: none'
tabWrapper.style.cssText = 'height: 64px; -webkit-user-select: none'
}
if (tabs) {
tabs.style.cssText = 'padding-left: 40px'
tabs.style.cssText =
'height: 64px; padding-top: 0; justify-content: center; align-items: end'
tabs.firstChild.style.cssText = 'margin-left: 19px'
}
if (aboutTab) {
aboutTab.style.cssText = 'display: none'
}
if (synopsisTab) {
synopsisTab.style.cssText = 'display: none'
}
if (insightsTab) {
insightsTab.style.cssText = 'display: none'
if (siteinfoTab) {
siteinfoTab.style.cssText = 'display: none'
}
}
// Chat area of main page
Expand All @@ -83,7 +89,7 @@ window.addEventListener('DOMContentLoaded', () => {
}
}
// Compose page
const composeWrapper = document.getElementsByClassName(
/*const composeWrapper = document.getElementsByClassName(
'uds_coauthor_wrapper'
)[0]
const composeMain = document.getElementsByClassName('sidebar')[0]
Expand All @@ -104,7 +110,7 @@ window.addEventListener('DOMContentLoaded', () => {
}
if (previewOptions) {
previewOptions.style.cssText = 'bottom: 1px'
}
}*/
})

// New topic
Expand All @@ -113,7 +119,7 @@ ipcRenderer.on('new-topic', () => {
const newTopicBtn = document
.getElementsByTagName('cib-serp')[0]
.shadowRoot.getElementById('cib-action-bar-main')
.shadowRoot.querySelector('button[class="button-compose"]')
.shadowRoot.querySelector('.button-compose')
if (newTopicBtn) {
newTopicBtn.click()
}
Expand All @@ -128,6 +134,7 @@ ipcRenderer.on('focus-on-textarea', () => {
const textarea = document
.getElementsByTagName('cib-serp')[0]
.shadowRoot.getElementById('cib-action-bar-main')
.shadowRoot.querySelector('cib-text-input')
.shadowRoot.getElementById('searchbox')
if (textarea) {
textarea.focus()
Expand Down Expand Up @@ -175,6 +182,7 @@ ipcRenderer.on('switch-tone', (event, direction) => {
const toneOptions = document
.getElementsByTagName('cib-serp')[0]
.shadowRoot.getElementById('cib-conversation-main')
.shadowRoot.querySelector('cib-welcome-container')
.shadowRoot.querySelector('cib-tone-selector')
.shadowRoot.getElementById('tone-options')
if (toneOptions) {
Expand Down Expand Up @@ -210,12 +218,10 @@ ipcRenderer.on('set-font-size', (event, size) => {
const conversationMain = serp.shadowRoot.getElementById(
'cib-conversation-main'
)
conversationMain.style.cssText += `--cib-type-body1-font-size: ${size}px; --cib-type-body1-strong-font-size: ${size}px; --cib-type-body2-font-size: ${size}px; --cib-type-body2-line-height: ${
size + 6
}px`
serp.style.cssText += `--cib-type-body2-font-size: ${
size > 15 ? size + 2 : 16
}px; --cib-type-body2-line-height: ${size > 15 ? size + 8 : 22}px`
conversationMain.style.cssText =
serp.style.cssText += `--cib-type-body1-font-size: ${size}px; --cib-type-body1-strong-font-size: ${size}px; --cib-type-body2-font-size: ${size}px; --cib-type-body2-line-height: ${
size + 6
}px`
} catch (err) {
console.log(err)
}
Expand All @@ -231,11 +237,20 @@ ipcRenderer.on('set-initial-style', (event) => {
// Center element
const scroller = conversationMain.shadowRoot.querySelector('.scroller')
const actionBarMain = serp.shadowRoot.getElementById('cib-action-bar-main')
const containerControl =
conversationMain.shadowRoot.querySelector('.container-control')
scroller.style.cssText += 'justify-content: center'
actionBarMain.style.cssText += 'max-width: unset'
containerControl.style.cssText += 'flex-direction: column'
} catch (err) {
console.log(err)
}
})

// Replace compose page
ipcRenderer.on('replace-compose-page', (event, isDarkMode) => {
try {
const composeModule = document.getElementById('underside-coauthor-module')
composeModule.innerHTML = `<iframe id="coauthor" name="coauthor" frameborder="0" csp="frame-src 'none'; base-uri 'self'; require-trusted-types-for 'script'" data-bm="4" src="https://edgeservices.bing.com/edgesvc/compose?udsframed=1&amp;form=SHORUN&amp;clientscopes=chat,noheader,coauthor,channeldev,&amp;${
isDarkMode ? 'dark' : 'light'
}schemeovr=1" style="width: 100%; height: calc(100% - 64px); position: absolute; overflow: hidden"></iframe>`
} catch (err) {
console.log(err)
}
Expand All @@ -255,7 +270,8 @@ ipcRenderer.on('export', (event, format, isDarkMode) => {
allowTaint: true,
ignoreElements: (element) => {
if (
element.classList.contains('intro') ||
element.tagName === 'CIB-WELCOME-CONTAINER' ||
element.tagName === 'CIB-NOTIFICATION-CONTAINER' ||
element.getAttribute('type') === 'host'
) {
return true
Expand All @@ -266,21 +282,17 @@ ipcRenderer.on('export', (event, format, isDarkMode) => {
element.classList.contains('hidden') ||
element.classList.contains('expand-button') ||
element.getAttribute('type') === 'meta' ||
element.tagName === 'CIB-TURN-COUNTER')
element.tagName === 'CIB-TURN-COUNTER' ||
element.tagName === 'BUTTON')
) {
return true
}
},
onclone: (doc) => {
const bodyWidth = doc.body.clientWidth
const paddingX = bodyWidth > 767 ? '32px' : '16px'
const paddingBottom = bodyWidth > 767 ? '48px' : '36px'
const paddingTop =
chatMain.getElementsByTagName('cib-chat-turn')[0].offsetHeight === 0
? '0'
: bodyWidth > 767
? '24px'
: '18px'
const paddingX = bodyWidth > 832 ? '32px' : '16px'
const paddingBottom = '48px'
const paddingTop = bodyWidth > 832 ? '24px' : '0px'
doc.getElementById(
'cib-chat-main'
).style.cssText = `padding: ${paddingTop} ${paddingX} ${paddingBottom} ${paddingX}`
Expand Down Expand Up @@ -367,15 +379,19 @@ const markdownHandler = (element) => {
return node.classList.contains('text-message-content')
},
replacement: (content, node) => {
return `> **${node.firstElementChild.innerHTML}**`
return `> **${node.firstElementChild.innerHTML}**${
node.querySelector('img')
? `\n> ![](${node.querySelector('img').getAttribute('src')})`
: ''
}`
},
})
turndownService.addRule('latex', {
filter: (node) => {
return node.classList.contains('katex-block')
},
replacement: (content, node) => {
return `$$${node.querySelector('annotation').innerHTML.trim()}$$\n\n`
return `$$${node.querySelector('annotation').innerHTML.trim()}$$\n`
},
})
turndownService.addRule('inlineLatex', {
Expand Down

0 comments on commit 4a0f100

Please sign in to comment.