Skip to content

Instantly share code, notes, and snippets.

@ArcHound
Created March 1, 2025 19:20
Show Gist options
  • Save ArcHound/393560f671006c12f43ffba72abb8a29 to your computer and use it in GitHub Desktop.
Save ArcHound/393560f671006c12f43ffba72abb8a29 to your computer and use it in GitHub Desktop.
Fix Substack Gist embedding by pasting this into the console
// source: https://github.com/Maluen/code-medium/issues/11#issuecomment-2192400621
// I am taking it for archival and convenience - I've done no changes
var _open = XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function (method, URL) {
var _onreadystatechange = this.onreadystatechange,
_this = this;
_this.onreadystatechange = function () {
if (_this.readyState === 4 && _this.status === 200 && ~URL.indexOf('api/v1/github/gist')) {
try {
var data = JSON.parse(_this.responseText);
data.innerHTML = data.innerHTML.replace(/<template ([\s\S]*?)>([\s\S]+?)<\/template>/g, ' ');
// rewrite responseText
Object.defineProperty(_this, 'responseText', {
value: JSON.stringify(data),
configurable: true,
enumerable: true,
});
} catch (e) {}
}
// call original callback
if (_onreadystatechange) _onreadystatechange.apply(this, arguments);
};
// detect any onreadystatechange changing
Object.defineProperty(this, "onreadystatechange", {
get: function () {
return _onreadystatechange;
},
set: function (value) {
_onreadystatechange = value;
}
});
return _open.apply(_this, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment