Skip to content

Commit 9a6690f

Browse files
committed
✨ Chatgpt usage enhancement
1 parent f5869d6 commit 9a6690f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

apps.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"name": "chatgpt",
2929
"title": "ChatGPT",
3030
"name_zh": "ChatGPT",
31-
"url": "https://chat.openai.com/chat"
31+
"url": "https://chatgpt.com/"
3232
},
3333
{
3434
"name": "flomo",

src-tauri/src/inject/event.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function isDownloadLink(url) {
4545
'jpg', 'm3u8', 'mov', 'mp3', 'mp4', 'mpa', 'mpg', 'mpeg', 'msi', 'odt',
4646
'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw',
4747
'svg', 'swf', 'tar', 'tif', 'tiff', 'ts', 'txt', 'wav', 'webm', 'webp',
48-
'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip', 'json', 'yaml', '7zip', 'mkv'
48+
'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip', 'json', 'yaml', '7zip', 'mkv',
4949
];
5050
const downloadLinkPattern = new RegExp(`\\.(${fileExtensions.join('|')})$`, 'i');
5151
return downloadLinkPattern.test(url);
@@ -56,7 +56,6 @@ function externalDownLoadLink() {
5656
return ['quickref.me'].indexOf(location.hostname) > -1;
5757
}
5858

59-
6059
document.addEventListener('DOMContentLoaded', () => {
6160
const tauri = window.__TAURI__;
6261
const appWindow = tauri.window.getCurrentWindow();
@@ -181,14 +180,17 @@ document.addEventListener('DOMContentLoaded', () => {
181180
};
182181
}
183182

183+
const isExternalLink = link => window.location.host !== link.host;
184184
// process special download protocol['data:','blob:']
185185
const isSpecialDownload = url => ['blob', 'data'].some(protocol => url.startsWith(protocol));
186186

187187
const isDownloadRequired = (url, anchorElement, e) => anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url);
188188

189189
const handleExternalLink = (e, url) => {
190190
e.preventDefault();
191-
tauri.shell.open(url);
191+
invoke('plugin:shell|open', {
192+
path: url,
193+
});
192194
};
193195

194196
const handleDownloadLink = (e, url, filename) => {
@@ -207,6 +209,12 @@ document.addEventListener('DOMContentLoaded', () => {
207209
const absoluteUrl = hrefUrl.href;
208210
let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
209211

212+
// Handling external link redirection, _blank will automatically open.
213+
if (isExternalLink(absoluteUrl) && (['_new'].includes(anchorElement.target))) {
214+
handleExternalLink(e, absoluteUrl);
215+
return;
216+
}
217+
210218
// Process download links for Rust to handle.
211219
if (isDownloadRequired(absoluteUrl, anchorElement, e) && !externalDownLoadLink() && !isSpecialDownload(absoluteUrl)) {
212220
handleDownloadLink(e, absoluteUrl, filename);
@@ -222,7 +230,7 @@ document.addEventListener('DOMContentLoaded', () => {
222230

223231
// Rewrite the window.open function.
224232
const originalWindowOpen = window.open;
225-
window.open = function (url, name, specs) {
233+
window.open = function(url, name, specs) {
226234
// Apple login and google login
227235
if (name === 'AppleAuthentication') {
228236
//do nothing
@@ -231,7 +239,7 @@ document.addEventListener('DOMContentLoaded', () => {
231239
} else {
232240
const baseUrl = window.location.origin + window.location.pathname;
233241
const hrefUrl = new URL(url, baseUrl);
234-
tauri.shell.open(hrefUrl.href);
242+
handleExternalLink(e, hrefUrl.href);
235243
}
236244
// Call the original window.open function to maintain its normal functionality.
237245
return originalWindowOpen.call(window, url, name, specs);

src-tauri/src/inject/style.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ window.addEventListener('DOMContentLoaded', _event => {
333333
#__next>div>div>.flex.h-screen.w-full.flex-col.items-center {
334334
padding-top: 20px;
335335
}
336+
337+
body > div.relative.flex.h-full.w-full.overflow-hidden.transition-colors.z-0 > div.z-\\[21\\].flex-shrink-0.overflow-x-hidden.bg-token-sidebar-surface-primary.max-md\\:\\!w-0 > div > div > div > nav > div.flex.justify-between.h-\\[60px\\].items-center.md\\:h-header-height {
338+
padding-top: 25px;
339+
}
340+
341+
body > div.relative.flex.h-full.w-full.overflow-hidden.transition-colors.z-0 > div.relative.flex.h-full.max-w-full.flex-1.flex-col.overflow-hidden > main > div.composer-parent.flex.h-full.flex-col.focus-visible\\:outline-0 > div.flex-1.overflow-hidden.\\@container\\/thread > div > div.absolute.left-0.right-0 > div{
342+
padding-top: 35px;
343+
}
336344
337345
#__next .sticky.left-0.right-0.top-0.z-20.bg-black{
338346
padding-top: 0px;

0 commit comments

Comments
 (0)