@@ -13,37 +13,11 @@ STYLE=``;
13
13
OFFLINE_JSON_DATA = null ;
14
14
// END
15
15
16
- let parentDirectoryUrl ;
17
- if ( document . currentScript && document . currentScript . src ) {
18
- // This is run when the script is included via an <script src=...> tag.
19
- // The script is always at the same location, no matter on which page it is inluded.
20
- parentDirectoryUrl = new URL ( document . currentScript . src ) ;
21
- parentDirectoryUrl . pathname = parentDirectoryUrl . pathname . substring ( 0 , parentDirectoryUrl . pathname . lastIndexOf ( "/" ) + 1 ) ;
22
- } else {
23
- // This is run when the script is inlined to a page.
24
- // In this case we can not be certain about where we are, but the python code fixed all relative paths, so that they should work from here.
25
- parentDirectoryUrl = new URL ( window . location . href ) ;
26
- const directoryUrlsUsed = parentDirectoryUrl . pathname . endsWith ( "/" ) || parentDirectoryUrl . pathname . endsWith ( "/index.html" )
27
- if ( directoryUrlsUsed ) {
28
- // Directory URLs are in use -> go up one directory and remove file name
29
- parentDirectoryUrl . pathname = parentDirectoryUrl . pathname . substring ( 0 , parentDirectoryUrl . pathname . lastIndexOf ( "/" ) ) ;
30
- parentDirectoryUrl . pathname = parentDirectoryUrl . pathname . substring ( 0 , parentDirectoryUrl . pathname . lastIndexOf ( "/" ) + 1 ) ;
31
- } else {
32
- // Directory URLs are disabled -> stay in directory but remove file name
33
- parentDirectoryUrl . pathname = parentDirectoryUrl . pathname . substring ( 0 , parentDirectoryUrl . pathname . lastIndexOf ( "/" ) + 1 ) ;
34
- }
35
- }
36
-
37
- parentDirectoryUrl . query = "" ;
38
- parentDirectoryUrl . hash = "" ;
39
- const base_url = parentDirectoryUrl . href . endsWith ( "/" ) ? parentDirectoryUrl . href : parentDirectoryUrl . href + "/" ;
40
- console . debug ( "The base URL for the search result links is" , base_url ) ;
41
-
16
+ // Convert relative to absolute URL
42
17
const normalizeUrl = ( url ) => {
43
- return new URL ( url , location . href ) ;
18
+ return new URL ( url , location . href ) . pathname ;
44
19
} ;
45
20
46
-
47
21
const parent = document . getElementById ( "listing-extract-search" ) ;
48
22
if ( parent ) {
49
23
const search_mode = parent . getAttribute ( "data-searchmode" ) || DEFAULT_SEARCH_MODE ;
@@ -224,7 +198,7 @@ if (parent) {
224
198
const on_json_loaded = ( json ) => {
225
199
// Publicly accessible for easier debugging
226
200
// Remap the URLs based on the location of this script (which is in the same directory as the JSON file)
227
- window . extract_listings_case_sensitive = json . map ( x => ( { ...x , page_url : normalizeUrl ( base_url + x . page_url ) } ) ) ;
201
+ window . extract_listings_case_sensitive = json . map ( x => ( { ...x , page_url : normalizeUrl ( x . page_url ) } ) ) ;
228
202
// @TODO : maybe only cache this if an cae-insensitive mode is selected?
229
203
window . extract_listings_lowercase = window . extract_listings_case_sensitive . map ( x => ( { ...x , text : x . text . toLowerCase ( ) } ) ) ;
230
204
0 commit comments