Merge with browser fixes from RossMods
| @@ -1,4 +1,4 @@ | |||
| 1 | import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter, addSafariPatch } from './scripts/RossAscends-mods.js'; | 1 | import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter } from './scripts/RossAscends-mods.js'; |
| 2 | import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js'; | 2 | import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js'; |
| 3 | import { | 3 | import { |
| 4 | generateKoboldWithStreaming, | 4 | generateKoboldWithStreaming, |
| @@ -273,7 +273,6 @@ await new Promise((resolve) => { | |||
| 273 | }); | 273 | }); |
| 274 | 274 | ||
| 275 | showLoader(); | 275 | showLoader(); |
| 276 | applyBrowserFixes(); | ||
| 277 | 276 | ||
| 278 | // Configure toast library: | 277 | // Configure toast library: |
| 279 | toastr.options.escapeHtml = true; // Prevent raw HTML inserts | 278 | toastr.options.escapeHtml = true; // Prevent raw HTML inserts |
| @@ -940,7 +939,7 @@ async function firstLoadInit() { | |||
| 940 | throw new Error('Initialization failed'); | 939 | throw new Error('Initialization failed'); |
| 941 | } | 940 | } |
| 942 | 941 | ||
| 943 | addSafariPatch(); | 942 | applyBrowserFixes(); |
| 944 | await getClientVersion(); | 943 | await getClientVersion(); |
| 945 | await readSecretState(); | 944 | await readSecretState(); |
| 946 | await initLocales(); | 945 | await initLocales(); |
| @@ -121,7 +121,7 @@ export function humanizeGenTime(total_gen_time) { | |||
| 121 | */ | 121 | */ |
| 122 | var parsedUA = null; | 122 | var parsedUA = null; |
| 123 | 123 | ||
| 124 | function getParsedUA() { | 124 | export function getParsedUA() { |
| 125 | if (!parsedUA) { | 125 | if (!parsedUA) { |
| 126 | try { | 126 | try { |
| 127 | parsedUA = Bowser.parse(navigator.userAgent); | 127 | parsedUA = Bowser.parse(navigator.userAgent); |
| @@ -717,18 +717,6 @@ export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, deboun | |||
| 717 | 717 | ||
| 718 | // --------------------------------------------------- | 718 | // --------------------------------------------------- |
| 719 | 719 | ||
| 720 | export function addSafariPatch() { | ||
| 721 | const userAgent = getParsedUA(); | ||
| 722 | console.debug('User Agent', userAgent); | ||
| 723 | const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); | ||
| 724 | const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop'; | ||
| 725 | const isIOS = userAgent?.os?.name === 'iOS'; | ||
| 726 | |||
| 727 | if (isIOS || isMobileSafari || isDesktopSafari) { | ||
| 728 | document.body.classList.add('safari'); | ||
| 729 | } | ||
| 730 | } | ||
| 731 | |||
| 732 | export function initRossMods() { | 720 | export function initRossMods() { |
| 733 | // initial status check | 721 | // initial status check |
| 734 | checkStatusDebounced(); | 722 | checkStatusDebounced(); |
| @@ -741,16 +729,6 @@ export function initRossMods() { | |||
| 741 | RA_autoconnect(); | 729 | RA_autoconnect(); |
| 742 | } | 730 | } |
| 743 | 731 | ||
| 744 | if (isMobile()) { | ||
| 745 | const fixFunkyPositioning = () => { | ||
| 746 | console.debug('[Mobile] Device viewport change detected.'); | ||
| 747 | document.documentElement.style.position = 'fixed'; | ||
| 748 | requestAnimationFrame(() => document.documentElement.style.position = ''); | ||
| 749 | }; | ||
| 750 | window.addEventListener('resize', fixFunkyPositioning); | ||
| 751 | window.addEventListener('orientationchange', fixFunkyPositioning); | ||
| 752 | } | ||
| 753 | |||
| 754 | $('#main_api').change(function () { | 732 | $('#main_api').change(function () { |
| 755 | var PrevAPI = main_api; | 733 | var PrevAPI = main_api; |
| 756 | setTimeout(() => RA_autoconnect(PrevAPI), 100); | 734 | setTimeout(() => RA_autoconnect(PrevAPI), 100); |
| @@ -1,3 +1,5 @@ | |||
| 1 | import { getParsedUA, isMobile } from './RossAscends-mods.js'; | ||
| 2 | |||
| 1 | const isFirefox = () => /firefox/i.test(navigator.userAgent); | 3 | const isFirefox = () => /firefox/i.test(navigator.userAgent); |
| 2 | 4 | ||
| 3 | function sanitizeInlineQuotationOnCopy() { | 5 | function sanitizeInlineQuotationOnCopy() { |
| @@ -43,10 +45,34 @@ function sanitizeInlineQuotationOnCopy() { | |||
| 43 | }); | 45 | }); |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 48 | function addSafariPatch() { | ||
| 49 | const userAgent = getParsedUA(); | ||
| 50 | console.debug('User Agent', userAgent); | ||
| 51 | const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); | ||
| 52 | const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop'; | ||
| 53 | const isIOS = userAgent?.os?.name === 'iOS'; | ||
| 54 | |||
| 55 | if (isIOS || isMobileSafari || isDesktopSafari) { | ||
| 56 | document.body.classList.add('safari'); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 46 | function applyBrowserFixes() { | 60 | function applyBrowserFixes() { |
| 47 | if (isFirefox()) { | 61 | if (isFirefox()) { |
| 48 | sanitizeInlineQuotationOnCopy(); | 62 | sanitizeInlineQuotationOnCopy(); |
| 49 | } | 63 | } |
| 64 | |||
| 65 | if (isMobile()) { | ||
| 66 | const fixFunkyPositioning = () => { | ||
| 67 | console.debug('[Mobile] Device viewport change detected.'); | ||
| 68 | document.documentElement.style.position = 'fixed'; | ||
| 69 | requestAnimationFrame(() => document.documentElement.style.position = ''); | ||
| 70 | }; | ||
| 71 | window.addEventListener('resize', fixFunkyPositioning); | ||
| 72 | window.addEventListener('orientationchange', fixFunkyPositioning); | ||
| 73 | } | ||
| 74 | |||
| 75 | addSafariPatch(); | ||
| 50 | } | 76 | } |
| 51 | 77 | ||
| 52 | export { isFirefox, applyBrowserFixes }; | 78 | export { isFirefox, applyBrowserFixes }; |