Last active
November 16, 2023 00:42
-
-
Save varenc/7c0c17eea480a03d7c8844d81e608e1e to your computer and use it in GitHub Desktop.
uBlock origin custom scripts
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
/// allow-but-log-webassembly.js | |
(function() { | |
var OriginalWebAssembly = WebAssembly; | |
var counter = 0; | |
var logMessage = function(message) { | |
if (counter < 10) { | |
console.log(`CV SAYS: ${message}`); | |
} else if (counter === 10) { | |
console.log('CV SAYS: WebAssembly log messages now suppressed'); | |
counter++; | |
} | |
counter++; | |
}; | |
WebAssembly = new Proxy(OriginalWebAssembly, { | |
construct: function(target, args) { | |
logMessage('WebAssembly instantiated'); | |
return new target(...args); | |
}, | |
apply: function(target, thisArg, args) { | |
logMessage('WebAssembly invoked'); | |
return target.apply(thisArg, args); | |
} | |
}); | |
Object.keys(OriginalWebAssembly).forEach(key => { | |
if (typeof OriginalWebAssembly[key] === 'function') { | |
WebAssembly[key] = function() { | |
logMessage(`WebAssembly method ${key} invoked`); | |
return OriginalWebAssembly[key].apply(this, arguments); | |
}; | |
} else { | |
WebAssembly[key] = OriginalWebAssembly[key]; | |
} | |
}); | |
logMessage('WebAssembly logging wrapper installed'); | |
})(); | |
/// disable-webassembly.js | |
(function() { | |
delete WebAssembly; | |
console.log('CV SAYS: WebAssembly deleted') | |
})(); | |
/// disable-websocket.js | |
(function() { | |
function getContextInfo() { | |
if (typeof window !== 'undefined') return window.location.href; | |
if (typeof self !== 'undefined' && typeof self.location !== 'undefined') return self.location.href; | |
if (typeof global !== 'undefined' && typeof global.process !== 'undefined') return `Node.js - ${global.process.title}`; | |
return 'Unknown context'; | |
} | |
function deleteSubframeWebSockets() { | |
let frames = document.querySelectorAll('iframe, frame'); | |
frames.forEach(frame => { | |
// try { | |
delete frame.contentWindow.WebSocket; | |
console.log('CV SAYS: WebSocket deleted from subframe:', frame); | |
// } catch (e) { | |
// console.error('An error occurred when deleting WebSocket: ', e); | |
// } | |
}); | |
} | |
setTimeout(deleteSubframeWebSockets,1500); | |
delete WebSocket; | |
console.log('CV SAYS: WebSocket deleted from:',getContextInfo()) | |
})(); | |
/// hn-favicons.js | |
(function() { | |
console.log('CV SAYS: hn-favicon active') | |
for(let link of document.querySelectorAll('.titlelink')) { | |
const domain = new URL(link.href).hostname | |
const imageUrl = `https://icons.duckduckgo.com/ip3/${domain}.ico` | |
const image = document.createElement('img') | |
image.src = imageUrl | |
image.width = 16 | |
image.height = 16 | |
image.style.paddingRight = '0.25em' | |
image.style.paddingLeft = '0.25em' | |
link.prepend(image) | |
} | |
})(); | |
/// disable-sendBeacon.js | |
(function() { | |
window.__sendBeacon_count=0; | |
navigator.sendBeacon=function(url,data) { | |
console.debug("blocked sendBeacon of " + (data ? data.length : "None") + " chars (" + window.__sendBeacon_count++ + "): ", url,data); | |
// console.count("sendBeacon"); | |
console.groupCollapsed("sendBeacon details"); | |
try { | |
console.debug("parsed data:",JSON.parse(data)) | |
} catch(e) { | |
try { | |
for (const entry of data.entries()) { | |
console.debug("FormData entry\t" + entry[0] + ' = ' + entry[1]); | |
} | |
} catch (e) { | |
console.debug("unparsed:",data) | |
} | |
}; | |
console.trace(); | |
console.groupEnd("sendBeacon details"); | |
return true | |
} | |
})(); | |
/// disable-keyboard.js | |
(function() { | |
(function() { | |
console.log('CV SAYS: disabling these listeners:',arguments) | |
// for each argument passed in, create a listener that does nothing | |
for (var i = 0; i < arguments.length; i++) { | |
document.addEventListener(arguments[i], function (e) { | |
e.stopPropagation(); | |
console.log("event recieved and unblocked:", e); | |
}, true); | |
} | |
})('keydown', 'keyup', 'keypress') | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment