Skip to content

Commit

Permalink
移动端屏蔽跳转APP
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Jul 18, 2024
1 parent 27dbaba commit e4a44bc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 50 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ https://github.com/027xiguapi/code-box

博客网站在未登录状态下无法复制代码,使用这个插件,无需登录可以一键复制代码。

还支持解除`关注博主即可阅读全文`的提示,隐藏登陆弹窗
还支持解除`关注博主即可阅读全文`的提示,隐藏登录弹窗

完整分析:[谷歌插件:无需登录一键复制 CSDN 代码](https://lwebapp.com/zh/post/copy-csdn)

Expand Down Expand Up @@ -47,7 +47,7 @@ https://github.com/027xiguapi/code-box
1. 打开任意一个`CSDN`博客即可开始复制代码
2. 未登录`CSDN`状态下,支持选中代码
3. 未登录`CSDN`状态下,代码右上角按钮一键复制
4. 未登录`CSDN`状态下,不会再出现强制登陆弹窗
4. 未登录`CSDN`状态下,不会再出现强制登录弹窗
5. 未关注博主状态下,不再提示关注博主即可阅读全文,且完整展示文章
6. 自动展开代码块
7. 移动端屏蔽跳转APP
Expand Down
17 changes: 16 additions & 1 deletion component/csdn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export default function Csdn() {
(v) => (v === undefined ? true : v)
)

const [closeRedirectModal, setCloseRedirectModal] = useStorage(
"csdn-closeLoginModal",
(v) => (v === undefined ? true : v)
)

return (
<fieldset>
<legend>CSDN设置</legend>
Expand Down Expand Up @@ -70,7 +75,17 @@ export default function Csdn() {
checked={closeLoginModal}
onChange={(e) => setCloseLoginModal(e.target.checked)}
/>
<label htmlFor="csdn-closeLoginModal">关闭登陆弹窗</label>
<label htmlFor="csdn-closeLoginModal">关闭登录弹窗</label>
</div>
<div>
<input
type="checkbox"
id="csdn-closeRedirectModal"
name="csdn-closeRedirectModal"
checked={closeRedirectModal}
onChange={(e) => setCloseRedirectModal(e.target.checked)}
/>
<label htmlFor="csdn-closeRedirectModal">关闭跳转APP弹窗</label>
</div>
</fieldset>
)
Expand Down
102 changes: 58 additions & 44 deletions contents/csdn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useEffect, useRef } from "react"

import { useStorage } from "@plasmohq/storage/hook"

import { addCss } from "~tools"

export const config: PlasmoCSConfig = {
matches: ["https://*.blog.csdn.net/*"]
}
Expand All @@ -17,36 +19,35 @@ const csdn = () => {
const [closeFollow] = useStorage<boolean>("csdn-closeFollow")
const [autoOpenCode] = useStorage<boolean>("csdn-autoOpenCode")
const [closeLoginModal] = useStorage<boolean>("csdn-closeLoginModal")
const [closeRedirectModal] = useStorage<boolean>("csdn-closeLoginModal")

useEffect(() => {
console.log("CSDN closeAds", closeAds)
console.log("CSDN status", {
closeAds,
copyCode,
autoOpenCode,
closeFollow,
closeLoginModal,
closeRedirectModal
})
closeAds && closeAdsFunc()
}, [closeAds])

useEffect(() => {
console.log("CSDN copyCode", copyCode)
copyCode && copyCodeFunc()
}, [copyCode])

useEffect(() => {
console.log("CSDN autoOpenCode", autoOpenCode)
autoOpenCode && autoOpenCodeFunc()
}, [autoOpenCode])

useEffect(() => {
console.log("CSDN closeFollow", closeFollow)
closeFollow && followFunc()
}, [closeFollow])

useEffect(() => {
console.log("CSDN closeLoginModal", closeLoginModal)
closeLoginModal && closeLoginModalFunc()
}, [closeLoginModal])
closeRedirectModal && closeRedirectModalFunc()
}, [
closeAds,
copyCode,
autoOpenCode,
closeFollow,
closeLoginModal,
closeRedirectModal
])

/* 未登录复制代码 */
function copyCodeCssFunc() {
let style = document.createElement("style")
const css = document.createTextNode(`
const css = `
#content_views pre,
#content_views pre code {
-webkit-touch-callout: auto !important;
Expand All @@ -55,9 +56,8 @@ const csdn = () => {
-moz-user-select: auto !important;
-ms-user-select: auto !important;
user-select: auto !important;
}`)
style.appendChild(css)
document.head.appendChild(style)
}`
addCss(css)
}

function copyCodeFunc() {
Expand Down Expand Up @@ -103,43 +103,36 @@ const csdn = () => {

// 关闭广告
function closeAdsFunc() {
const style = document.createElement("style")
const css = document.createTextNode(`
const css = `
.toolbar-advert,
#recommendAdBox,
.adsbygoogle {
display:none !important;
}`)
style.appendChild(css)
document.head.appendChild(style)
}`
}

// 解除 关注博主即可阅读全文的提示
const followFunc = () => {
const readMore = document.querySelector(".btn-readmore")
const style = document.createElement("style")
const css = document.createTextNode(`
#article_content{
height: auto !important;
}
.hide-article-box {
z-index: -1 !important;
}`)
if (readMore) {
style.appendChild(css)
document.head.appendChild(style)
const css = `
#article_content{
height: auto !important;
}
.hide-article-box {
z-index: -1 !important;
}`
addCss(css)
}
}

// 隐藏登陆弹窗
// 隐藏登录弹窗
function closeLoginModalFunc() {
const style = document.createElement("style")
const css = document.createTextNode(`
const css = `
.passport-login-container {
display:none !important;
}`)
style.appendChild(css)
document.head.appendChild(style)
}`
addCss(css)
}

// 自动展开代码块
Expand All @@ -153,13 +146,34 @@ const csdn = () => {
document.querySelectorAll<HTMLElement>(".hide-preCode-box")
)

const readallBox = document.querySelector<HTMLElement>(".readall_box")

pres.forEach((pre) => {
pre.style.height = "unset"
pre.style.maxHeight = "unset"
})
presBox.forEach((box) => {
box.style.display = "none"
})

if (readallBox) {
const articleContent =
document.querySelector<HTMLElement>(".article_content")

articleContent.style.height = "unset"
readallBox.style.display = "none"
}
}

// 隐藏移动端跳转APP弹窗
function closeRedirectModalFunc() {
const css = `
.ios-shadowbox,
.feed-Sign-weixin,
.weixin-shadowbox {
display:none !important;
}`
addCss(css)
}

return <div style={{ display: "none" }}></div>
Expand Down
2 changes: 1 addition & 1 deletion contents/zhihu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function zhihu() {
})
}

// 隐藏登陆弹窗
// 隐藏登录弹窗
function closeLoginModalFunc() {
addCss(`
.Modal-wrapper--transparent,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "code-box",
"displayName": "codebox-免登录复制代码(CSDN/知乎/脚本之家/博客园)",
"version": "0.0.5",
"description": "本插件可以用于CSDN/知乎/脚本之家/博客园等网站,实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登陆弹窗.",
"version": "0.0.6",
"description": "本插件可以用于CSDN/知乎/脚本之家/博客园等网站,实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗.",
"author": "027xiguapi. <458813868@qq.com>",
"scripts": {
"dev": "plasmo dev",
Expand Down

0 comments on commit e4a44bc

Please sign in to comment.