Skip to content

Instantly share code, notes, and snippets.

@moekhalil
moekhalil / getSiteVars.js
Created February 25, 2019 10:48
Extract a websites custom global variables. Very not-tested.
const getSiteVars = () => {
const blankWindow = window.open('about:blank');
const defaultKeys = Object.keys(blankWindow);
blankWindow.close();
return Object
.keys(window)
.reduce((all, key) =>
blankWindow.hasOwnProperty(key) ? all : { ...all, [key]: window[key]}
, {}
);
@moekhalil
moekhalil / Craigslist-ImageDownloader.js
Created February 17, 2020 09:49
Craigslist-ImageDownloader.js
const list = document.createElement("ul");
const filenamePre = document.title.split("-")[0].replace(/ /g, ".");
imgList.forEach((i, k) => fetch(i.url).then(x => x.blob()).then(imgBlob => {
const url = URL.createObjectURL(imgBlob);
const imgNum = k + 1;
const item = document.createElement("li");
const ele = document.createElement("a");
ele.innerHTML = `Image ${imgNum} - Download<br />`;
// Direcory Listing Downloader - "Index Of/" Downloader
// Moe Khalil - me@mkhalil.org
// This is to download files located in directories with directory list permissions enabled
// set MINIMUM_SIZE to filter smaller files.
// File names will be what they are on server with date prepended and host domain appended.
(() => {
// minimum file-size to download
const MINIMUM_SIZE = '800K';
@moekhalil
moekhalil / folderFileCounter.sh
Created August 14, 2022 12:07
Nested Folder File Counter
#!/bin/sh
# Usually sitting in my .bash_alias file
folderFileCounter() {
echo -e Directory: .\\\nFiles: `(/usr/bin/find . -maxdepth 1 -type f) | wc -l`
/usr/bin/find . -mindepth 1 -maxdepth 1 -type d -exec sh -c "echo Directory: {}\\\nFiles: \`/usr/bin/find {} -type f | wc -l\`\\\n" \;
}
@moekhalil
moekhalil / getAllPermissions.js
Last active September 6, 2022 12:09
Get list of all browser permissions.
const getAvailablePermissions = async () => {
const allFeatures = document.featurePolicy
.features()
.sort()
.map((i) => ({ name: i }));
const availablePermissions = [];
const nonPermissionFeatures = [];
for (let index = 0; index < allFeatures.length; index++) {
const feature = allFeatures[index];
@moekhalil
moekhalil / downloadURLAsFilename.js
Last active September 6, 2022 12:13
Save any file at a url with a provided filename
// Created By : moe | mail is 𝚐𝚑𝚞𝚋-𝚊𝚝-𝚖𝚔𝚑𝚊𝚕𝚒𝚕.𝚘𝚛𝚐
// Uploaded To : https://gist.github.com/moekhalil
// Uploaded Date: 09/06/2022
// Notes : Save any file at a url with a provided filename.
// : Unlike download attribute, this even works with cross-origin urls
const downloadURLAsFilename = async ({ url, fileName }) => {
const mediaItem = await fetch(url);
const mediaBlob = await mediaItem.blob();
@moekhalil
moekhalil / Array.prototype.mapKey.js
Last active June 21, 2023 16:11
Just playing with how a native Array.prototype.mapKey would look.
/**
*
* @name: Array.prototype.mapKey
* @author: @moekhalil (GitHub)
*
* @description: A prototype of a native Array.prototype.mapKey that
* would allow users to map over an array of objects
* and return the value of a specific key or nested key
*
* @param prop {string | string[] | function}