Shopify Partner 使用 JS 一键创建店铺 作者: Chuwen 时间: 2022-12-28 分类: JavaScript 评论 # Shopify Partner 使用 JS 一键创建店铺 免去繁琐的操作步骤 ### 第 1 步 打开 https://partners.shopify.com/organizations > 如果没有登录需要先登录 ### 第 2 步 打开浏览器**开发者工具**,以 Chrome 为例,按 F12 即可打开 ### 第 3 步 > 请注意修改代码的 `subdomain` 和 `storeName` 值 在**开发者工具**找到 `Console` Tab,然后粘贴以下代码,按 `Enter` 键运行即可 ### 第 4 步 等待大概 20s 左右,因为创建店铺需要比较长的时间,创建成功后,会自动打开你新创建的店铺 ```js var organizationID = window.RailsData.user.organizationID var subdomain = 'test-008' var storeName = subdomain.replaceAll("-", " ").toUpperCase() fetch(`https://partners.shopify.com/${organizationID}/api/graphql`, { headers: { 'content-type': 'application/json', 'x-csrf-token': document.querySelector(`meta[name="csrf-token"]`).content }, body: JSON.stringify({ operationName: "ShopCreate", variables: { input: { storeType: "PARTNER_TEST_STORE", developerPreviewHandle: "checkout_extensibility", storeName, address: { countryCode: 'US'// 国家 }, subdomain, signupSourceDetails: 'test_app_or_theme' } }, query: "mutation ShopCreate($input: ShopCreateInput!) {\n shopCreate(input: $input) {\n redirectUrl\n userErrors {\n field\n message\n __typename\n }\n __typename\n }\n}\n" }), method: 'POST', mode: 'cors', credentials: 'include' }) .then((response) => response.json()) .then((data) => { console.log('创建店铺成功!', data); window.open(data.shopifyCreate.redirectUrl, "_blank") }) .catch((error) => { console.error('创建店铺失败!', error); alert(`创建店铺失败!${error}`) }); ``` --- Gist: https://gist.github.com/PrintNow/067f1d494a2f723e1486d9527997942ca
Chrome 无法使用谷歌翻译(Google Translate)解决办法 作者: Chuwen 时间: 2022-12-16 分类: 神奇技巧 评论 ## 解决方案 ### 1. DNS 重写 将 `translate.googleapis.com` CNAME 解析到 `update.googleapis.com` 即可 使用如 AdGuard 进行 DNS 重写: ![](https://cdn.nowtime.cc/2022/12/16/3589390178.png) ### 2. 修改系统 hosts 文件 因为网上有许多资料讲怎么修改,这里不再赘述
读取 .env 环境变量文件,并使用 mysqldump 导出数据库 作者: Chuwen 时间: 2022-12-10 分类: 其他分类 评论 ## 代码 如果没有 mysqldump 可以使用此命令安装<仅限于 CentOS 系统> ```shell yum install -y holland-mysqldump.noarch ``` --- ```shell #!/bin/bsh function echo_error() { [ $# -ne 1 ] && return 0 echo -e "\033[31m $1 \033[0m" } function echo_danger() { [ $# -ne 1 ] && return 0 echo -e "\033[41;37m $1 \033[0m" } function echo_info() { [ $# -ne 1 ] && return 0 echo -e "\033[32m $1 \033[0m" } function echo_success() { [ $# -ne 1 ] && return 0 echo -e "\033[42;37m $1 \033[0m" } function echo_warning() { [ $# -ne 1 ] && return 0 echo -e "\033[33m $1 \033[0m" } function now_time() { echo $(date '+%Y-%m-%d %H:%M:%S') } if [ ! -f ".env" ]; then echo_danger ".env 不存在,终止执行" exit 127 fi # 将 .env 文件导入环境变量(排除注释行) export $(cat .env | grep -v "^#") # 导出每个表前 1000 条数据 function export_limit_1000() { mysqldump --column-statistics=0 \ --host="${DB_HOST}" \ --user="${DB_USERNAME}" --password="${DB_PASSWORD}" \ "${DB_DATABASE}" \ --where="true limit 1000" >mysqldump_"$(date '+%Y-%m-%d_%H:%M:%S')".sql } function export_sql() { echo_info "[`now_time`] >>> 开始导出数据库" mysqldump --column-statistics=0 \ --host="${DB_HOST}" \ --user="${DB_USERNAME}" --password="${DB_PASSWORD}" \ "${DB_DATABASE}" \ >mysqldump_"$(date '+%Y-%m-%d_%H:%M:%S')".sql echo_success "[`now_time`] <<< 导出数据库完成" } export_sql ``` ## 执行结果 ![](https://cdn.nowtime.cc/2022/12/10/3529888146.png)
Shell 输出有颜色文本并封装成函数 作者: Chuwen 时间: 2022-12-10 分类: Linux 评论 ```shell #!/bin/bash # 输出红字 function echo_error() { [ $# -ne 1 ] && return 0 echo -e "\033[31m $1 \033[0m" } # 输出红底白字 function echo_danger() { [ $# -ne 1 ] && return 0 echo -e "\033[41;37m $1 \033[0m" } # 输出绿字 function echo_info() { [ $# -ne 1 ] && return 0 echo -e "\033[32m $1 \033[0m" } # 输出绿底白字 function echo_success() { [ $# -ne 1 ] && return 0 echo -e "\033[42;37m $1 \033[0m" } # 输出黄字 function echo_warning() { [ $# -ne 1 ] && return 0 echo -e "\033[33m $1 \033[0m" } ``` ## 运行结果截图 ```shell echo_error "输出红字" echo_danger "输出红底白字" echo_info "输出绿字" echo_success "输出绿底白字" echo_warning "输出黄字" ``` ![](https://cdn.nowtime.cc/2022/12/10/445780269.png) --- 通过 gist 查看:https://gist.github.com/PrintNow/a33da4cf74bb2f097deb00ac0dadd003
lottie-react-web 报错: Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') 作者: Chuwen 时间: 2022-10-29 分类: React 评论 ## 错误信息 ``` Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') at Lottie2.deRegisterEvents (index.js:226:22) at Lottie2.componentWillUnmount (index.js:148:12) at callComponentWillUnmountWithTimer (react-dom.development.js:20413:14) at HTMLUnknownElement.callCallback2 (react-dom.development.js:3945:14) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:16) at invokeGuardedCallback (react-dom.development.js:4056:31) at safelyCallComponentWillUnmount (react-dom.development.js:20420:5) at commitUnmount (react-dom.development.js:20951:11) at commitNestedUnmounts (react-dom.development.js:21004:5) at unmountHostComponents (react-dom.development.js:21290:7) ``` ![](https://cdn.nowtime.cc/2022/10/29/580616896.png) ## 问题原因 查看报错信息,似乎指的是 `eventListeners` 变量不是一个数组或不存在 ![](https://cdn.nowtime.cc/2022/10/29/92600442.png) ## 解决方案 加上这个属性并给一个空数组即可 `eventListeners` ```react ``` ![](https://cdn.nowtime.cc/2022/10/29/1407110091.png)