Skip to content

Instantly share code, notes, and snippets.

@ShabbirHasan1
Created May 11, 2022 15:40
Show Gist options
  • Select an option

  • Save ShabbirHasan1/382dcad0dff1a5d058c14b58b1fff106 to your computer and use it in GitHub Desktop.

Select an option

Save ShabbirHasan1/382dcad0dff1a5d058c14b58b1fff106 to your computer and use it in GitHub Desktop.
XMLHttpRequestを仲介するユーザースクリプト (Tampermonkey)
// ==UserScript==
// @name xhr-intercept
// @namespace https://github.com/BiasHacker
// @version 0.1
// @description XMLHttpRequestを仲介します。
// @author Sin
// @match https://hoge.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
window.nativeXHR = {
open: XMLHttpRequest.prototype.open,
send: XMLHttpRequest.prototype.send
};
var parseQueryString = function(value) {
return value.split('&').reduce(function(obj, text) {
var keyValue = text.split('=');
if (keyValue[0]) {
obj[keyValue[0]] = decodeURIComponent(keyValue[1] || '');
}
return obj;
}, {});
}, encodeQueryString = function(value) {
return Object.keys(value).map(function(key) {
return key + '=' + encodeURIComponent(value[key]);
}).join('&');
};
XMLHttpRequest.prototype.open = function() {
this.argsOpen = arguments;
window.nativeXHR.open.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function(payload) {
if (payload) console.log(this.argsOpen[1], parseQueryString(payload));
window.nativeXHR.send.apply(this, arguments);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment