Skip to content

Instantly share code, notes, and snippets.

View sofish's full-sized avatar
🚀
still hiring creatives

小鱼 sofish

🚀
still hiring creatives
View GitHub Profile
@sofish
sofish / array_unique.js
Last active July 11, 2017 01:36
Array Unique
function unique_keys(array) {
var values = {};
for(var i = 0; i < array.length; i++) {
values[array[i]] = null;
}
return Object.keys(values);
}
@sofish
sofish / error.js
Created November 1, 2014 09:05
Error
{"status":"error","error":{"msg":"\u6b64\u997f\u5355\u5df2\u6295\u8bc9","code":23}}
@sofish
sofish / nav.js
Created October 29, 2014 11:37
nav for uedetail
document.querySelector && window.addEventListener('keyup', function (e) {
var url = e.which === 39 ? document.querySelector('a[rel=prev]').href :
e.which === 37 ? document.querySelector('a[rel=next]').href : '';
if (url) window.location = url;
});
@sofish
sofish / urlparser.js
Last active March 18, 2021 11:31
URL Parser
var parser = function(url) {
var a = document.createElement('a');
a.href = url;
var search = function(search) {
if(!search) return {};
var ret = {};
search = search.slice(1).split('&');
for(var i = 0, arr; i < search.length; i++) {
@sofish
sofish / ciao.js
Created October 27, 2014 13:54
ciao.js
$.fn.ciao = function() {
console.log('没事爱瞎bb');
return this;
};
// 这样执行
$().ciao().ciao().ciao();
@sofish
sofish / jqLite.extra.js
Last active October 20, 2015 13:09
rewrite `parent` and `find` method for jqLite
angular.$ = angular.element;
// jqLite `.parent([selector])` 支持 selector
angular.$.prototype.parent = function(sel) {
if(!sel) return angular.$(this[0].parentNode);
var list = [].slice.call(document.querySelectorAll(sel))
, currentNode = this[0]
, ret;
while(currentNode.nodeName !== 'HTML') {
var girl_said = 'Girl: 不爱理你'
, programmer_s_prattle = 'Programmer: 我喜欢... 你';
console.log(girl_said);
girl_said = girl_said.replace(/(?:with\_love)?(不|理)/g, function(ignore) {
// said in heart
console.log(programmer_s_prattle);
return ignore = '';
})
@sofish
sofish / people.js
Created November 23, 2013 09:22
people.js
var names = [], emails = [], result = [];
var value = function(nodeList, target){
[].slice.call(nodeList).forEach(function(item){
target.push(item.textContent);
});
return target.slice(1);
};
var select = function(selector){
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sofish
sofish / sort.js
Created August 7, 2013 03:21
safari 不能用 true / false 来做排序
// firefox 和 chrome 是 [1024, 6, 5, 3, 2, 1]
// safari 中顺序没变
[1,3,2,5,6,1024].sort(function(a, b) {
return b > a;
});
// 在各中浏览器工作一致的方法
// 用正负和零来排序,而不是 true/false
[1,3,2,5,6,1024].sort(function(a, b) {