diff --git a/packages/shell-chrome/assets/js/content.js b/packages/shell-chrome/assets/js/content.js index 54949dc..787d11c 100644 --- a/packages/shell-chrome/assets/js/content.js +++ b/packages/shell-chrome/assets/js/content.js @@ -1 +1,14 @@ console.log("[BitDance extension] 学生助手插件已启用") + +// 每次改变开关状态时刷新页面使功能及时生效 +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + console.log(`进入 assets\js\content.js 中的onMessage Listener`) + + if (request.action === 'refreshPage') { + location.reload(); + sendResponse('Reload page because of ' + request.info); + } + + console.log(`离开 assets\js\content.js 中的onMessage Listener`) + return true; +}) diff --git a/packages/shell-chrome/assets/js/direct-url/url.js b/packages/shell-chrome/assets/js/direct-url/url.js index 471567d..7c562ad 100644 --- a/packages/shell-chrome/assets/js/direct-url/url.js +++ b/packages/shell-chrome/assets/js/direct-url/url.js @@ -1,8 +1,8 @@ window.onload = function(){ console.log("[BitDance extension] 学生助手插件 - 确认跳转页直接跳转模块加载成功"); - chrome.storage.sync.get("linkOpen", ({ linkOpen })=>{ - if(linkOpen){ + chrome.storage.sync.get("State_DirectUrl", ({ State_DirectUrl })=>{ + if(State_DirectUrl){ let locHost = location.host,locHref = location.href; let methods = { @@ -88,21 +88,21 @@ window.onload = function(){ setTimeout(url(),200); - function url(){ + function url() { let flag = false; - if(locHref.includes(RedirectPage.sites[locHost].include)){ + if(locHref.includes(RedirectPage.sites[locHost].include)) { locHref = locHref.split(RedirectPage.sites[locHost].include); flag = true; } - - if(flag){ + + if(flag) { location.replace(decodeURIComponent(locHref[1])); - }else{ + } else { //改进 - if(RedirectPage.sites[locHost].selector){ + if(RedirectPage.sites[locHost].selector) { let target = document.querySelector(RedirectPage.sites[locHost].selector); - location.replace(target.href || target.innerText) - } + location.replace(target.href || target.innerText) + } } } diff --git a/packages/shell-chrome/assets/js/mouse-effects/click.js b/packages/shell-chrome/assets/js/mouse-effects/click.js index 6dadbdb..626e9d4 100644 --- a/packages/shell-chrome/assets/js/mouse-effects/click.js +++ b/packages/shell-chrome/assets/js/mouse-effects/click.js @@ -4,24 +4,10 @@ $(function() { console.log("[BitDance extension] 学生助手插件 - 点击特效模块加载成功"); - - // 每次改变开关状态时刷新页面使功能及时生效 - chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - // console.log(`进入 assets\js\mouse-effects\click.js 中的onMessage Listener`) - - if (request.info === 'click') { - location.reload(); - sendResponse('Reload page because of click'); - } - - // console.log(`离开 assets\js\mouse-effects\click.js 中的onMessage Listener`) - return true; - }) - // 控制功能是否开启 - chrome.storage.sync.get('clickState3', function(budget) { + chrome.storage.sync.get('State_MouseEffect', function(budget) { // 得到按钮开关状态 - if (budget.clickState3 == false || budget.clickState3 == undefined) { + if (budget.State_MouseEffect == false || budget.State_MouseEffect == undefined) { // console.log('click功能启动'); var hearts = []; @@ -98,4 +84,4 @@ $(function() { } } }); -}) \ No newline at end of file +}) diff --git a/packages/shell-chrome/assets/js/mouse-effects/mouse-style.js b/packages/shell-chrome/assets/js/mouse-effects/mouse-style.js index 8e4f4c1..c3494be 100644 --- a/packages/shell-chrome/assets/js/mouse-effects/mouse-style.js +++ b/packages/shell-chrome/assets/js/mouse-effects/mouse-style.js @@ -4,23 +4,10 @@ $(function() { console.log("[BitDance extension] 学生助手插件 - 鼠标样式模块加载成功"); - // 每次改变开关状态时刷新页面使功能及时生效 - chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - // console.log(`进入 assets\js\mouse-effects\mouse-style.js 中的onMessage Listener`) - - if (request.info === 'mouse') { - location.reload(); - sendResponse('Reload page because of mouse-style'); - } - - // console.log(`离开 assets\js\mouse-effects\mouse-style.js 中的onMessage Listener`) - return true; - }) - // 控制功能是否开启 - chrome.storage.sync.get('clickState2', function(budget) { + chrome.storage.sync.get('State_MouseStyle', function(budget) { // 得到按钮开关状态 - if (budget.clickState2 == false || budget.clickState2 == undefined) { + if (budget.State_MouseStyle == false || budget.State_MouseStyle == undefined) { let style = document.getElementsByTagName('style'); // console.log(style[0]); let css = "* {curs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2f/dDgcDYH6%0AiQlgqLKycmh4eJhFdzi0SFlZmaO9vZ2qr6/38H2RSARvb28JkiQj5ubmHB0d%0AHc4qZGdn205OTlJceodUAQzDKGQcaWlpdp1O5zMNLmPp6uoiULPNzMyw0G96%0AvZ64uroCubm5OI/Hc49eMAjvCkRJpdJ/l5eX2fn5+Xa1Wu0DUFhYSCqVSqf9%0ASiQSQq1Ws6Ojo6FCoYBSqZRRnjeIH4JaMQDgc29v7+XU1FSk0WgkHx4ePA4a%0AlLSxsZFYWFhg0UetqamJnJiYwAQCAaPp0OTwgfDpAdTJT09PzoWYZMBxHPpz%0At2DmlZWVZTs/P/eAYDIis8lkike7KSoqsh0cHKBrlvNB9trW1gY0Go37BOzp%0A6bFNT0+73wkXwt8YIm8nMjIyMLPZ7JThzT7Z9N2jOedyuX+kp6dXHR8fvwvC%0A73UpMjJyxuFw/AwAcMoxODhIeJ9qSUlJdqPRiBILxWLxZTgQKSkpdr1eHxXw%0AvvZWzl2Kokq9S4vslc/n99EcLiyIycnJ1/7+/u9DAfi8u7v7rbS01GPEuFyu%0Aw2q1ehgSupKLxeLrYJVYX1931NXVyQEA46EAgLi4ONvd3Z3bE9CplpOTU+F9%0AsLxVKSAEPbm/05CpkT1kYLFYLxDCQHeGT5mZmddnZ2cejemdPBwAtwxoGlpb%0AW5MD+burEnQIpuThAIDY2Fj74+NjJI7jFnSTCTbvdIjOzk68u7t7GGnuHRdS%0AD7gWw3H8NwhhT4jJ6a8hKWxMcf8BWQiA/lSw+WUAAAAASUVORK5CYII=), auto}=" @@ -38,4 +25,4 @@ $(function() { }); } }) -}) \ No newline at end of file +}) diff --git a/packages/shell-chrome/assets/js/popup.js b/packages/shell-chrome/assets/js/popup.js index bcb8e25..bfb4c72 100644 --- a/packages/shell-chrome/assets/js/popup.js +++ b/packages/shell-chrome/assets/js/popup.js @@ -1,18 +1,101 @@ $(function() { - // 获取开关状态 - chrome.storage.sync.get('clickState2', function(budget) { - // 获取页面节点 - let input = document.querySelector("#button-2"); - // 改变开关状态(保持与上次设置时一致) - input.checked = budget.clickState2; + /** + * 鼠标样式 + */ + // 页面加载时,更新界面开关状态 + chrome.storage.sync.get('State_MouseStyle', function(budget) { + document.querySelector("#btnMouseStyle").checked = budget.State_MouseStyle; }); - // 获取开关状态 - chrome.storage.sync.get('clickState3', function(budget) { - // 获取页面节点 - let input = document.querySelector("#button-3"); - // 改变开关状态(保持与上次设置时一致) - input.checked = budget.clickState3; + + // 点击开关时存储按钮状态并刷新页面 + $("#btnMouseStyle").click(function() { + chrome.storage.sync.set({ 'State_MouseStyle': $("#btnMouseStyle")[0].checked }); + refreshPage('Mouse Style'); }); + + + /** + * 鼠标特效 + */ + // 页面加载时,更新界面开关状态 + chrome.storage.sync.get('State_MouseEffect', function(budget) { + document.querySelector("#btnMouseEffect").checked = budget.State_MouseEffect; + }); + + // 点击开关时存储按钮状态并刷新页面 + $("#btnMouseEffect").click(function() { + chrome.storage.sync.set({ 'State_MouseEffect': $("#btnMouseEffect")[0].checked }); + refreshPage('Mouse Effect'); + }) + + + /** + * 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; + chrome.extension.getBackgroundPage().updateAdsBlockStatus(!btnGoogleAds.checked); + }); + + // 点击开关时存储按钮状态并刷新页面 + $("#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(); + } + }) + }); + + + /** + * 翻译 + */ + 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); @@ -26,73 +109,6 @@ $(function() { } }); - // 点击开关时改变按钮状态 - $("#button-2").click(function() { - // 获取开关 - let checked = $("#button-2"); - // 持久化存储开关状态 - chrome.storage.sync.set({ 'clickState2': checked[0].checked }); - - // 自动刷新页面 - chrome.tabs.query({ - active: true, - currentWindow: true - }, (tabs) => { - console.log(tabs); - let message = { - info: 'mouse' - } - chrome.tabs.sendMessage(tabs[0].id, message, res => { - console.log(res); - }) - }) - }); - - // 点击开关时改变按钮状态 - $("#button-3").click(function() { - // 获取开关 - let checked = $("#button-3"); - // 持久化存储开关状态 - chrome.storage.sync.set({ 'clickState3': checked[0].checked }); - - // 自动刷新页面 - chrome.tabs.query({ - active: true, - currentWindow: true - }, (tabs) => { - console.log(tabs); - let message = { - info: 'click' - } - chrome.tabs.sendMessage(tabs[0].id, message, res => { - console.log(res); - }) - }) - }) - - // Direct Url - const btnDirectUrl = document.querySelector("#btnDirectUrl"); - chrome.storage.sync.get("linkOpen", ({ linkOpen }) => { - btnDirectUrl.checked = !linkOpen; - }); - - btnDirectUrl.addEventListener("change", () => { - chrome.storage.sync.set({ linkOpen: !btnDirectUrl.checked }); - }); - - // 截图 - 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(); - } - }) - }); - - // 番茄钟 $('#clock').click(function() { $('#pomodoro').fadeIn(500); $('#article').fadeOut(0); @@ -107,17 +123,7 @@ $(function() { chrome.storage.sync.set({ "clockState": "none" }); }) - //翻译 - 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:// 开头的链接 @@ -127,4 +133,23 @@ $(function() { 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); + }) + }) + } }) diff --git a/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js b/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js index 6377e79..10d8cbc 100644 --- a/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js +++ b/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js @@ -1,8 +1,15 @@ +var AdsBlockStatus = true; // refer: https://www.it1352.com/1996113.html chrome.webRequest.onBeforeRequest.addListener( function (details) { + console.log("AdsBlock Status: ", AdsBlockStatus); + + if (!AdsBlockStatus) + return { cancel: false }; // 如果没有开启此功能,不处理 + if (!details || !details.initiator || !details.url) return { cancel: false }; // 如果没有请求信息,则可能是chrome://开头的页面,不处理 + let isBlock = false || details.initiator === "https://googleads.g.doubleclick.net" || details.initiator.indexOf("googleads.g.doubleclick.net") != -1 @@ -13,10 +20,22 @@ chrome.webRequest.onBeforeRequest.addListener( || details.url.indexOf("adservice.google.com") != -1 || details.url.indexOf("googleads") != -1 || details.url.indexOf("adsbygoogle") != -1 + if (isBlock) // 拦截后打印到控制台显示 console.log(isBlock ? "block" : "allow", details) + return { cancel: isBlock }; }, { urls: [""] }, ["blocking"] ); + +// 由于上方拦截函数不可以是异步函数,所以设置变更后需要及时调用此函数 +var updateAdsBlockStatus = (status) => { + AdsBlockStatus = !!status; +} + +// 插件刚开始加载时,先读取一次状态 +chrome.storage.sync.get('State_AdsBlock', function (State) { + updateAdsBlockStatus(State.State_AdsBlock); +}); diff --git a/packages/shell-chrome/popup.html b/packages/shell-chrome/popup.html index de9d623..e5f8c8b 100644 --- a/packages/shell-chrome/popup.html +++ b/packages/shell-chrome/popup.html @@ -64,9 +64,9 @@