Skip to content

Instantly share code, notes, and snippets.

@smadey
smadey / vite-plugin-amis.ts
Last active March 13, 2023 02:27
Vite AMis Plugin
/* eslint-disable @typescript-eslint/no-var-requires */
import type { Plugin, HtmlTagDescriptor } from 'vite';
const addStyle = (src): HtmlTagDescriptor => ({
injectTo: 'head',
tag: 'link',
attrs: { rel: 'stylesheet', href: src },
});
const addScript = (src): HtmlTagDescriptor => ({
@smadey
smadey / url-parse.js
Created October 15, 2019 06:58
Parse url
var REG = /^([^:/?#]+:)?(?:\/\/(([^/?#:]*)(?::(\d+))?))?(([^?#]*)(\?([^#]*))?)(#.*)?$/i;
function parseUrl(str) {
var res = REG.exec(str);
if (!res) return null;
return {
href: res[0],
protocol: res[1] || '',
host: res[2] || '',
hostname: res[3] || '',
@smadey
smadey / autumn-falling-leaves-gsap.markdown
Created April 15, 2019 15:01
Autumn falling leaves ( GSAP )

Falling Leaves

There aren't many falling leaf javascript simulations, so I decided to make one. It's surprisingly difficult to mimic leaf motion, and this is a fairly simple attempt. There are a few more tricks with wind and leaf paths that I would like to add.

Vanilla JS, no dependencies

A Pen by Sarah Higley on CodePen.

License.

@smadey
smadey / book-flip-page-turn.markdown
Created April 15, 2019 12:17
book flip page turn
@smadey
smadey / onerror.js
Created January 9, 2019 14:05
错误调试
window.onerror = function (msg, url, lineNo, columnNo, error) {
var string = msg.toLowerCase();
var substring = "script error";
if (string.indexOf(substring) > -1){
alert('Script Error: See Browser Console for Detail');
} else {
var message = [
'Message: ' + msg,
'URL: ' + url,
'Line: ' + lineNo,
@smadey
smadey / onVisibilityChange.js
Created January 7, 2019 14:38
onVisibilityChange
let hidden
let visibilityChange
if (typeof document.hidden !== 'undefined') {
hidden = 'hidden'
visibilityChange = 'visibilitychange'
} else if (typeof document.webkitHidden !== 'undefined') {
hidden = 'webkitHidden'
visibilityChange = 'webkitvisibilitychange'
}
@smadey
smadey / plog.js
Created March 2, 2018 11:46
Performance Log Util
class Plog {
constructor (name) {
this.name = name
this.messages = []
}
write (...texts) {
this.messages.push({
texts,
time: Date.now()
@smadey
smadey / dialog.js
Last active June 7, 2017 10:01
对话框的简单实现
var Dialog = {
$$el: null,
$$resolve: null,
$$reject: null,
init: function () {
var self = this;
if (self.$$el) {
return self;
}