Created
July 31, 2023 11:31
-
-
Save spudtrooper/50ec26f98957adc36c19f833ee05edf6 to your computer and use it in GitHub Desktop.
Anonymously visit certain users' Instagram stories
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 Instagram story anonymous | |
// @namespace http://jeffpalm.com/ | |
// @version 0.1 | |
// @description Anonymously visit certain users' Instagram stories | |
// @author Jeff Palm | |
// @match https://www.instagram.com/* | |
// @grant none | |
// ==/UserScript== | |
/* | |
Instructions: | |
1. Copy a user id from here: https://commentpicker.com/instagram-user-id.php | |
2. Add it to `blockList` below | |
Caveats: | |
Doesn't work from the reel. So, you should mute any user to which you do this. | |
*/ | |
(function() { | |
'use strict'; | |
const blockList = [ | |
'26302987963', // stellabumbles | |
]; | |
// https://stackoverflow.com/questions/629671/how-can-i-intercept-xmlhttprequests-from-a-greasemonkey-script | |
function replaceXMLHttpRequest() { | |
XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open; | |
const myOpen = function(method, url, async, user, password) { | |
//do whatever mucking around you want here, e.g. | |
//changing the onload callback to your own version | |
// Store the url so we can use it in send | |
this.url = url; | |
this.realOpen (method, url, async, user, password); | |
} | |
XMLHttpRequest.prototype.open = myOpen; | |
XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send; | |
const mySend = function(body) { | |
const url = this.url; | |
// TODO: I don't think this matters... | |
const data = []; | |
const skipped = []; | |
if (url.match(/.*logging_client_events$/)) { | |
const p = new URLSearchParams(body); | |
const m = JSON.parse(p.get('message')); | |
const data = m.data.map(o => { | |
if (o.name === 'instagram_web_media_impressions') { | |
const user = (o.obj_id || '').replace(/\//g, ''); | |
if (blockList.includes(user)) { | |
console.log("skip", o); | |
return; | |
} | |
} | |
return o; | |
}).filter(Boolean); | |
m.data = data; | |
p.set('message', JSON.stringify(m)); | |
body = p.toString(); | |
} | |
if (url.match(/.*graphql$/)) { | |
const p = new URLSearchParams(body); | |
const vars = JSON.parse(p.get('variables') || ''); | |
if (vars && vars.reelMediaOwnerId && blockList.includes(vars.reelMediaOwnerId)) { | |
console.log("block", vars); | |
p.set('variables', '{}'); | |
body = p.toString(); | |
} | |
} | |
this.realSend(body); | |
}; | |
XMLHttpRequest.prototype.send = mySend ; | |
} | |
function main() { | |
replaceXMLHttpRequest(); | |
} | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment