Skip to content

Instantly share code, notes, and snippets.

@Merlin04
Last active January 10, 2024 03:08
Show Gist options
  • Save Merlin04/1b70e1bf1152cb9b635823726d721417 to your computer and use it in GitHub Desktop.
Save Merlin04/1b70e1bf1152cb9b635823726d721417 to your computer and use it in GitHub Desktop.
does this mastodon instance block people i follow? the script

how do i use it

add the bookmarklet as a bookmark in your browser - just copy the entire text of the thing labeled "bookmarklet" and paste that into the url field.

then, go to your instance's settings page and export the CSV of the accounts you follow

then go to the other instance's about page, expand the "moderated servers" list, then run the bookmarklet. choose the CSV you downloaded before, then allow the popup if your popup blocker blocked it.

javascript:void%20function()%7Bconst%20e%3Ddocument.createElement(%22input%22)%3Be.type%3D%22file%22%2Ce.onchange%3De%3D%3E%7Bconst%20t%3De.target.files%5B0%5D%2Co%3Dnew%20FileReader%3Bo.readAsText(t)%2Co.onload%3De%3D%3E%7Bconst%20t%3De.target.result.split(%22%5Cn%22)%2Co%3D%7B%7D%3Bfor(let%20e%3D1%3Be%3Ct.length%3Be%2B%2B)%7Bconst%20n%3Dt%5Be%5D.split(%22%2C%22)%5B0%5D%2Cc%3Dn.split(%22%40%22)%5B1%5D%3Bo%5Bc%5D%7C%7C(o%5Bc%5D%3D%5B%5D)%2Co%5Bc%5D.push(n)%7Dconst%20n%3D%5B%5D%3Bdocument.querySelectorAll(%22.about__domain-blocks__domain%22).forEach(e%3D%3E%7Blet%20t%3De.querySelector(%22h6%20span%22).textContent%2Co%3D%22%5E%22%2Bt.replace(%2F%5C.%2Fg%2C%22%5C%5C.%22).replace(%2F%5C*%2Fg%2C%22.%22)%3Bconst%20c%3De.querySelector(%22.about__domain-blocks__domain__type%22).textContent%3Bn.push(%7Bdomain%3At%2Cblock_type%3Ac%2Cregex%3Anew%20RegExp(o%2C%22g%22)%7D)%7D)%3Bconst%20c%3D%5B%5D%3Bn.forEach((%7Bdomain%3Ae%2Cblock_type%3At%2Cregex%3An%7D)%3D%3E%7Bconst%20l%3DObject.entries(o).find(e%3D%3En.exec(e%5B0%5D))%3Bl%26%26c.push(%7Bdomain%3Al%5B0%5D%2Ccensored%3Ae%2Cblock_type%3At%2Cemails%3Al%5B1%5D%7D)%7D)%3Blet%20l%3D'%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3Cmeta%20charSet%3D%22utf-8%22%3E%3C%2Fhead%3E%3Cbody%3E%3Cstyle%3E.i-report%20%7B%20background-color%3A%20white%3B%20color%3A%20black%3B%20position%3A%20fixed%3B%20z-index%3A%20999999%3B%7D%3C%2Fstyle%3E%3Cdiv%20class%3D%22i-report%22%3E'%3Bc.forEach(e%3D%3E%7Bl%2B%3D%60%5Cn%20%20%20%20%20%20%3Cdiv%3E%5Cn%20%20%20%20%20%20%20%20%3Ch3%3E%24%7Be.block_type%7D%20Domain%3A%20%24%7Be.domain%7D%24%7Be.censored!%3D%3De.domain%3F%60%20(matched%20with%20%24%7Be.censored%7D)%60%3A%22%22%7D%3C%2Fh3%3E%5Cn%20%20%20%20%20%20%20%20%3Cul%3E%5Cn%20%20%20%20%60%2Ce.emails.forEach(e%3D%3E%7Bl%2B%3D%60%3Cli%3E%24%7Be%7D%3C%2Fli%3E%60%7D)%2Cl%2B%3D%22%5Cn%20%20%20%20%20%20%20%20%3C%2Ful%3E%5Cn%20%20%20%20%20%20%3C%2Fdiv%3E%5Cn%20%20%20%20%22%7D)%2Cl%2B%3D%22%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%22%3Bconst%20i%3DURL.createObjectURL(new%20Blob(%5Bl%5D%2C%7Btype%3A%22text%2Fhtml%22%7D))%3Bwindow.open(i%2C%22win%22%2C%22width%3D400%2Cheight%3D800%2CscreenX%3D200%2CscreenY%3D200%22)%7D%7D%2Cdocument.body.appendChild(e)%2Ce.click()%7D()
(function() {
const input = document.createElement('input');
input.type = 'file';
input.onchange = e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsText(file);
reader.onload = e => {
const rows = e.target.result.split('\n');
const domains = {};
for (let i = 1; i < rows.length; i++) {
const row = rows[i].split(',');
const email = row[0];
const domain = email.split('@')[1];
if (!domains[domain]) {
domains[domain] = [];
}
domains[domain].push(email);
}
const blockedDomains = [];
document.querySelectorAll('.about__domain-blocks__domain').forEach(el => {
let domain = el.querySelector('h6 span').textContent;
// Replace asterisks with . to match censored domains
let regexStr = "^" + domain.replace(/\./g, '\\.').replace(/\*/g, '.');
const type = el.querySelector('.about__domain-blocks__domain__type').textContent;
blockedDomains.push({
domain,
block_type: type,
regex: new RegExp(regexStr, "g")
});
});
const intersections = [];
blockedDomains.forEach(({
domain,
block_type,
regex
}) => {
const a = Object.entries(domains).find(d => regex.exec(d[0]));
if (a) {
intersections.push({
domain: a[0],
censored: domain,
block_type,
emails: a[1]
});
}
});
let report = '<!DOCTYPE html><html><head><meta charSet="utf-8"></head><body><style>.i-report { background-color: white; color: black; position: fixed; z-index: 999999;}</style><div class="i-report">';
intersections.forEach(int => {
report += `
<div>
<h3>${int.block_type} Domain: ${int.domain}${int.censored !== int.domain ? ` (matched with ${int.censored})` : ""}</h3>
<ul>
`;
int.emails.forEach(email => {
report += `<li>${email}</li>`;
});
report += `
</ul>
</div>
`;
});
report += '</div></body></html>';
const url = URL.createObjectURL(new Blob([report], {
type: "text/html"
}));
const win = window.open(url, "win", "width=400,height=800,screenX=200,screenY=200");
};
}
document.body.appendChild(input);
input.click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment