Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name openLinkByLongPress
// @namespace http://rikuba.com/
// @include *
// @grant GM_openInTab
// ==/UserScript==
const WAIT = 500; // milliseconds
var tid;
// ==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*
@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);
@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 / 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 / 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 / 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 / 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 / function_getName.js
Last active December 21, 2015 09:29
get function name
Function.prototype.getName =
(function () { return (function foobar() { }).name === 'foobar'; })()
? (function () { return function getName() { return this.name; }; })()
: (function () {
var functionKeywordPattern = (function () {
var parts = [];
var keyword = 'function';
for (var i = 0; i < 8; ++i) {
var ch = keyword.charAt(i);
var code = keyword.charCodeAt(i);
@rikuba
rikuba / function_new.js
Created August 29, 2013 21:39
Function.prototype.new
(function () {
var bind = Function.prototype.bind;
var slice = Array.prototype.slice;
Object.defineProperty(Function.prototype, 'new', {
value: function _new() {
return new (bind.apply(this, [null].concat(slice.call(arguments))));
},
configurable: true,
enumerable: false,