Skip to content

Instantly share code, notes, and snippets.

View lushijie's full-sized avatar

Shijie Lu lushijie

  • Meituan && Qihoo 360
  • Beijing
View GitHub Profile
function interceptNetworkRequests(ee) {
const open = XMLHttpRequest.prototype.open;
const send = XMLHttpRequest.prototype.send;
const isRegularXHR = open.toString().indexOf('native code') !== -1;
// don't hijack if already hijacked - this will mess up with frameworks like Angular with zones
// we work if we load first there which we can.
if (isRegularXHR) {
@lushijie
lushijie / node-or-browser.js
Created December 6, 2018 11:21 — forked from rhysburnie/node-or-browser.js
Detect node or browser
// determine if in-browser or using node.js
// thruthy
var _nodejs = (
typeof process !== 'undefined' && process.versions && process.versions.node);
if (_nodejs) {
_nodejs = {
version: process.versions.node
};
}
@lushijie
lushijie / dom-to-json.js
Created May 6, 2018 02:41 — forked from sstur/dom-to-json.js
Stringify DOM nodes using JSON (and revive again)
function toJSON(node) {
node = node || this;
var obj = {
nodeType: node.nodeType
};
if (node.tagName) {
obj.tagName = node.tagName.toLowerCase();
} else
if (node.nodeName) {
obj.nodeName = node.nodeName;