mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-10-08 00:45:13 +08:00
add files
This commit is contained in:
0
assets/css/main.css
Normal file
0
assets/css/main.css
Normal file
23
assets/js/background.js
Normal file
23
assets/js/background.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// 用户首次安装插件时执行一次,后面不会再重新执行(除非用户重新安装插件)
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
// 插件功能安装默认启用
|
||||
chrome.storage.sync.set({
|
||||
linkOpen: true,
|
||||
});
|
||||
});
|
||||
|
||||
// 监听tab页面加载状态,添加处理事件
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
// 设置判断条件,页面加载完成才添加事件,否则会导致事件重复添加触发多次
|
||||
if (changeInfo.status === "complete" && /^http/.test(tab.url)) {
|
||||
chrome.scripting
|
||||
.executeScript({
|
||||
target: { tabId: tabId },
|
||||
files: ["./content-script.js"],
|
||||
})
|
||||
.then(() => {
|
||||
console.log("INJECTED SCRIPT SUCC.");
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
});
|
5
assets/js/common/jquery.min.js
vendored
Normal file
5
assets/js/common/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
25
assets/js/popup.js
Normal file
25
assets/js/popup.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const btn = document.querySelector("#switch");
|
||||
|
||||
chrome.storage.sync.get("linkOpen", ({ linkOpen }) => {
|
||||
btn.checked = linkOpen;
|
||||
});
|
||||
|
||||
btn.addEventListener("change", () => {
|
||||
if (btn.checked) {
|
||||
chrome.storage.sync.set({ linkOpen: true });
|
||||
} else {
|
||||
chrome.storage.sync.set({ linkOpen: false });
|
||||
}
|
||||
// 获取当前tab窗口
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tabs[0].id },
|
||||
func: refreshPage,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 刷新页面
|
||||
function refreshPage() {
|
||||
window.location.reload();
|
||||
}
|
100
assets/js/url.js
Normal file
100
assets/js/url.js
Normal file
@@ -0,0 +1,100 @@
|
||||
window.onload = function(){
|
||||
|
||||
chrome.storage.sync.get("linkOpen", ({ linkOpen })=>{
|
||||
if(linkOpen){
|
||||
let locHost = location.host,locHref = location.href;
|
||||
|
||||
let methods = {
|
||||
http(link, s = false) {
|
||||
return link.startsWith("http")
|
||||
? link
|
||||
: (s ? "https://" : "http://") + link;
|
||||
},
|
||||
};
|
||||
|
||||
let RedirectPage = {
|
||||
sites: {
|
||||
"c.pc.qq.com": {
|
||||
include: "middlem.html?pfurl=",
|
||||
selector: "#url",
|
||||
},
|
||||
"docs.qq.com": {
|
||||
include: "scenario/link.html?url=",
|
||||
selector: "span.url-src",
|
||||
timeout: 500,
|
||||
},
|
||||
"www.tianyancha.com": {
|
||||
include: "security?target=",
|
||||
selector: "div.security-link",
|
||||
},
|
||||
"jump.bdimg.com": {
|
||||
include: "safecheck/index?url=",
|
||||
selector: "div.warning_info.fl>a",
|
||||
},
|
||||
"jump2.bdimg.com": {
|
||||
include: "safecheck/index?url=",
|
||||
selector: "div.warning_info.fl>a",
|
||||
},
|
||||
"www.chinaz.com": {
|
||||
include: "go.shtml?url=",
|
||||
selector: "div.link-bd__text",
|
||||
},
|
||||
"www.douban.com": {
|
||||
include: "link2/?url=",
|
||||
selector: "a.btn-redir",
|
||||
},
|
||||
"iphone.myzaker.com" : {
|
||||
include: "zaker/link.php?",
|
||||
selector: "a.btn",
|
||||
},
|
||||
"www.itdaan.com": {
|
||||
include: "link/",
|
||||
selector: "a.c-footer-a1",
|
||||
},
|
||||
"link.csdn.net": {
|
||||
include: "?target=",
|
||||
selector: "a.loading-btn",
|
||||
timeout: 100,
|
||||
},
|
||||
"link.zhihu.com":{
|
||||
include :"?target=",
|
||||
selector : "a.button"
|
||||
},
|
||||
"link.juejin.cn": {
|
||||
include: "?target=",
|
||||
selector: 'p[style="margin: 0px;"]',
|
||||
},
|
||||
"www.jianshu.com": {
|
||||
include: "go-wild?ac=2&url=",
|
||||
selector: 'div[title^="http"], div[title^="www"]',
|
||||
},
|
||||
// QQ、腾讯文档、天眼查、百度贴吧、站长之家、豆瓣、Zaker、开发者知识库、CSDN、知乎、掘金、简书etc...
|
||||
},
|
||||
|
||||
redirect(host){
|
||||
let site = this.sites[host];
|
||||
if (site) {
|
||||
let include = host + "/" + site.include;
|
||||
if (locHref.includes(include) || site.match && locHref.match(site.match)) {
|
||||
|
||||
let target = document.querySelector(site.selector);
|
||||
if (target.length) location.replace(target.href || target.innerText);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locHref = locHref.split(RedirectPage.sites[locHost].include);
|
||||
if(locHref){
|
||||
location.replace(decodeURIComponent(locHref[1]));
|
||||
}else{
|
||||
//改进
|
||||
let target = document.querySelector(RedirectPage.sites[locHost].selector);
|
||||
location.replace(target.href || target.innerText)
|
||||
}
|
||||
|
||||
//两种方案 默认不阻止重定向 阻止重定向直接跳转
|
||||
}
|
||||
})
|
||||
}
|
BIN
images/get_started128.png
Normal file
BIN
images/get_started128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
images/get_started16.png
Normal file
BIN
images/get_started16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 495 B |
BIN
images/get_started32.png
Normal file
BIN
images/get_started32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 814 B |
BIN
images/get_started48.png
Normal file
BIN
images/get_started48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
32
manifest.json
Normal file
32
manifest.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name":"助手-directURL",
|
||||
"description":"make href clickable",
|
||||
"version":"0.0",
|
||||
"manifest_version":3,
|
||||
"host_permissions": ["https://*/*","storage", "tabs", "scripting"],
|
||||
"background":{
|
||||
"service_worker":"./assets/js/background.js"
|
||||
},
|
||||
"permissions":["storage","activeTab", "scripting"],
|
||||
"action":{
|
||||
"default_popup":"popup.html",
|
||||
"default_icon":{
|
||||
"16": "./images/get_started16.png",
|
||||
"32": "./images/get_started32.png",
|
||||
"48": "./images/get_started48.png",
|
||||
"128": "./images/get_started128.png"
|
||||
}
|
||||
},
|
||||
"icons": {
|
||||
"16": "./images/get_started16.png",
|
||||
"32": "./images/get_started32.png",
|
||||
"48": "./images/get_started48.png",
|
||||
"128": "./images/get_started128.png"
|
||||
},
|
||||
"content_scripts":[
|
||||
{
|
||||
"matches":["https://*/*"],
|
||||
"js":["./assets/js/url.js"]
|
||||
}
|
||||
]
|
||||
}
|
57
popup.html
Normal file
57
popup.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
.option{
|
||||
padding:30px 0;
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
min-width:160px}
|
||||
.option .name{
|
||||
color:#333;
|
||||
font-size:18px;
|
||||
font-weight:bold
|
||||
}
|
||||
.switch{position:relative;
|
||||
display:inline-block;
|
||||
width:60px;height:34px
|
||||
}
|
||||
.switch input{
|
||||
opacity:0;
|
||||
width:0;
|
||||
height:0
|
||||
}
|
||||
.slider{position:absolute;
|
||||
cursor:pointer;
|
||||
top:0;left:0;right:0;bottom:0;
|
||||
background-color:#ccc;
|
||||
-webkit-transition:.4s;
|
||||
transition:.4s
|
||||
}
|
||||
.slider:before{position:absolute;content:"";
|
||||
height:26px;width:26px;left:4px;bottom:4px;background-color:white;-webkit-transition:.4s;transition:.4s}
|
||||
input:checked+.slider{background-color:#45c7d8}
|
||||
input:focus+.slider{box-shadow:0 0 1px #45c7d8}
|
||||
input:checked+.slider:before{-webkit-transform:translateX(26px);-ms-transform:translateX(26px);transform:translateX(26px)}
|
||||
.slider.round{border-radius:34px}
|
||||
.slider.round:before{border-radius:50%}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="option">
|
||||
<span class="name">开启:</span>
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="switch">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<script src="./assets/js/popup.js"></script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user