Skip to content

Instantly share code, notes, and snippets.

@Krazete
Last active November 30, 2024 19:24
Show Gist options
  • Save Krazete/0fcfe6eeea57961df821f30c512cf2b2 to your computer and use it in GitHub Desktop.
Save Krazete/0fcfe6eeea57961df821f30c512cf2b2 to your computer and use it in GitHub Desktop.
Injects cognition.kizunaai.com with Bad Apple.
javascript:
/* https://cognition.kizunaai.com */
var video = document.createElement("video");
video.crossOrigin = "anonymous";
video.src = "https://raw.githubusercontent.com/NPCat/bad-apple-bot/main/bad_apple.mp4";
video.play();
var vw = 960;
var vh = 720;
var dpr = Math.ceil(window.devicePixelRatio || 1); /* for high dpi screens */
var canvas = Array.from(document.getElementsByTagName("canvas")).filter(e => e.getBoundingClientRect().width)[0];
var context = canvas.getContext("2d", {willReadFrequently: true});
var cw, ch, ix, iy, r;
var vcanvas = document.createElement("canvas");
var vcontext = vcanvas.getContext("2d");
var vcw, vch;
function getRectInfo() {
var cd = context.getImageData(0, 0, cw, ch);
var x1count = 0;
var x0count = 0;
for (var x = 0; x < cd.width; x++) {
var i = 4 * x;
if (cd.data[i] || cd.data[i + 1] || cd.data[i + 2]) {
if (x0count) {
break;
}
x1count++;
}
else {
x0count++;
}
}
var y1count = 0;
var y0count = 0;
for (var y = 0; y < cd.height; y++) {
var i = 4 * cd.width * y;
if (cd.data[i] || cd.data[i + 1] || cd.data[i + 2]) {
if (y0count) {
break;
}
y1count++;
}
else {
y0count++;
}
}
return { /* because the rectangles disappeared (2024-11-30) */
w: Math.min(x1count, 10) / dpr,
h: Math.min(y1count, 20) / dpr,
dx: Math.min(x1count + x0count, 12) / dpr,
dy: Math.min(y1count + y0count, 22) / dpr
};
}
function recalculate() {
cw = canvas.width / dpr;
ch = canvas.height / dpr;
/* scale video resolution to fit canvas */
var iw, ih;
if (vw / vh < cw / ch) {
iw = vw * ch / vh;
ih = ch;
}
else {
iw = cw;
ih = vh * cw / vw;
}
ix = (cw - iw) / 2;
iy = (ch - ih) / 2;
/* get rect info */
r = getRectInfo();
/* prepare video pixelation and adjust iw, ih, ix, iy with rect info */
vcw = Math.ceil(iw / r.dx);
vch = Math.ceil(ih / r.dy);
vcanvas.width = vcw;
vcanvas.height = vch;
ix = Math.floor(ix / r.dx) * r.dx;
iy = Math.floor(iy / r.dy) * r.dy;
}
/* colors
black #000000
white #ffffff
gray #0a0a0a
pink #eb50ae
blue #0000ff
*/
function play() {
vcontext.drawImage(video, 0, 0, vcw, vch);
var vcd = vcontext.getImageData(0, 0, vcw, vch);
context.beginPath();
for (var y = 0; y < vcd.height; y++) {
for (var x = 0; x < vcd.width; x++) {
var i = 4 * (vcd.width * y + x);
var j = (vcd.data[i] + vcd.data[i + 1] + vcd.data[i + 2]) / 3;
if (j < 120) {
context.fillStyle = "#0a0a0a";
}
else if (j < 128) {
context.fillStyle = "#0000ff";
}
else if (j < 192) {
context.fillStyle = "#eb50ae";
}
else {
context.fillStyle = "#ffffff";
}
context.fillRect(ix + x * r.dx, iy + y * r.dy, r.w, r.h);
}
}
if (!video.paused) {
requestAnimationFrame(play);
}
};
recalculate();
play();
window.addEventListener("resize", recalculate);
@Krazete
Copy link
Author

Krazete commented Jul 4, 2024

@Krazete
Copy link
Author

Krazete commented Jul 4, 2024

Alternative Video #1: Doom

  1. Set video.src to: https://raw.githubusercontent.com/filestack/filestack-ruby/develop/test-files/doom.mp4
  2. Set colors conditions in play() to:
    if (j >= 96) {context.fillStyle = "#ffffff";}
    else if (vcd.data[i] >= 80) {context.fillStyle = "#eb50ae";}
    else if (vcd.data[i + 2] >= 64) {context.fillStyle = "#0000ff";}
    else {context.fillStyle = "#0a0a0a";}

Preview: https://youtu.be/pLMNcYntmY4

@Krazete
Copy link
Author

Krazete commented Jul 4, 2024

Alternative Video #2: Lagtrain

  1. Set video.src to: https://raw.githubusercontent.com/Krazete/blah/master/lagtrain.mp4
  2. Set colors conditions in play() to:
    if (j < 152) {context.fillStyle = "#ffffff";}
    else if (j < 160) {context.fillStyle = "#0000ff";}
    else if (j < 200) {context.fillStyle = "#0a0a0a";}
    else {context.fillStyle = "#eb50ae";}

Preview: https://youtu.be/Z23aoGg4m7k

@Krazete
Copy link
Author

Krazete commented Jul 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment