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:

common/misc.js
41 41
    return match[1];
42 42
}
43 43

  
44
/*
45
 * Assume a url like: https://example.com/green?illuminati=confirmed#tinky#winky
46
 * This function will make it into an object like:
47
 * {
48
 *     "base_url" : "https://example.com/green?illuminati=confirmed",
49
 *     "target" : "#tinky",
50
 *     "target2" : "#winky"
51
 * }
52
 * In case url doesn't have 2 #'s, target2 and target can be set to undefined.
53
 */
54
function url_extract_target(url)
55
{
56
    let url_re = /^([^#]*)((#[^#]*)(#.*)?)?$/;
57
    let match = url_re.exec(url);
58
    return {
59
	base_url : match[1],
60
	target : match[3],
61
	target2 : match[4]
62
    };
63
}
64

  
44 65
/* csp rule that blocks all scripts except for those injected by us */
45 66
function csp_rule(nonce)
46 67
{
......
54 75
 * EXPORTS_START
55 76
 * EXPORT gen_unique
56 77
 * EXPORT url_item
78
 * EXPORT url_extract_target
57 79
 * EXPORT csp_rule
58 80
 * EXPORTS_END
59 81
 */

Also available in: Unified diff