Skip to content

Instantly share code, notes, and snippets.

@matthewpenkala
matthewpenkala / Paste Clipboard as Keystrokes.scpt
Created February 16, 2024 09:21
Simulate individual keystrokes from the clipboard's contents using AppleScript. Comprehensively iterate through all characters, handling numbers & special characters (e.g., `.`), with pauses to mimic human typing. Ideal for environments where direct paste is otherwise unavailable.
on run {input, parameters}
-- Setup: Delay before initiating the sequence of key presses.
tell application "System Events"
delay 1 -- Delay (in seconds) allows for any preparations before the script runs.
-- Iterates over each character in the clipboard's content.
repeat with char in (the clipboard)
set cID to id of char -- Retrieves the ASCII value of the character for conditional handling.
-- Checks if the character is a number (0-9) and maps it to the corresponding key code.
@matthewpenkala
matthewpenkala / getScriptVanilla.js
Last active February 3, 2024 09:29 — forked from kmonsoor/getScript.js
jQuery $.getScript() replacement via 100% vanilla JavaScript
// Vanilla JavaScript function for dynamic script loading with improved caching and optional callback
const getScriptVanilla = async (source, callback) => {
try {
const response = await fetch(source, {
method: 'GET',
headers: {
'Accept': '*/*',
'Sec-Fetch-Dest': 'script'
},
cache: 'force-cache' // Utilizes cache aggressively, falling back to network if unavailable
@matthewpenkala
matthewpenkala / browser_detect.js
Created December 27, 2023 00:29 — forked from dks50217/browser_detect.js
JavaScript: Detect Browser
// browser detect
var BrowserDetect = {
init: function(userAgent, appVersion) {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(userAgent) || this.searchVersion(appVersion) || "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function(data) {
for (var i = 0; i < data.length; i++) {
var dataString = data[i].string;
@matthewpenkala
matthewpenkala / OldBrowser.js
Last active November 20, 2023 09:26 — forked from gerbenvandijk/OldBrowser.js
Detect if the user has an old browser and if so, it inserts a friendly notification that not all features on the site will work, and that an upgrade is recommended.
// The code - first bit is all the UserAgent library.
(function(wndw) {
var Browsers, OS, Platform, Versions, browser_name, browser_version, os, platform;
Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i
@matthewpenkala
matthewpenkala / reducedMotion.js
Created September 30, 2023 14:58
Reduced Motion (Webflow-Specific JS)
// Cancel Webflow animations for users who prefer reduced motion
if (window.matchMedia("(prefers-reduced-motion)").matches) {
const cancelAnimationsInterval = setInterval(function() {
if (typeof Webflow == "undefined" || typeof Webflow.require == "undefined") {
return;
}
clearInterval(cancelAnimationsInterval);
// Get the interactions data from Webflow's state
@matthewpenkala
matthewpenkala / calculateZIndex.js
Last active September 28, 2023 11:09
This calculates the z-index of a given HTML element by traversing its parents and checking the computed z-index values. The function ensures an accurate determination of the z-index even if the z-index value is specified using different units or if it's inherited from parent elements.
/**
* @author Matthew Penkala <hello@matthewpenkala.com>
* @website https://matthewpenkala.com/
* @version 1.0.0
* @description This JavaScript file contains a function named `calculateZIndex`
* which, quite evidently, calculates the z-index (CSS) of a given
* HTML element by traversing its parents and checking the computed
* z-index values. The function ensures an accurate determination of
* the z-index even if the z-index value is specified using different
* units or if it's inherited from parent elements.*/
@matthewpenkala
matthewpenkala / jquery.isOver.js
Created July 26, 2023 14:17 — forked from UziTech/jquery.isOver.js
jQuery plugin to check if a point on the page is within an element.
/*
* DWTFYW License
*
* Author: Tony Brix, http://tonybrix.info
*
* Check if a point is within an element.
* Useful for mouseover on absolutely positioned overlapping elements.
*
* Example:
* $(document).mousemove(function(e){
@matthewpenkala
matthewpenkala / reenable-right-click.js
Created March 6, 2023 08:44 — forked from ahmadmysra/reenable-right-click.js
re-enable right click (bookmarklet)
javascript:(function(w){
var arr = ['contextmenu','copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'];
for(var i = 0, x; x = arr[i]; i++){
if(w['on' + x])w['on' + x] = null;
w.addEventListener(x, function(e){e.stopPropagation()}, true);
};
for(var j = 0, f; f = w.frames[j]; j++){try{arguments.callee(f)}catch(e){}}})(window);
// Vanilla JavaScript - trim Leading and Trailing - ES5
function TrimVanilla(str) {
return str.trim();
}
// Older browsers - IE8 and before - using Polyfill. Call trim() method after running this.
function TrimPolyfill() {
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
@matthewpenkala
matthewpenkala / svg2icns.sh
Last active January 20, 2023 10:05 — forked from jesusmaloQ/svg2icns.sh
Convert SVG file to macOS icon (icns) format
#!/bin/sh -x
set -e
SIZES="
16,16x16
32,32x32
64,64x64
128,128x128
256,256x256