Skip to content

Instantly share code, notes, and snippets.

View johan's full-sized avatar

Johan Sundström johan

View GitHub Profile
@johan
johan / srt.js
Created December 21, 2016 07:17
A little subtitle file tweaking class
class SRT {
constructor(s) { this.setSubs(typeof s === 'string' ? SRT.decode(s) : s); }
toString() { return SRT.encode(this.subs); }
timeShift(dt) {
return new SRT(this.subs.map(s => Object.assign({}, s, {t: s.t + dt})));
}
getSubs() { return this.subs.map(o => Object.assign({}, o)); }
setSubs(subs) { this.subs = subs; return this; }
@johan
johan / controlfreak.js
Last active December 16, 2016 03:22
Convenience lib for the chrome extension "Control Freak", a light-weight Greasemonkey.
const scrape = (scraper) => {
let spec = 'dom' in scraper ? scraper : { dom: scraper };
on(spec).then((scraped) => {
console.info('on.dom scraped:', {scraper, scraped});
exportToPage({scraper, scraped, on});
evalInPage('on');
});
};
const exportToPage = (obj) => {
@johan
johan / cancelAll.js
Created December 11, 2016 20:31
A browser functionality fill-in I ended up writing and sharing on http://stackoverflow.com/questions/3141064/how-to-stop-all-timeouts-and-intervals-using-javascript to batch cancel javascript's basic deferred execution functions.
(function(deferFunctions) {
for (var setter in deferFunctions) (function(setter, clearer) {
var ids = [];
var startFn = window[setter];
var clearFn = window[clearer];
function clear(id) {
var index = ids.indexOf(id);
if (index !== -1) ids.splice(index, 1);
return clearFn.apply(window, arguments);
@johan
johan / alert.js
Created November 22, 2016 06:46
Somewhat improved version of Fake News Alert extension 0.1.2 from https://chrome.google.com/webstore/detail/fake-news-alert/aickfmgnhocegpdbfnpfnedpeionfkbh/related – to mark links directly at Facebook before you even click through them.
// alert.js
const stripes = document.createElement('div');
stripes.style.cssText = `
height: 20px;
width: 100%;
position: fixed;
z-index: 99999;
opacity: 0.7;
pointer-events: none;
// ==UserScript==
// @name Clear Facebook Notifications Once
// @description If you have multiple Facebook tabs open
// @match https://*.facebook.com/*
// @namespace https://github.com/johan/
// ==/UserScript==
const onStorageChange, onNotificationClick;
window.addEventListener('storage', onStorageChange = (e) => {
@johan
johan / README.md
Last active October 5, 2016 02:13
A pleasant chime ring tone
@johan
johan / .block
Created July 20, 2016 11:52 — forked from mbostock/.block
Sleep Cycles
license: gpl-3.0
@johan
johan / README.md
Last active December 21, 2015 15:22
RFC 5545 compliant (US) Facebook holiday iCal calendar Raw

Facebook US' recognized holidays are:

  • New Year’s Day
  • Martin Luther King Day
  • Presidents Day
  • Memorial Day
  • Independence Day
  • Labor Day
  • Thanksgiving Day
  • day after Thanksgiving
@johan
johan / JSXTransformer.min.js
Last active August 8, 2023 22:57
Week Calendar of Life
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JSXTransformer=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){"use strict";var ReactTools=_dereq_("../main");var inlineSourceMap=_dereq_("./inline-source-map");var headEl;var dummyAnchor;var inlineScriptCount=0;var supportsAccessors=Obj
@johan
johan / index.html
Created October 2, 2015 03:51
iPhone 6S X-ray
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>iPhone 6S X-ray</title>
<style>
#xray {
top: -4px;
left: -5px;
position: absolute;
mouse-events: none;