Skip to content

Instantly share code, notes, and snippets.

@rikuba
rikuba / EseSet.js
Last active December 19, 2015 03:59
似非Set
var EseSet = (function (constructor, properties) {
var hasOwnProperty = Object.prototype.hasOwnProperty,
defineProperty = Object.defineProperty || function (object, name, descriptor) {
object[name] = descriptor.value;
},
prototype = constructor.prototype,
name;
for (name in properties) if (hasOwnProperty.call(properties, name)) {
defineProperty(prototype, name, {
@rikuba
rikuba / checkAtIntervals.js
Created June 12, 2013 07:00
ref. 0-9.tumblr.com/post/52701096724/setinterval-check-code-format
function checkAtIntervals(interval, checkfn, callbackfn) {
function tick() {
if (!checkfn()) {
setTimeout(tick, interval);
return;
}
callbackfn();
}
tick();
}
@rikuba
rikuba / find_findIndex.js
Last active December 17, 2015 08:49
define Array.prototype.find and Array.prototype.findIndex
(function () {
function find(predicate/*, thisArg*/) {
if (typeof predicate !== 'function') {
throw new TypeError(predicate + ' is not a function');
}
var O = Object(this),
thisArg = arguments[1],
i = 0,
len = O.length >>> 0;
@rikuba
rikuba / defineArrayGenericMethods.js
Last active December 14, 2015 22:29
define generic methods
(function /*defineArrayGenericMethods*/(methods) {
var defineProperty = Object.defineProperty,
name;
if (defineProperty) {
for (name in methods) if (methods.hasOwnProperty(name)) {
if (!Array.hasOwnProperty(name)) {
defineProperty(Array, name, {
value: methods[name],
configurable: true,
@rikuba
rikuba / ltsv.js
Last active December 12, 2015 07:29
lazy
var LTSV = (function () {
return {
parse: parse,
stringify: stringify
};
function parse(text) {
return text.split(/\r?\n/).map(_parseRecord);
}
@rikuba
rikuba / buildContextMenu.js
Last active December 11, 2015 06:48
build contextmenu on Firefox
var buildContextMenu = (function () {
var lastContextMenuTarget;
function oncontextmenu(e) {
lastContextMenuTarget = e.target;
}
function onclick(e) {
e.trigger = lastContextMenuTarget;
this.oniteminvoked(e);
// ==UserScript==
// @id slideshare_scroll
// @name slideshare scroll
// @version 1.3
// @namespace http://rikuba.com/
// @include http://slideshare.net/*
// @include http://www.slideshare.net/*
// @include http://speakerdeck.com/*
// @include https://speakerdeck.com/*
// @include https://docs.google.com/presentation/embed*
// ==UserScript==
// @name openLinkByLongPress
// @namespace http://rikuba.com/
// @include *
// @grant GM_openInTab
// ==/UserScript==
const WAIT = 500; // milliseconds
var tid;