From b0e486478280296e8641b39a016e5ae300fe73a3 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Thu, 27 Jul 2023 06:36:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=20star?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/doc.html | 3 +- sa-token-doc/static/is-star-plugin.js | 218 ++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 sa-token-doc/static/is-star-plugin.js diff --git a/sa-token-doc/doc.html b/sa-token-doc/doc.html index 07cfb0eb..b45ed643 100644 --- a/sa-token-doc/doc.html +++ b/sa-token-doc/doc.html @@ -152,6 +152,7 @@ + diff --git a/sa-token-doc/static/is-star-plugin.js b/sa-token-doc/static/is-star-plugin.js new file mode 100644 index 00000000..15c2f1f9 --- /dev/null +++ b/sa-token-doc/static/is-star-plugin.js @@ -0,0 +1,218 @@ +// + +// 声明 docsify 插件 +var isStarPlugin = function(hook, vm) { + + // 切换文档的次数,每隔固定次数检测一下 + let changePage = -1; + + // 钩子函数:解析之前执行 + hook.beforeEach(function(content) { + return content; + }); + + // 钩子函数:每次路由切换时,解析内容之后执行 + hook.afterEach(function(html) { + changePage++; + if(changePage % 15 === 0) { + isStarRepo(); + } + return html; + }); + + // 每钩子函数:次路由切换时数据全部加载完成后调用,没有参数。 + hook.doneEach(function() { + + }); + + // 钩子函数:初始化并第一次加载完成数据后调用,没有参数。 + hook.ready(function() { + + }); + +} + +// 应用参数 +const client_id = '0cc618beb08db99bff50e500e38c2144d95ada9abb51c00c44592726ecd583f4'; +const client_secret = '2574c2aac8ce2142e34752dc5957dddcb30bc68df5c61de64251a3a6b11a51e5'; +// const redirect_uri = 'http://local.dev33.cn:8848/sa-token-doc/doc.html'; +const redirect_uri = 'https://sa-token.cc/doc.html'; +// const docDomain = 'local.dev33.cn:8848'; +const docDomain = 'sa-token.cc'; + +// 检查成功后,多少天不再检查 +const allowDisparity = 1000 * 60 * 60 * 24 * 30; +// const allowDisparity = 1000 * 10; + + +// 判断当前是否已 star +function isStarRepo() { + // 非PC端不检查 + if(document.body.offsetWidth < 800) { + console.log('small screen ...'); + return; + } + + // 判断是否在主域名下 + if(location.host !== docDomain) { + console.log('非主域名,不检测...'); + return; + } + + // 判断是否近期已经判断过了 + try{ + const isStarRepo = localStorage.isStarRepo; + if(isStarRepo) { + // 记录 star 的时间,和当前时间的差距 + const disparity = new Date().getTime() - parseInt(isStarRepo); + + // 差距小于一月,不再检测,大于一月,再检测一下 + if(disparity < allowDisparity) { + console.log('checked ...'); + return; + } + } + }catch(e){ + console.error(e); + } + + // 开始获取 code + getCode(); +} + +// 去请求授权 +function getCode() { + + // 检查url中是否有code + const code = getParam('code'); + if(code) { + // 有 code,进一步去请求 access_token + getAccessToken(code); + } else { + // 不存在code,弹窗提示询问 + confirmStar(); + } +} + +// 弹窗提示点 star +function confirmStar() { + + // 弹窗提示文字 + let tipStr = "
嗨,同学,来支持一下 Sa-Token 吧,为项目点个 star !
"; + tipStr += "不点也没关系 ❤️ ❤️ ❤️,Sa-Token 将努力变得更加完善!😇
"; + tipStr = '