added root functionality for block external link feature

This commit is contained in:
Manan Jethwani 2021-03-23 03:17:14 +05:30
parent baed447dd3
commit 93264f7409
2 changed files with 4 additions and 3 deletions

View File

@ -221,9 +221,9 @@ void ContentResponse::inject_externallinks_blocker()
kainjow::mustache::data data;
data.set("root", m_root);
auto script_tag = render_template(RESOURCE::templates::external_blocker_part_html, data);
m_content = appendToFirstOccurence(
m_content = prependToFirstOccurence(
m_content,
"<head>",
"</head[ \\t]*>",
script_tag);
}

View File

@ -1,5 +1,6 @@
const root = document.querySelector( `link[type='root']` ).getAttribute("href");
// `block_path` variable used by openzim/warc2zim to detect whether URL blocking is enabled or not
var block_path = "/catch/external";
var block_path = `${root}/catch/external`;
// called only on external links
function capture_event(e, target) { target.setAttribute("href", encodeURI(block_path + "?source=" + target.href)); }