Skip to content

Instantly share code, notes, and snippets.

Avatar

Federico Brigante fregante

View GitHub Profile
@fregante
fregante / devtools_page.html
Created Oct 22, 2022
Request permissions from devtool panel
View devtools_page.html
<!DOCTYPE html>
<meta charset="utf-8" />
<script src="devtools_page.js"></script>
View background.worker.js
// Respond to CS
const startTime = Date.now()
const delay = 13000;
chrome.runtime.onMessage.addListener( (message, sender, respond) => {
setTimeout(respond, delay, Math.round((Date.now() - startTime + delay) / 1000));
return true
})
// Overlapping fetch requests
console.log('will req');
View index.js
Promise.reject(1).catch(err => {
if (err instanceof Error) {
throw err; // Exception
}
// Rejection
}).catch(exitProcess)
View README.md

work-cli

Personal launcher to start working in whatever directory you're into. Customize it as needed

$ work
# tries launching GitHub.app
# tries launching Sublime Text
# tries launching the build tool (npm run watch, gulp, grump in this order)
@fregante
fregante / bookmarklet.js
Last active Jun 7, 2016
Play videos inline on the iPhone (bookmarklet)
View bookmarklet.js
// to be flattened with http://chriszarate.github.io/bookmarkleter/
var s = document.createElement('script');
s.onload = function () {
[].forEach.call(document.querySelectorAll('video'), makeVideoPlayableInline);
};
s.src='https://rawgit.com/bfred-it/ffd71c642d2fcf4649b230bd71bc9a93/raw/fb39a59c458aeb49d882d81c9d4be2b3ae0b3b93/enabler.js';
document.head.appendChild(s);
@fregante
fregante / show-reddit-posts.js
Last active Feb 25, 2016
Bookmarklet: show current url posted on Reddit
View show-reddit-posts.js
// Create bookmarklet with: https://ted.mielczarek.org/code/mozilla/bookmarklet.html
var getPermalink = post => 'https://www.reddit.com'+post.data.permalink;
var getPermalinks = r => r.data.children.map(getPermalink);
var buildLink = url => {
var a = document.createElement('a');
a.href = url;
a.textContent = url.match(/\/r\/[^/]+/) && url.match(/\/r\/[^/]+/)[0] || url;
a.style.display = 'block';
return a;
};
@fregante
fregante / header.js
Last active May 21, 2016 — forked from dominikwilkowski/00-README.md
Doc strange outline love (jQuery-free)
View header.js
//detecting tab key press
document.body.addEventListener('keydown', function detector (e) {
var keyCode = e.keyCode || e.which;
if(keyCode == 9) {
console.log( 'Tab detected' );
document.documentElement.className += ' is-keyboarduser';
document.body.removeEventListener('keydown', detector);
@fregante
fregante / moved.md
Last active Dec 26, 2016
If you preventDefault on clicks, wrap the handler with this