docbrown/app/views/layouts/_user_config.html.erb
2023-02-06 10:43:11 +02:00

42 lines
1.4 KiB
Text

<script>
try {
const bodyClass = localStorage.getItem('config_body_class');
const userString = localStorage.getItem('current_user');
if (bodyClass) {
document.body.className = bodyClass;
if (bodyClass.includes('dark-theme')) {
document.getElementById('body-styles').innerHTML = '<style><%= Rails.application.assets["themes/dark.css"].to_s.squish.html_safe %></style>';
}
if (bodyClass.includes('open-dyslexic-article-body')) { // Preloading custom font for anticipated use
const link = document.createElement('link');
link.as = 'font'
link.rel = 'preload'
crossorigin = 'anonymous'
link.href = '<%= asset_path "OpenDyslexic-Regular.otf" %>';
document.head.appendChild(link);
}
}
if (navigator.userAgent === 'DEV-Native-ios') {
document.body.classList.add("dev-ios-native-body");
}
if (window.frameElement) { // Hide top bar and footer when loaded within iframe
document.body.classList.add("hidden-shell");
}
if (userString && userString.length > 0) {
const user = JSON.parse(userString)
const numTags = JSON.parse(user.followed_tags).length
if (numTags < 6) {
document.body.classList.add("user-tags-followed-" + numTags);
} else {
document.body.classList.add("user-tags-followed-max");
}
}
} catch (e) {
setTimeout(function () {
Honeybadger.notify(e);
}, 1000)
}
</script>