Skip to content

Commit

Permalink
fix: 支持知乎、微博等的页面跳转
Browse files Browse the repository at this point in the history
  • Loading branch information
damonchen committed Jan 24, 2021
1 parent b021f1b commit 89200fc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# auto-jump
自动跳转页面
32 changes: 32 additions & 0 deletions content-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 必须设置run_at=document_start才能执行
document.addEventListener('DOMContentLoaded', function() {
// 注入自定义JS
// injectCustomJs();
var host = location.host;
if(host === 'link.zhihu.com') {
var button = document.querySelector('.actions > a');
if(!!button) {
button.click();
}
} else if (host === 't.cn') {
var button = document.querySelector('.open-url > a');
if(!!button) {
button.click();
}
}
})


function injectCustomJs(jsPath) {
jsPath = jsPath || 'js/inject.js';
var temp = document.createElement('script');
temp.setAttribute('type', 'text/javascript');
// 获得的地址类似:chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
temp.src = chrome.extension.getURL(jsPath);
// temp.onload = function()
// {
// // 放在页面不好看,执行完后移除掉
// this.parentNode.removeChild(this);
// };
document.body.appendChild(temp);
}
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added js/inject.js
Empty file.
33 changes: 33 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"manifest_version": 2,
"name": "auto jump",
"version": "1.0",
"description": "这是一个用来自动跳转知乎、微博的页面的插件",
"author": "damonchen(netubu@gmail.com)",
"icons":
{
"48": "icon.png",
"128": "icon.png"
},
"browser_action":
{
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://*/*", // 可以通过executeScript或者insertCSS访问的网站
"https://*/*" // 可以通过executeScript或者insertCSS访问的网站
],
"content_scripts":
[
{
"matches": [ "http://*/*", "https://*/*" ],
"js": ["content-script.js"],
"run_at": "document_start"
}
],
"web_accessible_resources":
[
"inject.js"
]
}
13 changes: 13 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>自动跳转</title>
</head>
<body style="width:500px;min-height:20px;">
<p>
支持知乎,微博等的页面的自动跳转
</p>
<script type="text/javascript" src="js/popup.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('你好,我是popup!');

0 comments on commit 89200fc

Please sign in to comment.