mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
banner: add back inner frame update of banner on load, if html
rewrite: banner only mode encodes to utf-8, adjusts length
This commit is contained in:
parent
4f9310fe4d
commit
b68ef06067
@ -118,9 +118,22 @@ class RewriteContent:
|
|||||||
|
|
||||||
if head_insert_func:
|
if head_insert_func:
|
||||||
head_insert_str = head_insert_func(rule, cdx)
|
head_insert_str = head_insert_func(rule, cdx)
|
||||||
|
head_insert_str = head_insert_str.encode('utf-8')
|
||||||
|
|
||||||
if wb_url.is_banner_only:
|
if wb_url.is_banner_only:
|
||||||
gen = self._head_insert_only_gen(head_insert_str, stream)
|
gen = self._head_insert_only_gen(head_insert_str, stream)
|
||||||
|
|
||||||
|
content_len = headers.get_header('Content-Length')
|
||||||
|
try:
|
||||||
|
content_len = int(content_len)
|
||||||
|
except Exception:
|
||||||
|
content_len = None
|
||||||
|
|
||||||
|
if content_len and content_len >= 0:
|
||||||
|
content_len = str(content_len + len(head_insert_str))
|
||||||
|
status_headers.replace_header('Content-Length',
|
||||||
|
content_len)
|
||||||
|
|
||||||
return (status_headers, gen, False)
|
return (status_headers, gen, False)
|
||||||
|
|
||||||
rewriter = rewriter_class(urlrewriter,
|
rewriter = rewriter_class(urlrewriter,
|
||||||
@ -162,7 +175,8 @@ class RewriteContent:
|
|||||||
matcher = self.HEAD_REGEX.search(buff)
|
matcher = self.HEAD_REGEX.search(buff)
|
||||||
|
|
||||||
if matcher:
|
if matcher:
|
||||||
yield buff[:matcher.end()] + insert_str
|
yield buff[:matcher.end()]
|
||||||
|
yield insert_str
|
||||||
yield buff[matcher.end():]
|
yield buff[matcher.end():]
|
||||||
else:
|
else:
|
||||||
yield insert_str
|
yield insert_str
|
||||||
|
@ -119,14 +119,36 @@ function remove_event(name, func, object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((window.self == window.top) && (window.self.top == window.top) && wbinfo) {
|
function notify_top() {
|
||||||
if (wbinfo.canon_url && (window.location.href != wbinfo.canon_url)) {
|
if (window.parent != window.top) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window.WB_wombat_location) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(window.WB_wombat_location.href) != "string") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.parent.update_wb_url(window.WB_wombat_location.href,
|
||||||
|
wbinfo.timestamp,
|
||||||
|
wbinfo.is_live);
|
||||||
|
|
||||||
|
remove_event("readystatechange", notify_top, document);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((window.self == window.top) && wbinfo) {
|
||||||
|
if (wbinfo.canon_url && (window.location.href != wbinfo.canon_url) && wbinfo.mod != "bn_") {
|
||||||
// Auto-redirect to top frame
|
// Auto-redirect to top frame
|
||||||
window.location.replace(wbinfo.canon_url);
|
window.location.replace(wbinfo.canon_url);
|
||||||
} else {
|
} else {
|
||||||
// Init Banner (no frame or top frame)
|
// Init Banner (no frame or top frame)
|
||||||
add_event("readystatechange", init_banner, document);
|
add_event("readystatechange", init_banner, document);
|
||||||
}
|
}
|
||||||
|
} else if (window.self != window.parent && window.parent.update_wb_url) {
|
||||||
|
add_event("readystatechange", notify_top, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var update_wb_url = push_state;
|
|
||||||
|
|
||||||
var LIVE_COOKIE_REGEX = /pywb.timestamp=([\d]{1,14})/;
|
var LIVE_COOKIE_REGEX = /pywb.timestamp=([\d]{1,14})/;
|
||||||
|
|
||||||
|
var curr_state = {};
|
||||||
|
|
||||||
|
|
||||||
function make_outer_url(url, ts)
|
function make_outer_url(url, ts)
|
||||||
{
|
{
|
||||||
@ -41,13 +41,13 @@ function push_state(url, timestamp, capture_str, is_live) {
|
|||||||
|
|
||||||
window.history.replaceState(state, "", state.outer_url);
|
window.history.replaceState(state, "", state.outer_url);
|
||||||
|
|
||||||
update_status(state.capture_str, is_live);
|
set_state(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pop_state(state) {
|
function pop_state(state) {
|
||||||
update_status(state.capture_str, state.is_live);
|
set_state(state);
|
||||||
|
|
||||||
window.frames[0].src = state.outer_url;
|
window.frames[0].src = state.inner_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_ts(url)
|
function extract_ts(url)
|
||||||
@ -75,27 +75,29 @@ function extract_replay_url(url) {
|
|||||||
return url.substring(inx + 1);
|
return url.substring(inx + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_status(str, is_live) {
|
function set_state(state) {
|
||||||
var capture_info = document.getElementById("_wb_capture_info");
|
var capture_info = document.getElementById("_wb_capture_info");
|
||||||
if (capture_info) {
|
if (capture_info) {
|
||||||
capture_info.innerHTML = str;
|
capture_info.innerHTML = state.capture_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
var label = document.getElementById("_wb_label");
|
var label = document.getElementById("_wb_label");
|
||||||
if (label) {
|
if (label) {
|
||||||
if (is_live) {
|
if (state.is_live) {
|
||||||
label.innerHTML = _wb_js.labels.LIVE_MSG;
|
label.innerHTML = _wb_js.labels.LIVE_MSG;
|
||||||
} else {
|
} else {
|
||||||
label.innerHTML = _wb_js.labels.REPLAY_MSG;
|
label.innerHTML = _wb_js.labels.REPLAY_MSG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curr_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onpopstate = function(event) {
|
window.onpopstate = function(event) {
|
||||||
var curr_state = event.state;
|
var state = event.state;
|
||||||
|
|
||||||
if (curr_state) {
|
if (state) {
|
||||||
pop_state(curr_state);
|
pop_state(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +134,16 @@ function iframe_loaded(event) {
|
|||||||
ts = extract_ts(iframe.location.href);
|
ts = extract_ts(iframe.location.href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_wb_url(url, ts, is_live);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_wb_url(url, ts, is_live) {
|
||||||
|
if (curr_state.url == url && curr_state.timestamp == ts) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
capture_str = _wb_js.ts_to_date(ts, true);
|
capture_str = _wb_js.ts_to_date(ts, true);
|
||||||
|
|
||||||
update_wb_url(url, ts, capture_str, is_live);
|
push_state(url, ts, capture_str, is_live);
|
||||||
}
|
}
|
||||||
|
@ -699,7 +699,7 @@ WB_wombat_init = (function() {
|
|||||||
wb_replay_prefix = replay_prefix;
|
wb_replay_prefix = replay_prefix;
|
||||||
|
|
||||||
if (wb_replay_prefix) {
|
if (wb_replay_prefix) {
|
||||||
wb_replay_date_prefix = replay_prefix + capture_date + "em_/";
|
wb_replay_date_prefix = replay_prefix + capture_date + "mp_/";
|
||||||
|
|
||||||
if (capture_date.length > 0) {
|
if (capture_date.length > 0) {
|
||||||
wb_capture_date_part = "/" + capture_date + "/";
|
wb_capture_date_part = "/" + capture_date + "/";
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
wbinfo = {}
|
wbinfo = {}
|
||||||
wbinfo.timestamp = "{{ cdx.timestamp }}";
|
wbinfo.timestamp = "{{ cdx.timestamp }}";
|
||||||
wbinfo.prefix = "{{ wbrequest.wb_prefix }}";
|
wbinfo.prefix = "{{ wbrequest.wb_prefix }}";
|
||||||
wbinfo.is_frame_mp = {{"true" if wbrequest.wb_url.mod == 'mp_' else "false"}};
|
wbinfo.mod = "{{ wbrequest.wb_url.mod }}";
|
||||||
wbinfo.canon_url = "{{ canon_url }}";
|
wbinfo.canon_url = "{{ canon_url }}";
|
||||||
wbinfo.is_live = {{ "true" if cdx.is_live else "false" }};
|
wbinfo.is_live = {{ "true" if cdx.is_live else "false" }};
|
||||||
wbinfo.is_proxy_mode = {{ "true" if wbrequest.options.is_proxy else "false" }};
|
wbinfo.is_proxy_mode = {{ "true" if wbrequest.options.is_proxy else "false" }};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user