Project

General

Profile

« Previous | Next » 

Revision 8708ddd3

Added by koszko about 2 years ago

move parsing of url with targets to misc.js

View differences:

content/main.js
9 9
 * IMPORTS_START
10 10
 * IMPORT handle_page_actions
11 11
 * IMPORT url_item
12
 * IMPORT url_extract_target
12 13
 * IMPORT gen_unique
13 14
 * IMPORT csp_rule
14 15
 * IMPORT sanitize_attributes
......
39 40
    if (url.startsWith("https://") || url.startsWith("http://"))
40 41
	return false;
41 42

  
42
    let url_re = /^([^#]*)((#[^#]*)(#.*)?)?$/;
43
    let match = url_re.exec(document.URL);
44
    let base_url = match[1];
45
    let first_target = match[3];
46
    let second_target = match[4];
43
    const parsed_url = url_extract_target(document.URL);
47 44

  
48
    if (first_target !== undefined &&
49
	first_target === '#' + unique) {
50
	if (second_target !== undefined)
51
	    window.location.href = base_url + second_target;
45
    if (parsed_url.target !== undefined &&
46
	parsed_url.target === '#' + unique) {
47
	if (parsed_url.target2 !== undefined)
48
	    window.location.href = parsed_url.base_url + parsed_url.target2;
52 49
	else
53
	    history.replaceState(null, "", base_url);
50
	    history.replaceState(null, "", parsed_url.base_url);
54 51

  
55 52
	console.log(["allowing whitelisted", document.URL]);
56 53
	return false;

Also available in: Unified diff