diff --git a/.gitattributes b/.gitattributes index fcadb2c..da1a09e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,7 @@ +* text=auto * text eol=lf +*.png binary +*.otf binary +*.ttf binary +*.woff binary +*.woff2 binary diff --git a/assets/gitbook-fix.css b/assets/gitbook-fix.css index 5b3922f..29935b5 100644 --- a/assets/gitbook-fix.css +++ b/assets/gitbook-fix.css @@ -1,3 +1,23 @@ +:root { + --color-graystyle-background: rgba(0, 0, 0, 0.07); + --color-icon-in-background: white; + --color-graystyle: rgba(0, 0, 0, 0.2); + --color-nav-background-base: null; +} + +.color-theme-1 { + --color-graystyle-background: rgba(255, 255, 255, 0.48); + --color-icon-in-background: black; + --color-graystyle: rgba(135, 127, 106, 0.5); + --color-nav-background-base: #1111111; +} + +.color-theme-2 { + --color-graystyle-background: rgba(29, 34, 63, 0.6); + --color-icon-in-background: white; + --color-graystyle: rgba(193, 198, 215, 0.2); + --color-nav-background-base: #252737; +} .fold > ul { max-height: 0; @@ -54,8 +74,8 @@ top: 1px; right: 20px; padding: 0 5px 2px; - background: rgba(0,0,0,.07); - color: white; + background: var(--color-graystyle-background); + color: var(--color-icon-in-background); border-bottom: 0; border-radius: 0 0 5px 5px; z-index: 1000; @@ -72,9 +92,13 @@ .book .book-summary ul.summary li span.annotation { padding: 0; font-size: 0.2em; - color: rgba(0, 0, 0, 0.2); + color: var(--color-graystyle); } .book .book-summary ul.summary li span.annotation:hover { text-decoration: none !important; } + +#book-search-input { + background-color: var(--color-nav-background-base); +} diff --git a/assets/gitbook-fix.js b/assets/gitbook-fix.js index f7aa339..b4fee80 100644 --- a/assets/gitbook-fix.js +++ b/assets/gitbook-fix.js @@ -1,7 +1,11 @@ const WITH_SUMMARY_CLASS = "with-summary" +const DROPDOWN_OPEN_CLASS = "open"; + let bookRoot; +let fontSettingDiv; + function summaryOnOrOff () { if (bookRoot.classList.contains(WITH_SUMMARY_CLASS)) { @@ -16,6 +20,8 @@ window.onload = function () { bookRoot = document.getElementsByClassName("book")[0]; + fontSettingDiv = document.getElementsByClassName("font-settings")[0].getElementsByClassName("dropdown-menu")[0]; + if (window.innerWidth > 600) { bookRoot.classList.add(WITH_SUMMARY_CLASS); } @@ -42,3 +48,69 @@ for (const node of document.getElementsByClassName("summary-container")) { }) } + +function openOrCloseFontSettings () { + if (fontSettingDiv.classList.contains(DROPDOWN_OPEN_CLASS)) { + fontSettingDiv.classList.remove(DROPDOWN_OPEN_CLASS); + } else { + fontSettingDiv.classList.add(DROPDOWN_OPEN_CLASS); + } +} + +function getFontSize () { + return parseInt( + / font-size-([0-9]+) /.exec(bookRoot.className)[1] + ); +} + +function setFontSize (size) { + if (size < 0) size = 0; + else if (size > 4) size = 4; + bookRoot.className = bookRoot.className.replace(/ font-size-[0-9]+ /, " font-size-"+size+" "); + setCookie("font-size", size); +} + +function enlargeFontSize () { + setFontSize(getFontSize()+1); +} + +function reduceFontSize () { + setFontSize(getFontSize()-1); +} + +function setFontFamily (familyId) { + bookRoot.className = bookRoot.className.replace(/ font-family-[0-9]+ /, " font-family-"+familyId+" "); + setCookie("font-family", familyId); +} + +function setFontFamilySerif () { + setFontFamily(0); +} + +function setFontFamilySans () { + setFontFamily(1); +} + +function setColorTheme (colorThemeId) { + bookRoot.className = bookRoot.className.replace(/ color-theme-[0-9]+ /, " color-theme-"+colorThemeId+" "); + setCookie("color-theme", colorThemeId); +} + +function setColorThemeWhite () { + setColorTheme(0); +} + +function setColorThemeSepia () { + setColorTheme(1); +} + +function setColorThemeNight () { + setColorTheme(2); +} + +function setCookie(name, value) { + const d = new Date() + d.setTime(d.getTime() + (30*24*60*60*1000)); + const expires = "expires=" + d.toGMTString() + document.cookie = name + "=" + value + "; " + expires; +} diff --git a/index.php b/index.php index 780e3d1..84d0f0b 100644 --- a/index.php +++ b/index.php @@ -101,23 +101,23 @@ try { diff --git a/src/Data/SiteMeta.php b/src/Data/SiteMeta.php index de6d135..65a1fe3 100644 --- a/src/Data/SiteMeta.php +++ b/src/Data/SiteMeta.php @@ -29,6 +29,7 @@ class SiteMeta { public static function getGitbookStylesheetsList (): array { return array( "/assets/gitbook/style.css", + "/assets/gitbook/gitbook-plugin-fontsettings/website.css", "/assets/gitbook-fix.css", ); } @@ -48,4 +49,11 @@ class SiteMeta { return file_get_contents("./data/$id.js"); } + public static function getUserThemes (): string { + $fontSize = $_COOKIE['font-size'] ?? 2; + $fontFamily = $_COOKIE['font-family'] ?? 1; + $colorTheme = $_COOKIE['color-theme'] ?? 0; + return "font-size-$fontSize font-family-$fontFamily color-theme-$colorTheme"; + } + } diff --git a/template/header.php b/template/header.php index 61117eb..d66ad1b 100644 --- a/template/header.php +++ b/template/header.php @@ -27,5 +27,5 @@ -
+
\ No newline at end of file