-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manual control function switch (#32)
- Loading branch information
Showing
16 changed files
with
207 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
window.onload = async function () { | ||
const scriptElement = document.head.getElementsByTagName('script')[0].src; | ||
const settings = await require('electron').ipcRenderer.invoke('getSettings'); | ||
window.theme = { | ||
dev: false, | ||
location: decodeURIComponent(scriptElement.replace('addon.js', '').replace('file:///', '')), | ||
theme: settings.theme, | ||
} | ||
const refineScript = document.createElement('script'); | ||
refineScript.type = 'module'; | ||
refineScript.src = scriptElement.replace('addon.js', 'main.mjs'); | ||
document.head.appendChild(refineScript); | ||
refineScript.src = scriptElement.replace('addon.js', 'main.js'); | ||
const configScript = document.createElement('script'); | ||
configScript.src = scriptElement.replace('addon.js', 'config.js'); | ||
document.head.appendChild(configScript); | ||
configScript.onload = function () { | ||
|
||
window.theme = { | ||
...window.theme, | ||
location: decodeURIComponent(scriptElement.replace('addon.js', '').replace('file:///', '')), | ||
theme: settings.theme, | ||
}; | ||
|
||
document.head.appendChild(refineScript); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
window.theme = { | ||
chatbox: [ | ||
"merge-same-user-message", | ||
"enhance-stickers-display", | ||
"not-exist-function", | ||
"special-username-color", | ||
"better-image-display", | ||
"fix-message-content-width", | ||
], | ||
dev: true, | ||
core: [ | ||
"inject-custom-root-style", | ||
"listen-rooms-panel-drag-event", | ||
"modify-chat-box-interval", | ||
"refined-image-gallery", | ||
"file-changes-listener", | ||
"theme-listener", | ||
], | ||
manual: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { fileChangesListener } from "./file-changes-listener"; | ||
import { injectCustomRootStyle } from "./inject-custom-root-style"; | ||
import { listenRoomsPanelDragEvent } from "./listen-rooms-panel-drag-event"; | ||
import { modifyChatBoxInterval } from "./modify-chat-box"; | ||
import { themeListener } from "./theme-listener"; | ||
|
||
export const Cores = { | ||
"inject-custom-root-style": injectCustomRootStyle, | ||
"listen-rooms-panel-drag-event": listenRoomsPanelDragEvent, | ||
"modify-chat-box-interval": modifyChatBoxInterval, | ||
"file-changes-listener": fileChangesListener, | ||
"theme-listener": themeListener, | ||
}; | ||
|
||
export type CoresKey = keyof typeof Cores; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { betterImageDisplay } from "./better-image-display"; | ||
import { enhanceStickersDisplay } from "./enhance-stickers-display"; | ||
import { fixMessageContentWidth } from "./fix-message-content-width"; | ||
import { mergeSameUserMessage } from "./merge-same-user-message"; | ||
import { specialUsernameColor } from "./special-username-color"; | ||
|
||
export const Functions = { | ||
"merge-same-user-message": mergeSameUserMessage, | ||
"better-image-display": betterImageDisplay, | ||
"special-username-color": specialUsernameColor, | ||
"enhance-stickers-display": enhanceStickersDisplay, | ||
"fix-message-content-width": fixMessageContentWidth, | ||
} | ||
|
||
export type FunctionsKey = keyof typeof Functions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import { fileChangesListener } from './core/file-changes-listener'; | ||
import { injectCustomRootStyle } from './core/inject-custom-root-style'; | ||
import { listenRoomsPanelDragEvent } from './core/listen-rooms-panel-drag-event'; | ||
import { modifyChatBoxInterval } from './core/modify-chat-box'; | ||
import { themeListener } from './core/theme-listener'; | ||
import { createConsole, getRoomsPanelWidth } from './utils'; | ||
import { Cores } from "./core"; | ||
import { Functions } from "./functions"; | ||
import { createConsole, createConsoleGroup, getRoomsPanelWidth } from "./utils"; | ||
|
||
function init() { | ||
if (!getRoomsPanelWidth()) { | ||
if (!getRoomsPanelWidth()) { | ||
setTimeout(init, 1000); | ||
createConsole('ADDON', 'rooms-panel not found, try again after 1s'); | ||
createConsole("ADDON", "rooms-panel not found, try again after 1s"); | ||
return; | ||
} | ||
injectCustomRootStyle(); // 注入自定义根样式 | ||
listenRoomsPanelDragEvent(); // 监听侧边栏拖拽事件 | ||
modifyChatBoxInterval(); // 修改聊天框 | ||
// refinedImageGallery(); // 优化图片显示 | ||
fileChangesListener(); // 监听文件变化 | ||
themeListener(); // 监听主题变化 | ||
if (!window.theme.manual || window.theme.dev) { | ||
// 如果不是手动控制功能启动, dev 模式下也会全部启动 | ||
window.theme.core = Object.keys(Cores) as (keyof typeof Cores)[]; | ||
window.theme.chatbox = Object.keys(Functions) as (keyof typeof Functions)[]; | ||
} | ||
createConsoleGroup( | ||
"Init", | ||
"These Core Functions will be executed:", | ||
window.theme.core.map((f) => { | ||
// 将短横线转换为驼峰 | ||
const text = f.replace(/-(\w)/g, function (_all, letter) { | ||
return letter.toUpperCase(); | ||
}) as keyof typeof Cores; | ||
const isCoreExist = Cores[f] !== undefined; | ||
if (!isCoreExist) { | ||
window.theme.core = window.theme.core.filter((c) => c !== f); | ||
} | ||
return { | ||
text: `${text} => ${isCoreExist ? "✅" : "❌"}`, | ||
type: isCoreExist ? "log" : "warn", | ||
}; | ||
}) | ||
); | ||
Promise.all( | ||
window.theme.core.map((fn) => { | ||
return Cores[fn](); | ||
}) | ||
); | ||
} | ||
init(); | ||
init(); |
Oops, something went wrong.