function isIE() { return /*@cc_on!@*/false || !!document.documentMode; } function isEdge() { const ua = window.navigator.userAgent; const edge = ua.indexOf('Edge/'); if (edge > 0) { // Edge (IE 12+) => return version number return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); } // other browser return false; } function isSafari() { const isSafari = /constructor/i.test(window.HTMLElement) || (function(p) { return p.toString() === '[object SafariRemoteNotification]'; // eslint-disable-next-line no-undef })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification)); return isSafari; } function isMac() { const ua = window.navigator.userAgent.toLowerCase(); return /macintosh/i.test(ua); } function isMobile() { const ua = window.navigator.userAgent.toLowerCase(); return /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(ua); } function isAndroid() { const ua = window.navigator.userAgent.toLowerCase(); return /(android|kindle|silk)/g.test(ua); } function isLinux() { const ua = window.navigator.userAgent.toLowerCase(); return !isAndroid && /linux/.test(ua); } function getUrlParam(name, hashBased=false) { const url = hashBased ? window.location.hash.substr(1) : window.location.search; const urlParams = new URLSearchParams(url); return urlParams.get(name); } function isUtweb() { let ut; //remote if (window.location.hostname.match('utweb') || window.location.hostname.match('btweb')) { ut = Boolean(window.location.hostname.match('utweb')); } //localhost if (ut === undefined) { ut = window.location.port === '19575'; } return ut; } function getWebApiBaseUrl() { let urlBase = 'http://127.0.0.1' + (isUtweb() ? ':19575' : ':38565'); return urlBase + '/gui/'; } function badBrowser() { const edgeVersion = isEdge(); return isSafari() || isIE() || (edgeVersion && (edgeVersion < 17)); } // GA3 - remove later function sendPing(action, label) { let source = getUrlParam('utm_source'); let category = source ? 'share-' + source : 'share'; ga('send', { hitType: 'event', eventCategory: category, eventAction: action, eventLabel: label, }); } function sendGA4Ping(action, label) { let source = getUrlParam('utm_source'); let category = source ? 'share-' + source : 'share'; gtag('event', category, { eventAction: action, eventLabel: label, }); } function setDownloadText() { document.getElementById("os-download-text").innerHTML = isMac() ? '2. Run the .dmg file' : '2. Run the .exe file' ; } function setMagnetInfo() { // Store torrent magnet link into 'share' localstorage array const magnetLink = getUrlParam('link', true); if (magnetLink) { let magnets = JSON.parse(window.localStorage.getItem('share') || '[]') if (!magnets.includes(magnetLink)) { magnets.push(magnetLink); window.localStorage.setItem('share', JSON.stringify(magnets)); } } } function downloadClick() { let downloadUrl = ''; if (isUtweb()) { downloadUrl = isMac() ? 'https://www.utorrent.com/web/downloads/complete/track/stable/os/mac/' : 'https://www.utorrent.com/web/downloads/complete/track/stable/os/win/'; } else { downloadUrl = 'https://www.bittorrent.com/downloads/complete/'; } sendPing('click', 'download'); sendGA4Ping('download_app'); window.open(downloadUrl, '_self'); } function addMagnetClick() { const magnetLink = getUrlParam('link', true); sendPing('click', 'magnet'); sendGA4Ping('add_torrent'); window.open(magnetLink, '_self'); } function notSupported() { return isMobile() || isAndroid() || isLinux(); } function isInstalled() { return window.localStorage.getItem('language'); } function running() { // App running, redirect to index.html document.getElementById('running').style.display = 'flex'; sendPing('pageload', 'app running') sendGA4Ping('pageload', 'app_running'); let url = location.protocol + '//' + location.host + location.pathname; window.location = url.replace('share.html', 'index.html'); } function notRunning() { // Check if app is installed by checking localstorage value // We cant check if installed on localhost browsers so assume not installed if (!isInstalled()) { document.getElementById('not-installed').style.display = 'flex'; if (badBrowser()) { document.getElementById('localhost-browser').style.display = 'flex'; sendPing('pageload', 'localhost browser'); sendGA4Ping('pageload', 'localhost_browser'); } else { sendPing('pageload', 'app not installed') sendGA4Ping('pageload', 'app_not_installed'); } } else { document.getElementById('not-running').style.display = 'flex'; sendPing('pageload', 'app not running') sendGA4Ping('pageload', 'app_not_running') } } function checkPresence() { // Check if on mobile/android/linux, etc if (notSupported()) { document.getElementById('not-supported').style.display = 'flex'; let errorStr = 'device not supported'; // GA3 - remove later let errorGA4Str = 'device_not_supported'; if (isLinux()) { errorStr += ' (linux)'; errorGA4Str += '_linux'; } else if (isAndroid()) { errorStr += ' (android)'; errorGA4Str += '_android'; } else if (isMobile()) { errorStr += ' (mobile)'; errorGA4Str += '_mobile'; } sendPing('pageload', errorStr) sendGA4Ping('pageload', errorGA4Str); return; } //Check if app is running by sending ping request (only in version >= 1.1.3) const pingUrl = getWebApiBaseUrl() + '?action=ping'; fetch(pingUrl) .then(function() { running(); }) .catch(function() { notRunning(); }); } setDownloadText(); setMagnetInfo(); checkPresence();