Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaoy1 committed Dec 3, 2020
1 parent 217b9de commit 6894f98
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Nonstop
Nonstop 是一个 chrome 扩展,用于无感跳转到知乎,微博,简书等无法直接跳转的外链,免去手动跳转的烦恼。
Nonstop 是一个 chrome 扩展,用于无感跳转到知乎,微博,简书等无法直接跳转的外链,免去手动跳转的烦恼;同时支持拦截知乎登录弹窗

## 使用方法
1. 通过 Edge 扩展应用商店[安装](https://microsoftedge.microsoft.com/addons/detail/nonstop/ncjhljkmeagghpgekhdkaedcbippeaog?hl=zh-CN)
2. 手动安装,[下载](https://github.com/Yuxiaoy1/nonstop/releases/tag/0.1.0) crx 扩展文件,在chrome内核的浏览器扩展页面手动添加。
2. 手动安装,[下载](https://github.com/Yuxiaoy1/nonstop/releases/tag/0.2.0) crx 扩展文件,在chrome内核的浏览器扩展页面手动添加。

## 测试
安装扩展后,点击下方三个链接,均可自动跳转:
* 知乎外链:[https://link.zhihu.com/?target=https%3A//yuxiaoy.com/](https://link.zhihu.com/?target=https%3A//yuxiaoy.com/)
* 简书外链:[https://www.jianshu.com/go-wild?ac=2&url=https%3A%2F%2Fyuxiaoy.com%2F](https://www.jianshu.com/go-wild?ac=2&url=https%3A%2F%2Fyuxiaoy.com%2F)
* 微博外链:[http://t.cn/A6b1HjVM?u=1802713725&m=4563585797724502&cu=1802713725](http://t.cn/A6b1HjVM?u=1802713725&m=4563585797724502&cu=1802713725)
* 微博外链:[http://t.cn/A6Gsm8pD](http://t.cn/A6Gsm8pD)

## 免责声明
本扩展开发仅用于学习,严禁任何商业用途。
使用本扩展即代表同意承担由于跳转带来的任意后果,若造成损失与本扩展无关。
安装本扩展即代表同意承担使用带来的任意后果,若造成损失与本扩展无关。
25 changes: 12 additions & 13 deletions nonstop/content-script.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
(function() {
'use strict'
let href = window.location.href
if (href.indexOf('www.zhihu.com/question/') != -1) {
// close zhihu login page when not logged
window.onload = () => {
let btn = document.querySelector('.Button.Modal-closeButton.Button--plain')
if (btn) {
btn.click()
}
return
}
}
// redirect for zhihu, weibo sites
let link = document.querySelector('.link')
let url = link ? link.textContent : ''
if (url) {
window.location.href = url
return
}

// redirect for jianshu site
function getParams(field) {
let href = window.location.href
let getParams = field => {
let urlObject = new URL(href)
let res = urlObject.searchParams.get(field)
return res
}
url = getParams('url')
if (url) {
window.location.href = url
return
}

// show alert message if there is not valid url
alert('Nonstop提醒:没有合法的外链,请重试或手动跳转')

// let body = document.body
// let ele = document.createElement('div')
// ele.innerHTML = `<p style="text-align:center;color:red;">
// 没有合法的外链,请重试或手动跳转</p>`
// body.insertBefore(ele, body.firstChild)
})();
10 changes: 7 additions & 3 deletions nonstop/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "Nonstop",
"version": "0.1.1",
"description": "无感直达知乎,微博,简书等无法直接跳转的外链,免去手动跳转的烦恼。",
"version": "0.2.0",
"description": "无感直达知乎,微博,简书等无法直接跳转的外链,免去手动跳转的烦恼;同时支持拦截知乎登录弹窗",
"author": "yuxiaoy",
"icons": {
"48": "icon.png",
Expand All @@ -13,7 +13,11 @@
"default_icon": "icon.png"
},
"content_scripts": [{
"matches": ["https://link.zhihu.com/?target=*", "http://t.cn/*", "https://www.jianshu.com/go-wild?ac=2&url=*"],
"matches": ["*://link.zhihu.com/?target=*",
"*://t.cn/*",
"*://www.jianshu.com/go-wild?ac=2&url=*",
"*://www.zhihu.com/question/*"
],
"js": ["content-script.js"]
}]
}

0 comments on commit 6894f98

Please sign in to comment.