Skip to content
Closed
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
18 changes: 18 additions & 0 deletions src/plugin/syringe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function childNodes(node: Node): Node[] {
const skipNodeName = new Set<string>(['TITLE', 'LINK', 'META', 'HEAD', 'SCRIPT', 'BR', 'HR', 'STYLE', 'MARK']);
const ignoreClassName = `eh-syringe-ignore`;
const skipElementMatcher = `.${ignoreClassName}, .${ignoreClassName} *, [translate=no], [translate=no] :not([translate=yes])`;
const hAthFontStyleId = 'ehs-hath-font-style';

declare global {
interface Window {
Expand Down Expand Up @@ -259,6 +260,7 @@ export class Syringe {
this.config = config;
this.storage.set('config', config);
this.setRootAttrs();
this.setPageStyles();
this.translateTags();
}

Expand Down Expand Up @@ -304,6 +306,7 @@ export class Syringe {
this.documentEnd = true;
});
this.setRootAttrs();
this.setPageStyles();
const { body } = document;
if (body) {
const nodes = childNodes(body);
Expand Down Expand Up @@ -363,6 +366,8 @@ export class Syringe {
readonly isEh = isEh(location.hostname);
readonly isRepo = isRepo(location.hostname);
readonly isWiki = isWiki(location.hostname);
readonly isHentaiAtHome = location.pathname === '/hentaiathome.php';

setRootAttrs(): void {
const node = document.documentElement;
if (!node) return;
Expand Down Expand Up @@ -399,6 +404,19 @@ export class Syringe {
node.classList.add(`ehs-image-level-${this.config.introduceImageLevel}`);
}

private setPageStyles(): void {
const style = document.getElementById(hAthFontStyleId);
if (!this.isHentaiAtHome || !this.config.translateUi) {
style?.remove();
return;
}
if (style) return;
const nextStyle = document.createElement('style');
nextStyle.id = hAthFontStyleId;
nextStyle.textContent = '#hct { font-family: sans-serif; }';
(document.head ?? document.documentElement)?.append(nextStyle);
}

translateNode(node: Node): void {
const { nodeName } = node;
if (!nodeName || skipNodeName.has(nodeName)) return;
Expand Down
Loading