Skip to content

Instantly share code, notes, and snippets.

@Raz-js
Last active August 14, 2023 18:53
Show Gist options
  • Save Raz-js/bf7da3bf76b8e13512f64ed8c79d1171 to your computer and use it in GitHub Desktop.
Save Raz-js/bf7da3bf76b8e13512f64ed8c79d1171 to your computer and use it in GitHub Desktop.
Basic Scripts to make your life easier

Fetch code from a source/cdn link

fetch("URL").then((res) => res.text().then((t) => eval(t)))

Timed Debugger

setTimeout(function(){debugger;},3000);

Wrong Website Error

//Output: { VM14:2 Uncaught Error: This ain't Github bro. \n at <anonymous>:2:11 }
if (window.location.href.search("github.com") == -1) {
    throw new Error("This ain't Github bro.");
}

Custom Errors

//window.my_log("txt")
window.trace = function stackTrace() {
    var err = new Error();
    return err.stack;
}

window.my_log = function (x) {
    var line = trace();
    var lines = line.split("\n");
    console.log(x + " " + lines[2].substring(lines[2].indexOf("("), lines[2].lastIndexOf(")") + 1))
}

Get Contents of Link

function get_information(link, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", link, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            callback(xhr.responseText);
        }
    };
    xhr.send(null);
}

Image in Console

//console.image("img-url")
(function(console) {
	"use strict";
	function getBox(width, height) {
		return {
			string: "+",
			style: "font-size: 1px; padding: " + Math.floor(height/2) + "px " + Math.floor(width/2) + "px; line-height: " + height + "px;"
		}
	}
	function drawMemeText(ctx, type, text, width, y) {
		text = text.toUpperCase();
		//Determine the font size
		if(text.length < 24) {
			var val = Math.max(0, text.length - 12),
				size = 70 + (val * - 3);

			drawText(ctx, size, text, width/2, y);
		} else if(text.length < 29) {
			drawText(ctx, 40, text, width/2, y);
		} else {
			var strs = wrap(text, 27);
			strs.forEach(function(str, i) {
				drawText(ctx, 40, str, width/2, (type == "lower") ? (y - ((strs.length - 1) * 40)) + (i * 40) : y + (i * 40));
			});
		}
	}
	function drawText(ctx, size, text, x, y) {
		//Set the text styles
		ctx.font = "bold " + size + "px Impact";
		ctx.fillStyle = "#fff";
		ctx.textAlign = "center";
		ctx.textBaseline = "middle";
		ctx.lineWidth = 7;
		ctx.strokeStyle = "#000";
		ctx.strokeText(text, x, y);
		ctx.fillText(text, x, y);
	}
	function wrap(text, num) {
		var output = [],
			split = text.split(" ");

		var str = [];
		for(var i = 0, cache = split.length; i < cache; i++) {
			if((str + split[i]).length < num) str.push(split[i])
			else {
				output.push(str.join(" "));
				str.length = 0;
				str.push(split[i]);
			}
		}

		//Push the final line
		output.push(str.join(" "));

		return output;
	}
	console.image = function(url, scale) {
		scale = scale || 1;
		var img = new Image();

		img.onload = function() {
			var dim = getBox(this.width * scale, this.height * scale);
			console.log("%c" + dim.string, dim.style + "background: no-repeat url(" + url + "); background-size: " + (this.width * scale) + "px " + (this.height * scale) + "px; color: transparent;");
		};

		img.src = url;
	};
})(console);

Delete Webhoook

let webhook = "URL";  

  await fetch(webhook, {
    "method": "DELETE",
  });

Post to Webhook

let webhook = "URL";

fetch(
    webhook,
    {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Accept": "application/json"
        },
        body: JSON.stringify({
            "embeds": [
                {
                    "title": "Title",
                    "description": "Desc",
                    "color": 16711680,
                    "footer": {
                        "text": "Input"
                    },
                    "fields": [
                        {
                            "name": "Field name",
                            "value": "field value",
                            "inline": true
                        },
                        {
                            "name": "Field name",
                            "value": "field value",
                            "inline": true
                        }
                    ]
                }
            ]
        })
    }
)

Colored Console Log

//colorLog(message, color)
function colorLog(message, color) {

    color = color || "black";

    switch (color) {
        case "success":  
             color = "Green"; 
             break;
        case "info":     
                color = "DodgerBlue";  
             break;
        case "error":   
             color = "Red";     
             break;
        case "warning":  
             color = "Orange";   
             break;
        default: 
             color = color;
    }

    console.log("%c" + message, "color:" + color);
}

Already Injected Script

if (window.Injected && !window.InjectedDebug) {
    throw new Error("Already ran script! Advanced: Set !Window.InjectedDebug to bypass this.");
}
window.Injected = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment