@@ -6,12 +6,8 @@ define([], function () {
66 async function checkFavicon ( source ) {
77 return new Promise ( ( resolve , reject ) => {
88 const baseUrl = new URL ( source . get ( 'base' ) ) ;
9- const hostBaseAddress = baseUrl . origin ;
109
1110 async function getFaviconAddress ( baseUrl ) {
12- if ( ! baseUrl instanceof URL ) {
13- baseUrl = new URL ( baseUrl ) ;
14- }
1511 return new Promise ( ( resolve , reject ) => {
1612 if ( settings . get ( 'faviconSource' ) === 'duckduckgo' ) {
1713 resolve ( 'https://icons.duckduckgo.com/ip3/' + baseUrl . host + '.ico' ) ;
@@ -38,60 +34,39 @@ define([], function () {
3834 }
3935 const baseDocumentContents = xhr . responseText . replace ( / < b o d y ( .* ?) < \/ b o d y > / gm, '' ) ;
4036 const baseDocument = new DOMParser ( ) . parseFromString ( baseDocumentContents , 'text/html' ) ;
41- let iconAddress = hostBaseAddress + '/favicon.ico' ;
4237 const iconLinks = [ ...baseDocument . querySelectorAll ( 'link[rel*="icon"][href]' ) ] ;
43- let size = 0 ;
44- let tempIcon = '' ;
38+
4539 iconLinks . some ( ( link ) => {
46- if ( size === 16 ) {
47- return false ;
48- }
49- if ( tempIcon . includes ( 'svg' ) ) {
40+ favicon = link . getAttribute ( 'href' ) ;
41+ if ( ! favicon ) {
5042 return false ;
5143 }
52- const localSize = link . getAttribute ( 'sizes' ) ;
53- if ( ! localSize ) {
54- if ( size === 0 ) {
55- iconAddress = tempIcon ;
56- }
44+ if ( favicon . includes ( 'svg' ) ) {
5745 return false ;
5846 }
59- const side = parseInt ( localSize . split ( 'x' ) [ 0 ] ) ;
60- if ( side === 16 ) {
61- size = side ;
62- iconAddress = tempIcon ;
47+ if ( favicon . startsWith ( '/' ) ) {
48+ const prefix = favicon . startsWith ( '//' ) ? 'https:' : baseUrl . origin ;
49+ resolve ( prefix + favicon ) ;
6350 return true ;
6451 }
65- if ( side < size ) {
66- return false ;
67- }
68- size = side ;
69- iconAddress = tempIcon ;
70- } ) ;
71-
72- if ( ! iconAddress . includes ( '//' ) ) {
73- if ( iconAddress [ 0 ] === '.' ) {
74- iconAddress = iconAddress . substr ( 1 ) ;
75- }
76- if ( iconAddress [ 0 ] === '/' ) {
77- iconAddress = iconAddress . substr ( 1 ) ;
52+ if ( ! favicon . startsWith ( 'http' ) ) {
53+ resolve ( baseUrl . origin + '/' + favicon ) ;
54+ return true ;
7855 }
79- iconAddress = hostBaseAddress + '/' + iconAddress ;
80- }
81- if ( iconAddress . startsWith ( '//' ) ) {
82- iconAddress = baseUrl . protocol ? baseUrl . protocol : 'https:' + iconAddress ;
83- }
8456
85- resolve ( iconAddress ) ;
57+ resolve ( favicon ) ;
58+ } ) ;
8659
60+ resolve ( baseUrl . origin + '/favicon.ico' ) ;
8761 } ;
88- xhr . open ( 'GET' , hostBaseAddress ) ;
62+
63+ xhr . open ( 'GET' , baseUrl ) ;
8964 xhr . timeout = 1000 * 30 ;
9065 xhr . send ( ) ;
9166 } ) ;
9267 }
9368
94- getFaviconAddress ( hostBaseAddress )
69+ getFaviconAddress ( baseUrl )
9570 . then ( ( faviconAddress ) => {
9671 toDataURI ( faviconAddress )
9772 . then ( response => {
0 commit comments