Skip to content

Instantly share code, notes, and snippets.

View Explosion-Scratch's full-sized avatar

--Explosion-- Explosion-Scratch

View GitHub Profile
@Explosion-Scratch
Explosion-Scratch / function_log.js
Last active May 6, 2023 04:49
Function log prototype manipulation
Function.prototype.log = function () {
function annotate(func) {
return (func + "")
.replace(/[/][/].*$/gm, "")
.replace(/\s+/g, "")
.replace(/[/][*][^/*]*[*][/]/g, "")
.split("){", 1)[0]
.replace(/^[^(]*[(]/, "")
.replace(/=[^,]+/g, "")
.split(",")
@Explosion-Scratch
Explosion-Scratch / colors.css
Last active August 23, 2021 18:19
CSS colors as variables.
:root{
--aliceblue-50: #F8F8F9;
--aliceblue-100: #F2F2F2;
--aliceblue-200: #DDDEDF;
--aliceblue-300: #C9CBCC;
--aliceblue-400: #A1A3A6;
--aliceblue-500: #787C80;
--aliceblue-600: #6C7073;
--aliceblue-700: #484A4D;
--aliceblue-800: #36383A;
function url(u) {
const GITHUB_API_URL = "https://api.github.com";
const TEMPLATES = [
[
/^(https?):\/\/gitlab\.com\/([^\/]+.*\/[^\/]+)\/(?:raw|blob)\/(.+?)(?:\?.*)?$/i,
"$1://gl.githack.com/$2/raw/$3",
],
[
/^(https?):\/\/bitbucket\.org\/([^\/]+\/[^\/]+)\/(?:raw|src)\/(.+?)(?:\?.*)?$/i,
@Explosion-Scratch
Explosion-Scratch / _spotify-playlist-downloader.sh
Last active March 13, 2023 15:44
Download a playlist from spotify with metadata
#!/bin/bash
########################################################
# Get data from spotify api #
########################################################
sudo rm -rf _temp && mkdir _temp && cd _temp;
pwd && ls
@Explosion-Scratch
Explosion-Scratch / minified.js
Last active April 22, 2024 18:24
Upload an image to imgur with a bookmarklet
async function run(){var e;try{e=await(e=>new Promise((a,t)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=(()=>a(r.result)),r.onerror=(e=>t(e))}))(await async function(){return new Promise(e=>{var a=document.createElement("input");a.style.display="none",a.type="file",a.accept="image/*",document.body.appendChild(a),a.onchange=(t=>{e(a.files[0]),a.remove()}),a.click()})}())}catch(e){return alert("No file selected")}if(!e)return alert("No data generated");var a=await fetch("https://uploads.explosionscratc.repl.co/upload",{method:"POST",body:e}).then(e=>e.json());if(console.log(a),a.error)return alert(`There was an error: ${a.message}`);var t=document.createElement("textarea");document.body.appendChild(t),t.value=a.link,t.focus(),t.select(),document.execCommand("copy"),t.remove()}run();
@Explosion-Scratch
Explosion-Scratch / print.js
Created September 7, 2021 20:39
Print from GitHub markdown pages
javascript: {
var container =
document.querySelector("article") ||
document.querySelector("#readme .Box-body article") ||
document.querySelector("#readme") ||
document.querySelector(".page");
if (document.querySelector(".final-path")) {
var header = document.createElement("h1");
header.innerText = document.querySelector(".final-path").innerText;
@Explosion-Scratch
Explosion-Scratch / translate.js
Created September 11, 2021 02:30
Translate text using the google translate API
// const {translated} = await translate("bonjour");
// --> "Hello"
async function translate(text, target, source) {
var opts = {
text: text || "",
source: source || 'auto',
target: target || "en",
}
var result = await fetch(`https://translate.googleapis.com/translate_a/single?client=gtx&sl=${opts.source}&tl=${opts.target}&dt=t&q=${encodeURI(opts.text)}`).then(res => res.json());
return {
@Explosion-Scratch
Explosion-Scratch / google-answers.js
Last active May 6, 2023 04:48
Get a quick answer from google.
async function answer(q) {
var html = await fetch(
`https://cors.explosionscratc.repl.co/google.com/search?q=${encodeURI(q)}`,
{
headers: {
"User-Agent":
"Mozilla/5.0 (X11; CrOS x86_64 13982.88.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.162 Safari/537.36",
},
}
).then((res) => res.text());
@Explosion-Scratch
Explosion-Scratch / SvelteComponent.svelte
Last active May 6, 2023 04:48
Get metadata from a URL and parse it.
<script>
import {onMount} from "svelte";
export let link = "";
let m, title, description, img, img_el;
onMount(async () => {
m = await meta(link);
m = parseMeta(m);
title = m.title;
description = m.description;
img = m.image;
@Explosion-Scratch
Explosion-Scratch / htmltoimage.js
Created October 4, 2021 19:07
Converts a string of HTML to an image.
function htmlToImage(html, { x = 0, y = 0, width = 300, height = 400 }) {
let canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
return new Promise((res) => {
var xml = toXML(html);
xml = xml.replace(/\#/g, "%23");
var data = `data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"><foreignObject width="100%" height="100%">${xml}</foreignObject></svg>`;