whistle
Version:
HTTP, HTTP2, HTTPS, Websocket debugging proxy
249 lines (243 loc) • 8.47 kB
HTML
<style>html {background: #fff;}</style>
<script>
;(function() {
var config = window.whistleMenuConfig;
var list = [];
var networkListeners = [];
var rulesListeners = [];
var valuesListeners = [];
var pluginsListeners = [];
var handleOnLoad = function() {
timer = null;
list.forEach(emit);
list = null;
};
var timer = setTimeout(handleOnLoad, 12000);
function execListeners(listeners, options) {
listeners.forEach(function(fn) {
try {
fn(options)
} catch (e) {
console.error(e);
}
});
}
function emit(options) {
switch(options.type) {
case 'rules':
execListeners(rulesListeners, options);
break;
case 'values':
execListeners(valuesListeners, options);
break;
case 'plugins':
execListeners(pluginsListeners, options);
break;
default:
execListeners(networkListeners, options);
}
}
window.onWhistleContextMenuClick = function(options) {
if (list) {
list.push(options);
} else {
emit(options);
}
};
var delayOnLoad = function() {
if (timer) {
setTimeout(handleOnLoad, 100);
clearTimeout(timer);
timer = null;
}
};
window.onload = delayOnLoad;
try {
window.addEventListener('load', delayOnLoad);
} catch (e) {}
var toast = {};
var addNetworkListener = function(l) {
if (typeof l === 'function' && networkListeners.indexOf(l) === -1) {
networkListeners.push(l);
}
};
var removeNetworkListener = function(l) {
l = networkListeners.indexOf(l);
if (l !== -1) {
networkListeners.splice(l, 1);
}
};
var removeAllNetworkListeners = function() {
networkListeners = [];
};
var addRulesListener = function(l) {
if (typeof l === 'function' && rulesListeners.indexOf(l) === -1) {
rulesListeners.push(l);
}
};
var removeRulesListener = function(l) {
l = rulesListeners.indexOf(l);
if (l !== -1) {
rulesListeners.splice(l, 1);
}
};
var removeAllRulesListeners = function() {
rulesListeners = [];
};
var addValuesListener = function(l) {
if (typeof l === 'function' && valuesListeners.indexOf(l) === -1) {
valuesListeners.push(l);
}
};
var removeValuesListener = function(l) {
l = valuesListeners.indexOf(l);
if (l !== -1) {
valuesListeners.splice(l, 1);
}
};
var removeAllValuesListeners = function() {
valuesListeners = [];
};
var addPluginsListener = function(l) {
if (typeof l === 'function' && pluginsListeners.indexOf(l) === -1) {
pluginsListeners.push(l);
}
};
var removePluginsListener = function(l) {
l = pluginsListeners.indexOf(l);
if (l !== -1) {
pluginsListeners.splice(l, 1);
}
};
var removeAllPluginsListeners = function(l) {
pluginsListeners = [];
};
function on(type, l) {
if (typeof l !== 'function') {
return;
}
switch(type) {
case 'network':
return addNetworkListener(l);
case 'rules':
return addRulesListener(l);
case 'values':
return addValuesListener(l);
case 'plugins':
return addPluginsListener(l);
}
}
function off(type, l) {
switch(type) {
case 'network':
if (l) {
removeNetworkListener(l);
} else {
removeAllNetworkListeners();
}
return;
case 'rules':
if (l) {
removeRulesListener(l);
} else {
removeAllRulesListeners();
}
return;
case 'values':
if (l) {
removeValuesListener(l);
} else {
removeAllValuesListeners();
}
return;
case 'plugins':
if (l) {
removePluginsListener(l);
} else {
removeAllPluginsListeners();
}
return;
}
}
var whistleBridge = {
config: config,
toast: toast,
on: on,
off: off,
addNetworkListener: addNetworkListener,
removeNetworkListener: removeNetworkListener,
removeAllNetworkListeners: removeAllNetworkListeners,
addRulesListener: addRulesListener,
removeRulesListener: removeRulesListener,
removeAllRulesListeners: removeAllRulesListeners,
addValuesListener: addValuesListener,
removeValuesListener: removeValuesListener,
removeAllValuesListeners: removeAllValuesListeners,
addPluginsListener: addPluginsListener,
removePluginsListener: removePluginsListener,
removeAllPluginsListeners: removeAllPluginsListeners
};
try {
window.initWhistleBridge = function(options) {
window.initWhistleBridge = function() {};
Object.keys(options.msgBox).forEach(function(name) {
toast[name] = options.msgBox[name];
});
whistleBridge.getSelectedSessionList = options.getSelectedSessionList;
whistleBridge.getActiveSession = whistleBridge.getSession = whistleBridge.getSelectedSession = options.getActiveSession;
whistleBridge.showOption = options.showOption;
whistleBridge.hideOption = options.hideOption;
whistleBridge.updateUI = options.updateUI;
whistleBridge.copyText = options.copyText;
whistleBridge.pageId = options.pageId;
whistleBridge.compose = options.compose;
whistleBridge.composeInterrupt = options.createComposeInterrupt();
whistleBridge.getWhistleId = options.getWhistleId;
whistleBridge.hasWhistleToken = options.hasWhistleToken;
whistleBridge.decodeBase64 = options.decodeBase64;
whistleBridge.joinBase64 = options.joinBase64;
whistleBridge.getReqId = options.getReqId;
whistleBridge.onComposeData = options.onComposeData;
whistleBridge.offComposeData = options.offComposeData;
whistleBridge.importSessions = options.importSessions;
whistleBridge.exportSessions = options.exportSessions;
whistleBridge.importMockData = options.importMockData;
whistleBridge.download = options.download;
whistleBridge.setNetworkSettings = options.setNetworkSettings;
whistleBridge.setRulesSettings = options.setRulesSettings;
whistleBridge.setValuesSettings = options.setValuesSettings;
whistleBridge.setComposerData = options.setComposerData;
whistleBridge.showHttpsSettings = options.showHttpsSettings;
whistleBridge.showCustomCerts = options.showCustomCerts;
whistleBridge.uploadCustomCerts = options.uploadCustomCerts;
whistleBridge.showNetwork = options.showNetwork;
whistleBridge.showRules = options.showRules;
whistleBridge.showValues = options.showValues;
whistleBridge.showPlugins = options.showPlugins;
whistleBridge.showService = options.showService;
whistleBridge.hideService = options.hideService;
whistleBridge.getInstalledPlugins = options.getInstalledPlugins;
whistleBridge.showInstallPlugins = options.showInstallPlugins;
whistleBridge.showUpdatePlugins = options.showUpdatePlugins;
whistleBridge.readFileAsText = options.readFileAsText;
whistleBridge.readFileAsBase64 = options.readFileAsBase64;
whistleBridge.getVersion = options.getVersion;
whistleBridge.request = options.request;
whistleBridge.createRequest = options.createRequest;
whistleBridge.parseRules = options.parseRules;
whistleBridge.showModal = options.showModal;
whistleBridge.createModal = options.createModal;
whistleBridge.importRules = options.importRules;
whistleBridge.importValues = options.importValues;
whistleBridge.getServerInfo = options.getServerInfo;
whistleBridge.alert = options.alert;
whistleBridge.confirm = options.confirm;
whistleBridge.syncData = options.syncData;
whistleBridge.syncRules = options.syncRules;
whistleBridge.syncValues = options.syncValues;
};
window.parent.onPluginContextMenuReady(window);
} catch (e) {}
window.whistleBridge = whistleBridge;
})();
</script>