Skip to content

Instantly share code, notes, and snippets.

View nicholasxjy's full-sized avatar
🖖
AFK

xue nicholasxjy

🖖
AFK
View GitHub Profile
@nicholasxjy
nicholasxjy / vscode.json
Created February 9, 2021 01:51
some vscode settings
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Attributes",
"scope": "entity.other.attribute-name",
"settings": {
"fontStyle": "italic"
}
},
{
@nicholasxjy
nicholasxjy / util.js
Last active January 26, 2021 07:02
util
const getURLParameters = url =>
(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
(a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),
{}
);
function extractRootDomain(d) {
return /^([\d.]+|[a-z-]+)$/.test(d) ? d : d.split('.').slice(-2).join('.')
}
@nicholasxjy
nicholasxjy / prevent-body-scroll.js
Created June 30, 2019 04:31
prevent-body-scroll
let previousOverflow
let previousPaddingRight
/**
* Toggle the body scroll / overflow and additional styling
* necessary to preserve scroll position and body width (scrollbar replacement)
*
* @param {boolean} preventScroll - whether or not to prevent body scrolling
*/
export default function preventBodyScroll(preventScroll) {
@nicholasxjy
nicholasxjy / trucateNumber.js
Created March 7, 2019 02:43
truncate number with k M G (3001 -> 3k)
function truncateNumber(num, digits = 0) {
const si = [
{ value: 1, symbol: '' },
{ value: 1e3, symbol: 'k' },
{ value: 1e6, symbol: 'M' },
{ value: 1e9, symbol: 'G' },
{ value: 1e12, symbol: 'T' },
{ value: 1e15, symbol: 'P' },
{ value: 1e18, symbol: 'E' }
]
@nicholasxjy
nicholasxjy / copy.js
Created February 15, 2019 06:03
copy append text
const appendCopyrightToLivenews = e => {
const crText = `\r\n\r\n链接:${
location.origin
}\r\n非商业转载请注明出处。`
e.preventDefault()
e.clipboardData.setData('Text', window.getSelection() + crText)
}
document.addEventListener('copy', appendCopyrightToLivenews)
@nicholasxjy
nicholasxjy / git.md
Last active December 24, 2018 03:20
git commands
  • remove unused remote branches to local
git fetch origin --prune
  • remove unused remote tags to local
git fetch --prune --prune-tags origin
@nicholasxjy
nicholasxjy / popup.js
Created September 20, 2018 10:13
open a popup window in center
export function popupUrlCenterWindow(url, title, w, h) {
const dualScreenLeft =
window.screenLeft != undefined ? window.screenLeft : window.screenX
const dualScreenTop =
window.screenTop != undefined ? window.screenTop : window.screenY
const width = window.innerWidth
? window.innerWidth
: document.documentElement.clientWidth
? document.documentElement.clientWidth
@nicholasxjy
nicholasxjy / regex.js
Last active February 27, 2020 03:09
some useful regex
// mobile phone numbers in china
const reg = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/
// image tag
const regex = /<img([\s\S]*?)src\s*=\s*(['"])([\s\S]*?)\2([^>]*)>/gi
// only chinese charactors and letters
const regex = /^[\u4e00-\u9fa5a-zA-Z]+$/
// email
@nicholasxjy
nicholasxjy / meta-tags.md
Created August 4, 2018 14:50 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">
// 屏幕可视窗口大小
window.innerHeight // 标准浏览器及IE9+
document.documentElement.clientHeight // 标准浏览器及低版本IE标准模式
document.body.clientHeight // 低版本混杂模式
// 浏览器窗口顶部与文档顶部之间的距离,也就是滚动条滚动的距离
window.pagYOffset // 标准浏览器及IE9+
document.documentElement.scrollTop // 兼容ie低版本的标准模式
document.body.scrollTop // 兼容混杂模式