1
0
mirror of https://gitee.com/bitdance-team/chrome-extension synced 2025-01-31 15:30:25 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

155 lines
4.7 KiB
JavaScript
Raw Normal View History

2022-02-05 11:13:22 +08:00
$(function() {
/**
* 鼠标样式
*/
// 页面加载时,更新界面开关状态
chrome.storage.sync.get('State_MouseStyle', function(budget) {
document.querySelector("#btnMouseStyle").checked = budget.State_MouseStyle;
2022-02-05 13:43:37 +08:00
});
// 点击开关时存储按钮状态并刷新页面
$("#btnMouseStyle").click(function() {
chrome.storage.sync.set({ 'State_MouseStyle': $("#btnMouseStyle")[0].checked });
refreshPage('Mouse Style');
2022-02-09 16:45:45 +08:00
});
2022-02-05 11:13:22 +08:00
/**
* 鼠标特效
*/
// 页面加载时,更新界面开关状态
chrome.storage.sync.get('State_MouseEffect', function(budget) {
document.querySelector("#btnMouseEffect").checked = budget.State_MouseEffect;
2022-02-05 13:43:37 +08:00
});
// 点击开关时存储按钮状态并刷新页面
$("#btnMouseEffect").click(function() {
chrome.storage.sync.set({ 'State_MouseEffect': $("#btnMouseEffect")[0].checked });
refreshPage('Mouse Effect');
2022-02-05 13:43:37 +08:00
})
/**
* Direct Url
*/
const btnDirectUrl = document.querySelector("#btnDirectUrl");
// 页面加载时,更新界面开关状态
chrome.storage.sync.get("State_DirectUrl", ({ State_DirectUrl }) => {
btnDirectUrl.checked = !State_DirectUrl;
});
// 点击开关时存储按钮状态并刷新页面
btnDirectUrl.addEventListener("change", () => {
chrome.storage.sync.set({ State_DirectUrl: !btnDirectUrl.checked });
refreshPage('Direct Url');
});
/**
* Google广告拦截
*/
const btnGoogleAds = document.querySelector("#btnAdsBlock");
// 页面加载时,更新界面开关状态
chrome.storage.sync.get('State_AdsBlock', function(budget) {
btnGoogleAds.checked = !budget.State_AdsBlock;
});
// 点击开关时存储按钮状态并刷新页面
$("#btnAdsBlock").click(function() {
chrome.storage.sync.set({ 'State_AdsBlock': !btnGoogleAds.checked });
chrome.extension.getBackgroundPage().updateAdsBlockStatus(!btnGoogleAds.checked);
refreshPage('Ads Block');
})
/**
* 截图
*/
document.getElementById("btnScreenshot").addEventListener("click", () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if(isChromeSettingPage(tabs[0].url)) {
alert("抱歉由于浏览器限制“chrome://”开头的网页不支持截图");
} else {
chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]);
window.close();
}
})
});
2022-02-09 16:45:45 +08:00
/**
* 翻译
*/
document.getElementById("transform").onclick = function () {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if(isChromeSettingPage(tabs[0].url)) {
alert("抱歉由于浏览器限制“chrome://”开头的网页不支持翻译");
} else {
chrome.extension.getBackgroundPage().showTranslationWindow()
window.close();
}
})
}
/**
* 番茄钟
*/
// 获取番茄钟页面状态
chrome.storage.sync.get('clockState', function(budget) {
console.log(budget.clockState);
if (budget.clockState === "block") {
$('#back').css("display", "block");
$('#article').css("display", "none");
$('#pomodoro').css("display", "block");
} else if (budget.clockState === "none") {
$('#article').css("display", "block");
$('#pomodoro').css("display", "none");
}
});
2022-02-09 16:45:45 +08:00
$('#clock').click(function() {
$('#pomodoro').fadeIn(500);
$('#article').fadeOut(0);
$('#back').css("display", "block");
chrome.storage.sync.set({ "clockState": "block" });
});
$('#back').click(function() {
$('#pomodoro').fadeOut(0);
$('#article').fadeIn(200);
$('#back').css("display", "none");
chrome.storage.sync.set({ "clockState": "none" });
})
// ****************************************************************************************************************
/**
* 判断是否是 chrome:// 开头的链接
* @param {} url
* @returns
*/
function isChromeSettingPage(url) {
return /^chrome:\/\/.*$/.test(url);
}
/**
* 改变开关自动刷新页面
*/
function refreshPage(messageInfo) {
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
console.log(tabs);
let message = {
info: messageInfo,
action: "refreshPage"
}
chrome.tabs.sendMessage(tabs[0].id, message, res => {
console.log(res);
})
})
}
2022-02-09 19:30:31 +08:00
})