From 06c1448c2f7a029cbc81f22592e0f774c2ee1895 Mon Sep 17 00:00:00 2001 From: BestJarvan <532547613@qq.com> Date: Fri, 21 Jan 2022 03:52:01 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 996a66c8..1a9d2e88 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ - [PVulcan's Blog](https://pvulcan.cn/) - [TimeMachine's Blog](https://timemachine.icu/) - [Oridnaryman's Blog](https://jack1024.club/) +- [Jiangyh's Blog](https://bestjarvan.gitee.io/) - [未读代码](https://www.wdbyte.com/) 如果你准备长期使用 «Stun» 主题,并希望展示在这里,你只需在 [README](https://github.com/liuyib/hexo-theme-stun/edit/master/README.md) 中填入你的网站,然后提交 PR 即可。 From 894a01952aa78417f28c499504950de640dd88cd Mon Sep 17 00:00:00 2001 From: Jarvan Date: Fri, 1 Sep 2023 17:40:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20execCommand=E5=8D=B3=E5=B0=86?= =?UTF-8?q?=E5=BC=83=E7=94=A8,=E6=9B=BF=E6=8D=A2=E6=96=B0=E7=9A=84api;?= =?UTF-8?q?=E9=99=8D=E7=BA=A7=E4=BD=BF=E7=94=A8execCommand;=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=A4=8D=E5=88=B6=E6=90=BA=E5=B8=A6=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 2 ++ layout/_partials/config.pug | 1 + package.json | 2 ++ source/js/utils.js | 28 ++++++++++++++++++---------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index e5d5d7a5..6f09b1d4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,6 +10,8 @@ "Atomics": "readonly", "SharedArrayBuffer": "readonly", "hexo": "readonly", + "location": "readonly", + "navigator": "readonly", "Stun": "readonly", "CONFIG": "readonly" }, diff --git a/layout/_partials/config.pug b/layout/_partials/config.pug index 5a59e7cc..bd1132c9 100644 --- a/layout/_partials/config.pug +++ b/layout/_partials/config.pug @@ -158,6 +158,7 @@ script. var Stun = window.Stun || {}; var CONFIG = { root: '!{ config.root }', + author: '!{ theme.rootConfig.author }', algolia: !{ algolia }, assistSearch: !{ assistSearch }, fontIcon: !{ fontIcon }, diff --git a/package.json b/package.json index 1fd2c48f..62c815c4 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "CONFIG", "hexo", "Stun", + "location", + "navigator", "instantsearch" ] }, diff --git a/source/js/utils.js b/source/js/utils.js index 63febe06..4775fb80 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -291,21 +291,29 @@ Stun.utils = Stun.$u = { selection.addRange(range) var text = selection.toString() - var input = document.createElement('input') - // Create a temporary input to make the - // execCommand command take effect. - input.style.display = 'none' - input.setAttribute('readonly', 'readonly') - input.setAttribute('value', text) - document.body.appendChild(input) - input.setSelectionRange(0, -1) - if (document.execCommand('copy')) { + if (navigator.clipboard && navigator.clipboard.writeText) { + console.log('CONFIG: ', CONFIG) + var currentText = text + ` +// 作者:${CONFIG.author} +// 地址:${location.href}` + navigator.clipboard.writeText(currentText).then(() => { + console.log('success') + }) + return true + } else if (document.execCommand) { + var input = document.createElement('input') + // Create a temporary input to make the + // execCommand command take effect. + input.style.display = 'none' + input.setAttribute('readonly', 'readonly') + input.setAttribute('value', text) + document.body.appendChild(input) + input.setSelectionRange(0, -1) document.execCommand('copy') document.body.removeChild(input) return true } - document.body.removeChild(input) } catch (e) { return false } From 3ec72e657b10aafe8b8788f80abfc114068b9ad7 Mon Sep 17 00:00:00 2001 From: Jarvan Date: Fri, 1 Sep 2023 17:43:58 +0800 Subject: [PATCH 3/3] feat: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad80b6f9..2bb5795e 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ - [MikyMing's Blog](https://mikyming.online/) - [Gemini's Blog](https://geminiplanet.cn/) - [TimeMachine's Blog](https://timemachine.icu/) -- [Jiangyh's Blog](https://bestjarvan.gitee.io/) +- [Jiangyh's Blog](https://jiangyh.cn/) - [Frank's Blog](https://shufanhao.top/) 如果你准备长期使用 «Stun» 主题,并希望展示在这里,你只需在 [README](https://github.com/liuyib/hexo-theme-stun/edit/master/README.md) 中填入你的网站,然后提交 PR 即可。