个人爱好,知识积累,点滴成石
web端
wisdom-plus + 高德自定义地图 DemoMap.vue
鼠标拖拽坐标捕获 useMouseDownToMove.ts
获取事件冒泡路径,兼容ie11,edge,chrome,firefox,safari
服务端
前端资源javascript-obfuscator代码混淆加密
nodejs 17 以下fetch兼容,以axios方式-可解决llama-js 在低版本的nodejs中的正常运行
other
import { defineConfig } from 'unocss';
export default defineConfig({
// ...UnoCSS options
shortcuts: {
'flex-center': 'flex justify-center items-center',
'flex-center-start': 'flex justify-start items-center',
'flex-center-end': 'flex justify-end items-center',
'flex-center-between': 'flex justify-between items-center',
'flex-center-around': 'flex justify-around items-center',
'flex-v': 'flex flex-col',
'abs-f': 'fixed',
'abs-r': 'relative',
abs: 'absolute',
'size-content': 'left-0 top-0 w-100% h-100%',
'abs-content': 'absolute left-0 top-0 w-100% h-100%',
'abs-start': 'absolute left-0 top-0',
'abs-end': 'absolute right-0 top-0',
'abs-end-bottom': 'absolute right-0 bottom-0',
'abs-start-bottom': 'absolute left-0 bottom-0',
'abs-center': 'absolute left-50% top-50% translate--50%',
'abs-x': 'absolute left-50% translate-x--50%',
'abs-y': 'absolute top-50% translate-y--50%',
bold: 'font-bold',
'cur-p': 'cursor-pointer',
'p-e-n': 'pointer-events-none',
},
rules: [
[
// 包含小数点的 flex
/^flex-?([0-9]+(?:\.[0-9]+)?)$/,
(match) => {
return {
flex: match[1],
};
},
],
[
/^tr-?([xy])(?:-?(-?.+))?$/,
(match) => {
return {
transform: `translate${match[1].toUpperCase() || 'Y'}(${match[2] || 0})`,
};
},
],
[
/^frame(?:-?(-?.+))?$/,
(match) => {
const [name, start, time, ...timing] = match[1].split('-');
let timingFn = timing;
let timeStr = time;
if (time === 'cubic') {
timingFn = [time].concat(timing);
timeStr = '';
}
return {
animation: `${name} calc(1 - var(--sy) / ${start}) ${timeStr || ''} ${timingFn.join('-') || 'linear'} forwards reverse`,
};
},
],
[
// c-var--primary-color => color: var(--primary-color)
/^c-var-([a-zA-Z0-9-]+)$/,
(match) => {
return {
color: `var(--${match[1]})`,
};
},
],
[
/^(s|size)-([a-zA-Z0-9-]+)$/,
(match) => {
return {
width: match[2],
height: match[2],
};
},
],
[
/^bg-(lg|rlg|rg|rrg|url)-(.{1,})$/,
(match) => {
return {
'background-image': `${
{
lg: 'linear-gradient',
rlg: 'radial-gradient',
rg: 'repeating-linear-gradient',
rrg: 'repeating-radial-gradient',
url: 'url',
}[match[1]]
}(${match[2].replace(/--/g, ' , ').replace(/-/g, ' ').replace(/\$([^\s]+)/g, 'var(--$1)')})`,
};
},
],
],
});
//10进制转成有符号的10进制
function hexToSignedDecimal(hexStr) {
// 将 16 进制字符串转换为无符号的整数
const unsignedInt = parseInt(hexStr, 16);
// 32 位有符号整数的范围
const INT32_MAX = 0x7FFFFFFF;
const INT32_MIN = -0x80000000;
// 判断是否为负数
if (unsignedInt > INT32_MAX) {
// 如果无符号整数大于 0x7FFFFFFF,则它在有符号整数的负数范围内
return unsignedInt - 0x100000000; // 0x100000000 是 2^32,用于从无符号转换为有符号
} else {
// 如果不在负数范围内,直接返回值
return unsignedInt;
}
}
const hexStr = "fe7ae63d";
const signedDecimal = hexToSignedDecimal(hexStr);
console.log(signedDecimal); // 输出 -126813651
// 转符号10进制示例
function signedDecimalToHex(unsignedInt) {
// 判断是否为负数
if (unsignedInt < 0) {
// 如果无符号整数大于 0x7FFFFFFF,则它在有符号整数的负数范围内
return (unsignedInt + 0x100000000).toString(16); // 0x100000000 是 2^32,用于从无符号转换为有符号
} else {
// 如果不在负数范围内,直接返回值
return unsignedInt.toString(16);
}
}
import { readFileSync } from "fs"
/**
* @name sqlCommitFunction sql文件注释解析
* @param sqlFilePath sql文件路径
* @returns
*/
export default function <T = Record<string, any>>(sqlFilePath: string): T{
const sql = readFileSync(sqlFilePath, 'utf8')
const sqlNames = []
sql.replace(/\/\*(.|\n)*?\*\//g, function(m){
const name = m.match(/@[^*\/]*/)?.[0].replace(/@|\n|\s/g,'') || ''
sqlNames.push([name, m])
return ``
})
let sqlCopy = sql
return sqlNames.reverse().reduce((a,b)=>{
const value = sqlCopy.slice(sql.lastIndexOf(b[1]))
a[b[0]] = value.replace(b[1],'')
sqlCopy = sqlCopy.replace(value, '')
return a
},{})
}
const waitForSelector = async (selector: string) => {
return await page.evaluate(async function name(selector) {
if (!document.querySelector(selector)) {
return await new Promise(r => {
requestAnimationFrame(async () => {
await name(selector)
r(true)
})
})
}
},selector)
}
import { CronJob } from 'cron';
import { execSync, execFileSync } from 'child_process';
new CronJob('* * * * * *',()=>{
try {
execSync(`
screen_status=$(adb shell dumpsys power | grep "Display Power" | grep -o 'OFF')
if [ "$screen_status" = "OFF" ]; then
echo "Screen is off";
adb shell input keyevent 26;
fi;
adb shell dumpsys window | grep -i "current=[immersive]"
adb devices
`,{
stdio:'inherit',
});
}catch (error) {
console.log(error)
}
}).start();