diff --git a/README.md b/README.md index e98c6e2..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# auto-jump -自动跳转页面 diff --git a/content-script.js b/content-script.js new file mode 100755 index 0000000..b9d8760 --- /dev/null +++ b/content-script.js @@ -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); +} \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..3921426 Binary files /dev/null and b/icon.png differ diff --git a/js/inject.js b/js/inject.js new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json new file mode 100755 index 0000000..ab4936e --- /dev/null +++ b/manifest.json @@ -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" + ] +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100755 index 0000000..6ea31f9 --- /dev/null +++ b/popup.html @@ -0,0 +1,13 @@ + + + + + 自动跳转 + + +

+ 支持知乎,微博等的页面的自动跳转 +

+ + + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100755 index 0000000..8ee098e --- /dev/null +++ b/popup.js @@ -0,0 +1 @@ +console.log('你好,我是popup!'); \ No newline at end of file