From c47d3ca925292a093b203d3a42f6084079b1e781 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Tue, 3 Feb 2015 11:14:06 -0800 Subject: [PATCH] wombat: add mutation observers, addressing #71 and maybe #67 rules: fix regex for yt, add rx for wikimedia --- pywb/rules.yaml | 16 +++++++++++++--- pywb/static/wombat.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/pywb/rules.yaml b/pywb/rules.yaml index 325bbd9d..f3016efd 100644 --- a/pywb/rules.yaml +++ b/pywb/rules.yaml @@ -65,7 +65,17 @@ rules: fuzzy_lookup: '()' - # flickr rules + # wikimedia rules + #================================================================= + - url_prefix: 'org,wikimedia,meta)/' + + rewrite: + js_regexs: + - match: '\burl\((\\?/\\?/[^)]+)\)' + rewrite: true + group: 1 + + # flickr rules #================================================================= - url_prefix: ['com,yimg,l)/g/combo', 'com,yimg,s)/pw/combo', 'com,yahooapis,yui)/combo'] fuzzy_lookup: '([^/]+(?:\.css|\.js))' @@ -134,7 +144,7 @@ rules: js_regexs: - match: 'window.location' replace: 'WB_wombat_location' - + # youtube rules #================================================================= @@ -203,7 +213,7 @@ rules: - match: 'ytplayer.load\(\);' replace: 'ytplayer.config.args.dash = "0"; ytplayer.config.args.dashmpd = ""; {0}' - - match: 'yt\.setConfig.*PLAYER_CONFIG.*args": {' + - match: 'yt\.setConfig.*PLAYER_CONFIG.*args":\s*{' replace: '{0} "dash": "0", dashmpd: "", ' req_cookie_rewrite: diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index f0582b43..94587b0b 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -616,6 +616,36 @@ _WBWombat = (function() { window.Worker = undefined; } + + //============================================ + function init_mutation_obs() { + if (!window.MutationObserver) { + return; + } + + var m = new MutationObserver(function(records, observer) + { + for (var i = 0; i < records.length; i++) { + var r = records[i]; + if (r.type == "attributes" && r.attributeName == "style") { + var style = r.target.style.cssText; + if (style.indexOf("url(") > 0) { + var new_style = rewrite_style(style); + if (new_style != style) { + r.target.style.cssText = new_style; + } + } + } + } + }); + + m.observe(document.documentElement, {childList: false, + attributes: true, + subtree: true, + //attributeOldValue: true, + attributeFilter: ["style"]}); + } + //============================================ function rewrite_attr(elem, name, func) { if (!elem || !elem.getAttribute) { @@ -959,6 +989,9 @@ _WBWombat = (function() { init_ajax_rewrite(); init_worker_override(); + // Init mutation observer (for style only) + init_mutation_obs(); + // setAttribute init_setAttribute_override();