Majster87 Posted January 8 Posted January 8 (edited) Próbuje dodac w dziale download kolumne gdzie bedzie dodawało nazwe hostingu na która został wrzucony plik ale dostaje komunikat "Nieznany hosting" prubuje do tego uzyc ten kod: <span id="hosting-name"></span> <script> const fileUrl = "{file.url}"; try { const url = new URL(fileUrl); const host = url.hostname; document.getElementById('hosting-name').innerText = host; } catch (e) { console.error("Nieprawidłowy URL:", fileUrl); document.getElementById('hosting-name').innerText = "Nieznany hosting"; } </script> Ale nie pobiera nazwy. Drugi sposobem jaki próbowałem to takim kodem: <div class="button buttonPrimary externalURL" style="list-style: none;"> <p id="hostInfo">Loading host...</p> </div> <script> document.addEventListener('DOMContentLoaded', function () { const link = document.querySelector('#downloadLink'); const hostInfo = document.querySelector('#hostInfo'); if (link) { const url = link.href; fetch(url, { method: 'HEAD', mode: 'cors' }) .then(response => { const finalUrl = response.url; const host = new URL(finalUrl).hostname; hostInfo.textContent = Host: ${host}; }) .catch(error => { console.error('Błąd w pobieraniu hosta:', error); hostInfo.textContent = 'Nie udało się pobrać hosta.'; }); } }); </script> ale dostaje komunikat "nie udało sie pobrac hosta" Jak to dobrze zrobić żeby pobierało? Albo jakiś prostszy sposób na to? Edited January 8 by Majster87
Manager DawPi Posted January 8 Manager Posted January 8 A tak? <a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a> <span id="hosting-name"></span> <script> document.addEventListener('DOMContentLoaded', function () { const link = document.getElementById('downloadLink'); const hostingNameSpan = document.getElementById('hosting-name'); if (link) { try { const url = new URL(link.href); const host = url.hostname; hostingNameSpan.innerText = host; } catch (err) { console.error('Nieprawidłowy URL:', link.href); hostingNameSpan.innerText = 'Nieznany hosting'; } } }); </script> intermedia - profesjonalne rozwiązania Invision Power Board --- Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.
Majster87 Posted January 8 Author Posted January 8 (edited) Godzinę temu, DawPi napisał(a): A tak? <a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a> <span id="hosting-name"></span> <script> document.addEventListener('DOMContentLoaded', function () { const link = document.getElementById('downloadLink'); const hostingNameSpan = document.getElementById('hosting-name'); if (link) { try { const url = new URL(link.href); const host = url.hostname; hostingNameSpan.innerText = host; } catch (err) { console.error('Nieprawidłowy URL:', link.href); hostingNameSpan.innerText = 'Nieznany hosting'; } } }); </script> Pokazuje adres mojej strony A dodałem to tak: <nav class="contentHeaderNavigation"> <div class="button buttonPrimary externalURL" style="list-style: none;"> <a id="downloadLink" target='_blank' href='{{if settings.idm_antileech AND !$file->requiresDownloadConfirmation()}}{$file->url('download')->csrf()}{{else}}{$file->url('download')}{{endif}}' {{if $file->requiresDownloadConfirmation()}}data-ipsDialog{{endif}} data-datalayer-postfetch > <span id="hosting-name"></span> <script> document.addEventListener('DOMContentLoaded', function () { const link = document.getElementById('downloadLink'); const hostingNameSpan = document.getElementById('hosting-name'); if (link) { try { const url = new URL(link.href); const host = url.hostname; hostingNameSpan.innerText = host; } catch (err) { console.error('Nieprawidłowy URL:', link.href); hostingNameSpan.innerText = 'Nieznany hosting'; } } }); </script> <i class="fa-solid fa-download"></i> <span>Download</span> </a> </div> </nav> Edited January 8 by Majster87
Manager DawPi Posted January 9 Manager Posted January 9 W dniu 8.01.2025 o 10:23, Majster87 napisał(a): Próbuje dodac w dziale download kolumne gdzie bedzie dodawało nazwe hostingu na która został wrzucony plik ale dostaje komunikat "Nieznany hosting" No jak jest taki adres: 23 godziny temu, Majster87 napisał(a): <a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a> To jak ma pokazać? Jeszcze raz - co Ty tu kombinujesz? Chodzi o pliki dodane do Downloads? intermedia - profesjonalne rozwiązania Invision Power Board --- Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.
Majster87 Posted January 9 Author Posted January 9 (edited) Godzinę temu, DawPi napisał(a): Jeszcze raz - co Ty tu kombinujesz? Chodzi o pliki dodane do Downloads? Tak Edited January 9 by Majster87
Solution Weak. Posted January 9 Solution Posted January 9 {{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}} {{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}} {{$parsedUrl = parse_url($url['record_location']);}} {{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}} {{else}} {{if $url['record_type'] == 'upload'}} {{$host = \IPS\Settings::i()->base_url;}} {{else}} {{$host = 'Nieprawidłowy URL';}} {{endif}} {{endif}} {expression="htmlspecialchars($host)"} 1 1
Majster87 Posted January 9 Author Posted January 9 (edited) 2 godziny temu, Weak. napisał(a): {{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}} {{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}} {{$parsedUrl = parse_url($url['record_location']);}} {{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}} {{else}} {{if $url['record_type'] == 'upload'}} {{$host = \IPS\Settings::i()->base_url;}} {{else}} {{$host = 'Nieprawidłowy URL';}} {{endif}} {{endif}} {expression="htmlspecialchars($host)"} Taki sam komunikat jak ja otrzymuje Walcze juz z tym 3 dni i cały czas albo Nieprawidłowy URL, albo puste pole albo Error 😕 Edited January 9 by Majster87
Majster87 Posted January 9 Author Posted January 9 3 godziny temu, Weak. napisał(a): {{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}} {{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}} {{$parsedUrl = parse_url($url['record_location']);}} {{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}} {{else}} {{if $url['record_type'] == 'upload'}} {{$host = \IPS\Settings::i()->base_url;}} {{else}} {{$host = 'Nieprawidłowy URL';}} {{endif}} {{endif}} {expression="htmlspecialchars($host)"} Wkleiłem jeszcze raz i zadziałało 😛 Dzięki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now