1
0
mirror of https://gitee.com/bitdance-team/chrome-extension synced 2025-10-08 16:55:17 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

add files

This commit is contained in:
simonzhangs
2022-01-29 19:54:17 +08:00
parent bf5cb19d0f
commit cbf8a21ddb
11 changed files with 242 additions and 0 deletions

23
assets/js/background.js Normal file
View 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

File diff suppressed because one or more lines are too long

25
assets/js/popup.js Normal file
View 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
View 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)
}
//两种方案 默认不阻止重定向 阻止重定向直接跳转
}
})
}