Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './style/default.css'
import { GM_addStyle, GM_getValue, GM_registerMenuCommand, GM_setValue, GM_unregisterMenuCommand } from '$'
import { getAnswer } from './answer.js'
import { getContainer, initContainer } from './container.js'
import './style/default.css'

function getWebsite() {
function configRequestImmediately(name) {
Expand Down Expand Up @@ -42,26 +43,59 @@ function getQuestion() {
}
}

function getPosition() {
return GM_getValue('containerPosition', 1)
}
function setPosition(newPosition) {
GM_setValue('containerPosition', newPosition)
}

function initUI() {
function googleInjectContainer() {
const container = getContainer()
const siderbarContainer = document.getElementById("rhs");
if (siderbarContainer) {
siderbarContainer.prepend(container);
if (getPosition() === 1) {
// side
const container = getContainer()
const siderbarContainer = document.getElementById("rhs");
if (siderbarContainer) {
siderbarContainer.prepend(container);
} else {
container.classList.add("sidebar-free");
document.getElementById("rcnt").appendChild(container);
}
} else {
container.classList.add("sidebar-free");
document.getElementById("rcnt").appendChild(container);
GM_addStyle('.chat-gpt-container{max-width: 100%!important}')
const container2 = getContainer();
const mainContainer = document.querySelector("#search")
if (mainContainer) {
mainContainer.prepend(container2);
}
}
}
function bingInjectContainer() {
const container = getContainer()
const siderbarContainer = document.getElementById("b_context");
siderbarContainer.prepend(container);
if (getPosition() === 1) {
// side
const container = getContainer()
const siderbarContainer = document.getElementById("b_context");
siderbarContainer.prepend(container);
} else {
GM_addStyle('.chat-gpt-container{max-width: 100%!important}')
GM_addStyle('.chat-gpt-container{width: 70vw}')
const container2 = getContainer();
const mainBarContainer = document.querySelector("main");
mainBarContainer.prepend(container2);
}
}
function baiduInjectContainer() {
const container = getContainer()
const siderbarContainer = document.getElementById("content_right");
siderbarContainer.prepend(container);
if (getPosition() === 1) {
const container = getContainer()
const siderbarContainer = document.getElementById("content_right");
siderbarContainer.prepend(container);
} else {
GM_addStyle('.chat-gpt-container{max-width: 100%!important}')
const container2 = getContainer();
const siderbarContainer = document.querySelector("#content_left");
siderbarContainer.prepend(container2);
}
}
function duckduckgoInjectContainer() {
const container = getContainer()
Expand Down Expand Up @@ -116,9 +150,20 @@ function initUI() {
}
}

function initMenu() {
let position_id = GM_registerMenuCommand("Container Position - Side(1)/Top(0): " + getPosition(), position_switch, "M");

function position_switch() {
GM_unregisterMenuCommand(position_id);
setPosition((getPosition() + 1) % 2)
position_id = GM_registerMenuCommand("Container Position - Side(1)/Top(0): " + getPosition(), position_switch, "M");
location.reload()
}
}

async function main() {
initUI()
initUI();
initMenu();
if (getWebsite().type === "immediately") {
getAnswer(getQuestion())
}
Expand Down
2 changes: 2 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export default defineConfig({
'GM_getValue',
'GM_deleteValue',
'GM_addStyle',
'GM_registerMenuCommand',
'GM_unregisterMenuCommand',
],
namespace: 'https://greasyfork.org/scripts/456077',
updateURL: 'https://greasyfork.org/scripts/456077-chat-gpt-search-sidebar/code/chat-gpt-search-sidebar.user.js',
Expand Down