From 4a0f1006a21fa70d7b2c540b20318aae5af704ab Mon Sep 17 00:00:00 2001 From: DICE Date: Sun, 2 Jul 2023 12:06:40 +0800 Subject: [PATCH] fix: compose unavailable fix: compose unavailable fix: layout misalignment fix: content issues in exported markdown fix: invalid shortcuts --- forge.config.js | 4 +-- main.js | 13 ++++++-- package-lock.json | 4 +-- package.json | 2 +- preload.js | 82 ++++++++++++++++++++++++++++------------------- 5 files changed, 64 insertions(+), 41 deletions(-) diff --git a/forge.config.js b/forge.config.js index f48029d..48e9d36 100644 --- a/forge.config.js +++ b/forge.config.js @@ -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', @@ -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', diff --git a/main.js b/main.js index af64e9c..0141aed 100644 --- a/main.js +++ b/main.js @@ -42,7 +42,7 @@ 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, @@ -50,7 +50,7 @@ const createWindow = () => { titleBarOverlay: true, titleBarOverlay: { color: isDarkMode ? '#3b3b3b' : '#ffffff', - symbolColor: isDarkMode ? '#f3f3f3' : '#2b2b2b', + symbolColor: isDarkMode ? '#eeeeee' : '#1c1c1c', }, webPreferences: { preload: path.join(__dirname, 'preload.js'), @@ -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') @@ -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(() => { diff --git a/package-lock.json b/package-lock.json index 052b74e..8f43461 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "binggpt", - "version": "0.3.6", + "version": "0.3.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "binggpt", - "version": "0.3.6", + "version": "0.3.7", "license": "Apache-2.0", "dependencies": { "electron-context-menu": "^3.6.1", diff --git a/package.json b/package.json index 36034b0..84fe22e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/preload.js b/preload.js index 7de497e..53d7c7c 100644 --- a/preload.js +++ b/preload.js @@ -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' } @@ -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 @@ -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] @@ -104,7 +110,7 @@ window.addEventListener('DOMContentLoaded', () => { } if (previewOptions) { previewOptions.style.cssText = 'bottom: 1px' - } + }*/ }) // New topic @@ -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() } @@ -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() @@ -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) { @@ -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) } @@ -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 = `` } catch (err) { console.log(err) } @@ -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 @@ -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}` @@ -367,7 +379,11 @@ 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', { @@ -375,7 +391,7 @@ const markdownHandler = (element) => { 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', {