Skip to content

Instantly share code, notes, and snippets.

@ambar
ambar / nospm.user.js
Last active March 16, 2024 01:44
nospm 移除虾米、淘宝和 Bilibili 网址中的 spm 参数(包括地址栏和页面中的链接),推荐使用 Tampermonkey 或者 Violentmonkey 安装,UserScript 安装地址 https://gist.github.com/ambar/9706385/raw/nospm.user.js
// ==UserScript==
// @name nospm
// @version 1.4.0
// @run-at document-start
// @updateURL https://gist.github.com/ambar/9706385/raw/nospm.user.js
// @downloadURL https://gist.github.com/ambar/9706385/raw/nospm.user.js
// @description 移除 Bilibili、淘宝、天猫、优酷网址中的 spm 参数(包括地址栏和页面中的链接)
// @include https://*.bilibili.com/*
// @include https://*.taobao.com/*
// @include https://*.tmall.com/*
@ambar
ambar / mac-arabic-fix.css
Last active December 22, 2015 00:38
Mac/iOS arabic crash bug
@font-face {
font-family: 'Helvetica Neue';
unicode-range: U+0600—06FF, U+0750—077F, U+08A0—08FF, U+FB50—FDFF, U+FE70—FEFF, U+10E60—10E7F, U+1EE00—1EEFF;
src: local(Arial);
}
@font-face {
font-family: 'Helvetica Neue';
font-weight: bold;
unicode-range: U+0600—06FF, U+0750—077F, U+08A0—08FF, U+FB50—FDFF, U+FE70—FEFF, U+10E60—10E7F, U+1EE00—1EEFF;
src: local(Arial);
@ambar
ambar / openinapp.js
Created April 25, 2013 12:08
OpenInApp, from instagram
var exports = //
exports.protocal = 'zhihu://'
exports.applink = 'http://itunes.apple.com/cn/app/id432274380'
/**
* 尝试在 zhihu iPhone App 中打开链接
* @param {string} url
*/
@ambar
ambar / _.js
Last active December 15, 2015 05:59
var makePile = function(count, onfilter, onvalue) {
var values = []
var id = function(value) {
// console.info('onvalue::', value)
return value
}
return function(value) {
values.push((onvalue || id).apply(this, arguments))
if (values.length === count) {
onfilter.apply(this, values)
// ==UserScript==
// @name sans-serif enabler
// @include http://www.zhihu.com/*
// ==/UserScript==
document.head.querySelector('link[href$="punctuation.css"]').disabled = true
@ambar
ambar / _.js
Last active October 13, 2015 04:27
auto restore viewport
var autorestore_ = function(element) {
var oldPosition = element.getBoundingClientRect().bottom
setTimeout(function() {
var newPosition = element.getBoundingClientRect().bottom
window.scrollTo(window.scrollX, window.scrollY + newPosition - oldPosition)
})
}
@ambar
ambar / _.less
Created November 23, 2012 09:24
animated.css usage
.tooltip {
position: absolute;
z-index: 1050;
.animated();
.animation-duration(.55s);
.animation-timing-function(ease-in);
&.in {
// .fadeInDown();
.lightSpeedIn();
// .rollIn();
@ambar
ambar / gist:4022879
Created November 6, 2012 05:57 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); { if (a[3]) { print a[2]"/"a[3] } else { print a[2] } }}' |
xargs git push origin --delete
@ambar
ambar / -.md
Created October 26, 2012 16:06
delegate proto
  • 核心是 matchSelector 方法,可以借用了 jQuery.fn.is 方法;
  • 选择器匹配了多个元素时,事件触发顺序应该从底向上;
  • 绑定多个监听函数时并多时匹配到多个元素时,依次发生顺序要正确;
  • 匹配目标应该包含 event.target,不包含委托的顶层元素;
  • 反注册时,清理代理函数;
JSON.stringify(delegateMap, function(k, v) {
 return typeof v === 'function' ? 'fn' : v
}, ' ')
@ambar
ambar / csv2vcard.js
Created October 13, 2012 07:13
csv2vcard.js
/**
* @author ambar
* @ref http://en.wikipedia.org/wiki/VCard
*/
function parse(csv, sep) {
sep = sep || ','
var lines = csv.split('\n'), head = lines.shift().split(sep)
var json = lines.map(function(line) {
var person = {}, values = line.split(sep)