1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

wombat: add mutation observers, addressing #71 and maybe #67

rules: fix regex for yt, add rx for wikimedia
This commit is contained in:
Ilya Kreymer 2015-02-03 11:14:06 -08:00
parent 8b5a6be956
commit c47d3ca925
2 changed files with 46 additions and 3 deletions

View File

@ -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:

View File

@ -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();