diff --git a/pywb/apps/rewrite_live.py b/pywb/apps/rewrite_live.py new file mode 100644 index 00000000..e3b8f45b --- /dev/null +++ b/pywb/apps/rewrite_live.py @@ -0,0 +1,16 @@ +from pywb.framework.wsgi_wrappers import init_app, start_wsgi_server + +from pywb.webapp.rewrite_handler import create_rewrite_app + +#================================================================= +# init cdx server app +#================================================================= + +application = init_app(create_rewrite_app, load_yaml=False) + + +def main(): # pragma: no cover + start_wsgi_server(application, 'Rewrite App', default_port=8090) + +if __name__ == "__main__": + main() diff --git a/pywb/static/wb.css b/pywb/static/wb.css index 1367a2fe..3a36f54a 100644 --- a/pywb/static/wb.css +++ b/pywb/static/wb.css @@ -5,11 +5,12 @@ top: 0px !important; left: 0px !important; font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif !important; - position: absolute !important; - padding: 4px !important; + position: fixed !important; + /* padding: 4px !important; */ + height: 40px !important; width: 100% !important; font-size: 24px !important; - border: 1px solid !important; +/* border: 1px solid !important; */ background-color: lightYellow !important; color: black !important; text-align: center !important; @@ -17,3 +18,35 @@ line-height: normal !important; } +.wb_iframe_div +{ + width: 100%; + height: 100%; + padding: 40px 8px 8px 0px; + border: none; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; +} + +.wb_iframe +{ + width: 100%; + height: 100%; + border: 4px solid firebrick; +} + +.wb_iframe_all +{ + width: 100%; + height: 100%; + border: none; + background-color: firebrick; + padding: 44px 4px 4px 4px; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; +} + + + diff --git a/pywb/static/wb.js b/pywb/static/wb.js index ae5b586c..41343f81 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -26,6 +26,10 @@ function init_banner() { return; } + if (window.top != window.self) { + return; + } + if (!banner) { banner = document.createElement("wb_div"); banner.setAttribute("id", BANNER_ID); @@ -41,12 +45,54 @@ function init_banner() { } } -var readyStateCheckInterval = setInterval(function() { +function add_event(name, func, object) { + if (object.addEventListener) { + object.addEventListener(name, func); + return true; + } else if (object.attachEvent) { + object.attachEvent("on" + name, func); + return true; + } else { + return false; + } +} + +function remove_event(name, func, object) { + if (object.removeEventListener) { + object.removeEventListener(name, func); + return true; + } else if (object.detachEvent) { + object.detachEvent("on" + name, func); + return true; + } else { + return false; + } +} + +var notified_top = false; + +var detect_on_init = function() { + if (!notified_top && window && window.top && (window.self != window.top) && window.WB_wombat_location) { + if (!wbinfo.is_embed) { + window.top.postMessage(window.WB_wombat_location.href, "*"); + } + notified_top = true; + } + if (document.readyState === "interactive" || document.readyState === "complete") { init_banner(); - - clearInterval(readyStateCheckInterval); + + remove_event("readystatechange", detect_on_init, document); } -}, 10); +} + +add_event("readystatechange", detect_on_init, document); + +/* +if ((window.self == window.top) && !wbinfo.is_embed && window.location.href.indexOf("/rewrite/fr_/") == -1) { + new_loc = window.location.href.replace("/rewrite/", "/rewrite/fr_/"); + window.location.replace(new_loc); +} +*/ diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index 47d5042b..457d7d5a 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -60,18 +60,28 @@ WB_wombat_init = (function() { } } + function ends_with(str, suffix) { + if (str.indexOf(suffix, str.length - suffix.length) !== -1) { + return suffix; + } else { + return undefined; + } + } + //============================================ -/* function rewrite_url_debug(url) { + var rewrite_url = rewrite_url_debug; + + function rewrite_url_debug(url) { rewritten = rewrite_url_(url); if (url != rewritten) { console.log('REWRITE: ' + url + ' -> ' + rewritten); } else { - console.log('NOT REWRITTEN ' + url); + //console.log('NOT REWRITTEN ' + url); } return rewritten; } -*/ - function rewrite_url(url) { + + function rewrite_url_(url) { var http_prefix = "http://"; var https_prefix = "https://"; var rel_prefix = "//"; @@ -144,13 +154,22 @@ WB_wombat_init = (function() { if (!href) { return ""; } + href = href.toString(); + var index = href.indexOf("/http", 1); + + // extract original url from wburl if (index > 0) { - return href.substr(index + 1); - } else { - return href; + href = href.substr(index + 1); } + + // remove trailing slash + if (ends_with(href, "/")) { + href = href.substring(0, href.length - 1); + } + + return href; } //============================================ @@ -196,26 +215,39 @@ WB_wombat_init = (function() { } //============================================ - function update_location(req_href, orig_href, location) { - if (req_href && (extract_orig(orig_href) != extract_orig(req_href))) { - var final_href = rewrite_url(req_href); - - location.href = final_href; + function update_location(req_href, orig_href, actual_location) { + if (!req_href || req_href == orig_href) { + return; } + + ext_orig = extract_orig(orig_href); + ext_req = extract_orig(req_href); + + if (!ext_orig || ext_orig == ext_req) { + return; + } + + var final_href = rewrite_url(req_href); + + console.log(actual_location.href + ' -> ' + final_href); + + actual_location.href = final_href; } //============================================ function check_location_change(loc, is_top) { var locType = (typeof loc); - var location = (is_top ? window.top.location : window.location); + var actual_location = (is_top ? window.top.location : window.location); + + //console.log(loc.href); // String has been assigned to location, so assign it if (locType == "string") { - update_location(loc, location.href, location) + update_location(loc, actual_location.href, actual_location) } else if (locType == "object") { - update_location(loc.href, loc._orig_href, location); + update_location(loc.href, loc._orig_href, actual_location); } } @@ -306,7 +338,6 @@ WB_wombat_init = (function() { window.Worker = undefined; } - function rewrite_attr(elem, name) { if (!elem || !elem.getAttribute) { return; @@ -324,25 +355,41 @@ WB_wombat_init = (function() { orig_value = value; value = rewrite_url(value); - + elem.setAttribute(name, value); } function init_dom_override() { - if (!Element || - !Element.prototype) { + if (!Node || !Node.prototype) { return; } function replace_dom_func(funcname) { + var orig = Node.prototype[funcname]; - var orig = Element.prototype[funcname]; - - Element.prototype[funcname] = function() { + Node.prototype[funcname] = function() { rewrite_attr(arguments[0], "src"); rewrite_attr(arguments[0], "href"); - return orig.apply(this, arguments); + child = arguments[0]; + + var desc; + + if (child instanceof DocumentFragment) { + desc = child.querySelectorAll("*[href],*[src]"); + } else if (child.getElementsByTagName) { + desc = child.getElementsByTagName("*"); + } + + if (desc) { + for (var i = 0; i < desc.length; i++) { + rewrite_attr(desc[i], "src"); + rewrite_attr(desc[i], "href"); + } + } + + result = orig.apply(this, arguments); + return result; } } @@ -363,13 +410,14 @@ WB_wombat_init = (function() { window.WB_wombat_location = copy_location_obj(window.self.location); document.WB_wombat_location = window.WB_wombat_location; - if (window.self.location != window.top.location) { - window.top.WB_wombat_location = copy_location_obj(window.top.location); - } + //if (window.self.location != window.top.location) { + // window.top.WB_wombat_location = copy_location_obj(window.top.location); + //} + window.top.WB_wombat_location = window.WB_wombat_location; - if (window.opener) { - window.opener.WB_wombat_location = copy_location_obj(window.opener.location); - } + //if (window.opener) { + // window.opener.WB_wombat_location = copy_location_obj(window.opener.location); + //} // Domain document.WB_wombat_domain = orig_host; diff --git a/pywb/ui/frame_insert.html b/pywb/ui/frame_insert.html new file mode 100644 index 00000000..fd772251 --- /dev/null +++ b/pywb/ui/frame_insert.html @@ -0,0 +1,54 @@ + + + + + + + + + +
+