Merge with browser fixes from RossMods

This commit is contained in:
Cohee
2024-10-17 21:25:50 +03:00
parent 34ff8e239f
commit f897a4ab1a
3 changed files with 29 additions and 26 deletions

View File

@ -1,3 +1,5 @@
import { getParsedUA, isMobile } from './RossAscends-mods.js';
const isFirefox = () => /firefox/i.test(navigator.userAgent);
function sanitizeInlineQuotationOnCopy() {
@ -43,10 +45,34 @@ function sanitizeInlineQuotationOnCopy() {
});
}
function addSafariPatch() {
const userAgent = getParsedUA();
console.debug('User Agent', userAgent);
const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop';
const isIOS = userAgent?.os?.name === 'iOS';
if (isIOS || isMobileSafari || isDesktopSafari) {
document.body.classList.add('safari');
}
}
function applyBrowserFixes() {
if (isFirefox()) {
sanitizeInlineQuotationOnCopy();
}
if (isMobile()) {
const fixFunkyPositioning = () => {
console.debug('[Mobile] Device viewport change detected.');
document.documentElement.style.position = 'fixed';
requestAnimationFrame(() => document.documentElement.style.position = '');
};
window.addEventListener('resize', fixFunkyPositioning);
window.addEventListener('orientationchange', fixFunkyPositioning);
}
addSafariPatch();
}
export { isFirefox, applyBrowserFixes };