Skip to content

Instantly share code, notes, and snippets.

@varenc
Last active December 2, 2023 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varenc/20e4dbfe8e7a2cc305043ffcbc5454d0 to your computer and use it in GitHub Desktop.
Save varenc/20e4dbfe8e7a2cc305043ffcbc5454d0 to your computer and use it in GitHub Desktop.
Unbreak Snapchat web. Disable focus tracking and screenshot prevention
// ==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