Last active
March 12, 2025 01:34
-
-
Save varenc/20e4dbfe8e7a2cc305043ffcbc5454d0 to your computer and use it in GitHub Desktop.
Unbreak Snapchat web. Disable focus tracking and screenshot prevention
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 Unbreak Snapchat web. Disable focus tracking and screenshot prevention | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.1 | |
// @description This userscript improves the Snapchat web experience by disabling screenshot prevention features which don't prevent screenshots but do actively harm the usability. | |
// @homepage https://gist.github.com/varenc/20e4dbfe8e7a2cc305043ffcbc5454d0 | |
// @author https://github.com/varenc | |
// @match https://web.snapchat.com/* | |
// @icon http://snapchat.com/favicon.ico | |
// @license MIT | |
// @run-at document-idle | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function __unblockControlKeyEvents() { | |
const events = ["keydown", "keyup", "keypress"]; | |
const modifyKeys = ["Control", "Meta", "Alt","Shift"]; | |
for (var i = 0; i < events.length; i++) { | |
var event_type = events[i]; | |
document.addEventListener( | |
event_type, | |
function (e) { | |
// console.log(`${event_type}[${i}]=`, e.key); | |
if (modifyKeys.includes(e.key)) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
console.log(`'${event_type}' event for '${e.key}' received and prevented:`, e); | |
e.stopImmediatePropagation(); | |
} | |
}, | |
true | |
); | |
} | |
} | |
function __unblockEvent() { | |
for (var i = 0; i < arguments.length; i++) { | |
var event_type = arguments[i]; | |
document.addEventListener( | |
arguments[i], | |
function (e) { | |
// e.preventDefault(); | |
e.stopPropagation(); | |
console.log(`'${event_type}' event received and prevented:`, e); | |
// e.stopImmediatePropagation(); | |
}, | |
true | |
); | |
} | |
} | |
function __fixConsole() { | |
// snapchat tries to disable console.log.. how mean. So we copy the real Console object from a new iframe | |
const iframe = document.createElement("iframe"); | |
iframe.style.display = "none"; | |
document.body.appendChild(iframe); | |
const nativeConsole = iframe.contentWindow.console; | |
window.console=nativeConsole; | |
} | |
function __setupUnblocker() { | |
__fixConsole(); | |
__unblockControlKeyEvents(); | |
///////// NOTE ///////// | |
// The below makes right-click work like normal, but it also disables Snapchat's special right click behavior in certain places. | |
__unblockEvent("contextmenu") | |
} | |
console.dir("Snapchat unbreaker running!") // Snapchat doesn't disable `console.dir`... silly Snapchat. | |
__setupUnblocker(); | |
// Run a few extra times to ensure our event listeners take priority. | |
setTimeout(__setupUnblocker, 1000); | |
setTimeout(__setupUnblocker, 5000); | |
setTimeout(__setupUnblocker, 10000); | |
// Works 90% of the time, but they also use some other method to check focus I haven't tracked down yet. | |
document.hasFocus = function(){return true} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment