Home Reference Source

HTMLAnchorElement

keep a copy of the original element get/set properties in back pocket init_loc_override

Example:

 var anchor_orig = {}

function save_prop(prop) {
anchor_orig["get_" + prop] =
          get_orig_getter($wbwindow.HTMLAnchorElement.prototype, prop);
anchor_orig["set_" + prop] =
          get_orig_setter($wbwindow.HTMLAnchorElement.prototype, prop);
}

for (var i = 0; i < URL_PROPS.length; i++) {
 save_prop(URL_PROPS[i]);
}

var anchor_setter = function(prop, value) {
 var func = anchor_orig["set_" + prop];
 if (func) {
   return func.call(this, value);
 } else {
        return "";
 }
}

var anchor_getter = function(prop) {
 var func = anchor_orig["get_" + prop];
 if (func) {
   return func.call(this);
 } else {
   return "";
 }
}

init_loc_override($wbwindow.HTMLAnchorElement.prototype,
          anchor_setter, anchor_getter);
$wbwindow.HTMLAnchorElement.prototype.toString = function () {
  return this.href;
};

XMLHttpRequest

Method Summary

Public Methods
public

open(method: *, url: *, async: *, user: *, password: *)

rewrite url if rewrite enabled call original check if url starts with data: if does set 'X-Pywb-Requested-With', 'XMLHttpRequest'

Example:

if (!$wbwindow.XMLHttpRequest ||
!$wbwindow.XMLHttpRequest.prototype ||
!$wbwindow.XMLHttpRequest.prototype.open) {
  return;
}

var orig = $wbwindow.XMLHttpRequest.prototype.open;
function open_rewritten(method, url, async, user, password) {
  if (!this._no_rewrite) {
    url = rewrite_url(url);
  }

 // defaults to true
 if (async != false) {
  async = true;
 }

 result = orig.call(this, method, url, async, user, password);
 if (!starts_with(url, "data:")) {
  this.setRequestHeader('X-Pywb-Requested-With', 'XMLHttpRequest');
 }
}

$wbwindow.XMLHttpRequest.prototype.open = open_rewritten;