├── LICENSE └── readme.md /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # 迁移公告: 2 | 3 | 经网友提醒,本项目违反了 GitHub TOS,故将项目迁移到个人的私有 GitLab 仓库,需要提交 PR 的用户请发 Issue 联系我 4 | 项目迁移后地址:https://git.dev.geektr.cloud/geektr/fuck-smartisan 5 | 6 | # Fuck Smartisan 7 | 8 | **这是个恶意的项目,作者知道自己是错的,但并不会悔改。所以请勿费力批评。** 9 | 10 | 本项目用于拒绝锤子手机,请在明确认知到自己是在作恶的情况下使用。 11 | 12 | 另外,除非你有相应的权力,否则请勿在公司项目中使用。 13 | 14 | ## 基本使用 15 | 16 | 您可以简单地在项目代码中引入本项目来实现拒绝锤子手机的访问 17 | 18 | ```javascript 19 | import fuckSmartisan from 'fuck-smartisan' 20 | 21 | fuckSmartisan() 22 | ``` 23 | 24 | fuckSmartisan 函数将清理 html 标签下所有内容,并替换为一行 ‘因开发者个人的偏见,本项目不对锤子手机用户开放。’ 25 | 26 | 你也可以自定义的提示信息,支持以下几种用法(第二、三条将折行显示) 27 | 28 | ```javascript 29 | fuckSmartisan('本项目开发者精力有限,暂不准备兼容锤子手机') 30 | fuckSmartisan('本项目内含播放声音的内容\n为避免影响您使用 TNT\n特此主动屏蔽') 31 | fuckSmartisan(['锤子万岁', '太君威武']) 32 | ``` 33 | 34 | PS: 为了最佳的阅读体验,建议单行不超过 50 字 35 | 36 | ## 自定义使用 37 | 38 | 本项目提供了简单的 isSmartisanOS 函数,您可以引入此函数来判断一个 userAgent 字符串是否来自锤子手机,从而实现定制化的服务。 39 | 40 | 用法: 41 | 42 | ```javascript 43 | import { isSmartisanOS } from 'fuck-smartisan' 44 | 45 | isSmartisanOS() // 浏览器环境下可不传参,将自动获取 navigator.userAgent 用于判断 46 | isSmartisanOS(ctx.userAgent) 47 | ``` 48 | 49 | 示例: 50 | 51 | ```javascript 52 | function showPrice(price) { 53 | if (isSmartisanOS()) { 54 | return [`原价: ${price * 3}`, `锤子用户专享价:${price * 2.5}`] 55 | } else { 56 | return [`原价: ${price * 1.1}`, `现时特惠:${price}`] 57 | } 58 | } 59 | 60 | xxxxx.innerText = showPrice(100) 61 | ``` 62 | 63 | ### 作为 Vue 插件使用 64 | 65 | 本项目提供了 Vue 插件,该插件将在 Vue 原型上添加一个 `$isSmartisanOS` 属性用于判断是否锤子手机 66 | 67 | 引入: 68 | 69 | ```javascript 70 | import Vue from 'vue' 71 | import vIsSmartisanOS from 'fuck-smartisan/dist/v-is-smartisan-os' 72 | 73 | Vue.use(asyncValidatorPromisify) 74 | ``` 75 | 76 | 使用: 77 | 78 | ```html 79 | 87 | ``` 88 | 89 | ```javascript 90 | export default { 91 | name: 'beginning-info', 92 | // ...... 93 | methods: { 94 | async getCoupons() { 95 | if (this.$isSmartisanOS) { 96 | return [] 97 | } 98 | try { 99 | const coupons = await queryCoupons({ expried: false }) 100 | return coupons 101 | } catch (e) { 102 | alert('网络异常') 103 | return [] 104 | } 105 | }, 106 | }, 107 | } 108 | ``` 109 | 110 | ### 作为 Koa 插件使用 111 | 112 | 本项目提供了 Koa 插件,该中间件将根据客户端的 user-agent 判断是否锤子手机,进而 ctx 上添加一个 `isSmartisanOS` 属性。 113 | 114 | ```javascript 115 | import Koa from 'koa' // koa 2 116 | import koaFuckSmartisan from 'fuck-smartisan/dist/koa-fuck-smartisan' 117 | 118 | Vue.use(koaFuckSmartisan()) 119 | 120 | app.use(ctx => { 121 | if (ctx.isSmartisanOS) { 122 | ctx.status = 301 123 | ctx.body = '锤子手机售价低于2500,我是你孙子' 124 | ctx.redirect('http://www.smartisan.love') 125 | } 126 | }) 127 | 128 | ``` 129 | 130 | 您也可以向插件传入一个 config 来直接中断 koa 剩余业务逻辑,直接返回一行 “因开开发者能力有限,本页面不对锤子手机进行兼容,理解万岁。” 给锤子客户端: 131 | 132 | ```javascript 133 | import Koa from 'koa' // koa 2 134 | import koaFuckSmartisan from 'fuck-smartisan/dist/koa-fuck-smartisan' 135 | 136 | Vue.use(koaFuckSmartisan({ forbid: true })) 137 | 138 | app.use(async (ctx, next) => { 139 | // This will not run when hammer phone visit 140 | ctx.body = "Hello, Phone" 141 | await next() 142 | }) 143 | ``` 144 | 145 | 当然,自定义返回信息也是可以的: 146 | 147 | ```javascript 148 | import Koa from 'koa' // koa 2 149 | import koaFuckSmartisan from 'fuck-smartisan/dist/koa-fuck-smartisan' 150 | 151 | const SmartisanResponse = { 152 | status: 404, 153 | body: '锤子的销量不到 40 万,显然是一个可忽视的机型', 154 | } 155 | 156 | Vue.use(koaFuckSmartisan({ forbid: true, response: SmartisanResponse })) 157 | ``` 158 | 159 | ### 在命令行中使用 160 | 161 | 本项目提供了命令行工具,以便在 shell 中使用 162 | 163 | ```bash 164 | $ is-smartisan --help 165 | 166 | usage: is-smartisan [-i|] [--help] 167 | 168 | -i 接收标准输入 169 | --help 显示帮助信息 170 | 171 | example: 172 | $ is-smartisan "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-cn; SM919 Build/MXB48T) Ap..." 173 | $ cat user-agent.text | is-smartisan -i 174 | ``` 175 | 176 | 示例: 177 | 178 | ``` 179 | NGX_LOG=/data/logs/nginx-access.log 180 | 181 | while read LINE; do 182 | is-smartisan "$LINE" && push-black-list "$LINE" || push-white-list "$LINE" 183 | done < "$NGX_LOG" 184 | ``` 185 | 186 | ## 贡献代码 187 | 188 | 鉴于本人可能跟不上 TNT 用户的开发效率,所以提交 PR 的同时,请附上自己的屏幕截图,证明自己不是 TNT 用户。 189 | --------------------------------------------------------------------------------