ChatGPT/scripts/dalle2.js

42 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-05-18 07:32:32 +00:00
/**
* @name dalle2.js
* @version 0.1.0
* @url https://github.com/lencx/ChatGPT/tree/main/scripts/dalle2.js
*/
2023-01-08 04:28:54 +00:00
2023-05-25 01:52:33 +00:00
function dalle2Init() {
2023-05-18 07:32:32 +00:00
document.addEventListener('click', (e) => {
const origin = e.target.closest('a');
2023-01-08 09:04:49 +00:00
if (!origin || !origin.target) return;
2023-01-08 04:28:54 +00:00
if (origin && origin.href && origin.target !== '_self') {
if (/\/(login|signup)$/.test(window.location.href)) {
origin.target = '_self';
} else {
invoke('open_link', { url: origin.href });
}
}
});
if (window.searchInterval) {
clearInterval(window.searchInterval);
}
window.searchInterval = setInterval(() => {
const searchInput = document.querySelector('.image-prompt-form-wrapper form>.text-input');
if (searchInput) {
clearInterval(window.searchInterval);
if (!window.__CHATGPT_QUERY__) return;
const query = decodeURIComponent(window.__CHATGPT_QUERY__);
searchInput.focus();
searchInput.value = query;
}
2023-05-18 07:32:32 +00:00
}, 200);
}
2023-05-18 07:32:32 +00:00
if (document.readyState === 'complete' || document.readyState === 'interactive') {
2023-05-25 01:52:33 +00:00
dalle2Init();
} else {
2023-05-25 01:52:33 +00:00
document.addEventListener('DOMContentLoaded', dalle2Init);
2023-05-18 07:32:32 +00:00
}