Last active
March 18, 2022 19:24
-
-
Save AdriDevelopsThings/ce3d713a3bcc53c018d958a6c05fa188 to your computer and use it in GitHub Desktop.
A userscript that blocks every twitter users with a nft profile picture. (very useful)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Block NFT twitter users | |
// @namespace https://twitter.com | |
// @version 0.1 | |
// @description When a nft user is shown to you the userscript blocks them. | |
// @author AdriDevelopsThings | |
// @match https://twitter.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
// @grant none | |
// @updateURL https://gist.githubusercontent.com/AdriDevelopsThings/ce3d713a3bcc53c018d958a6c05fa188/raw/2ddd21d27abc717e6ee2fa7302f62c6d50d3a1c6/block_nft_twitter_users.js | |
// @require https://cdn.jsdelivr.net/npm/axios@0.25.0/dist/axios.min.js | |
// @require https://cdn.jsdelivr.net/npm/qs@6.10.3/dist/qs.min.js | |
// @require https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js | |
// ==/UserScript== | |
const alreadyBlocked = [] | |
const ignoredUsers = [] | |
function getCookie (name) { | |
const cookies = document.cookie.split('; ') | |
for (const cookie of cookies) { | |
const [key, value] = cookie.split('=') | |
if (key == name) | |
return value | |
} | |
return '' | |
} | |
function blockUser (ajax, userName) { | |
ajax.post('/1.1/blocks/create.json', Qs.stringify({ | |
screen_name: userName | |
}), {headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
}}) | |
console.log(`Blocked twitter user ${userName} because he uses a nft profile picture.`) | |
} | |
function ready () { | |
const elements = document.getElementsByClassName("css-4rbku5 css-18t94o4 css-1dbjc4n r-1niwhzg r-1loqt21 r-1pi2tsx r-1ny4l3l r-o7ynqc r-6416eg r-13qz1uu") | |
const ajax = axios.create({ | |
baseURL: 'https://api.twitter.com', | |
withCredentials: true, | |
headers: { | |
// I know it's look like I published my own authorization token but I didn't. It looks like twitter uses this one for everybody or something else. I don't get it. | |
'Authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA', | |
'X-Twitter-Auth-Type': 'OAuth2Session', | |
'X-Twitter-Active-User': 'yes', | |
'X-Csrf-Token': getCookie('ct0') | |
} | |
}) | |
for (const element of elements) { | |
const role = element.attributes && element.attributes.getNamedItem('href') !== null ? element.attributes.getNamedItem('role') : null | |
if (role && role.value == 'link') { | |
const href = element.href.split('/') | |
if (href[href.length - 1] == 'nft') { | |
const user = href[href.length - 2] | |
if (!alreadyBlocked.includes(user) && !ignoredUsers.includes(user)) { | |
blockUser(ajax, user) | |
alreadyBlocked.push(user) | |
} | |
} | |
} | |
} | |
} | |
(function() { | |
'use strict'; | |
$(document).ready(() => { | |
setInterval(ready, 1000) | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment