Skip to content

Instantly share code, notes, and snippets.

@mdashlw
Created January 1, 2025 13:49
Show Gist options
  • Select an option

  • Save mdashlw/4c48ae26aeef1661b149f064cc69a05b to your computer and use it in GitHub Desktop.

Select an option

Save mdashlw/4c48ae26aeef1661b149f064cc69a05b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tumblr No Reblogs
// @match https://*.tumblr.com/*
// @version 1.0
// @author mdashlw
// @run-at document-start
// @inject-into page
// ==/UserScript==
const _fetch = unsafeWindow.fetch;
function patchResponse(response, patcher) {
const _json = response.json;
response.json = async function () {
const json = await _json.call(this);
patcher(json);
return json;
};
return response;
}
unsafeWindow.fetch = function () {
const url = arguments[0];
if (typeof url === "string") {
if (url.includes("/posts?fields") && url.includes("&context=archive")) {
return _fetch.apply(this, arguments).then((response) =>
patchResponse(response, (json) => {
const posts =
json.response.posts?.filter((post) => !post.rebloggedRootId) ?? [];
if (!posts.length && json.response.posts?.length) {
posts.push(json.response.posts[0]);
}
json.response.posts = posts;
}),
);
}
}
return _fetch.apply(this, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment