From 7cf21348bf5fbfe7e73894a8b4b9d56c6ca71ec0 Mon Sep 17 00:00:00 2001 From: yoNico21 <119441054+yoNico21@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:58:54 +0200 Subject: [PATCH] css styling updated, added check for user mobile --- 1000_bots_webextension/background.js | 85 +++++++-- 1000_bots_webextension/background_chrome.js | 85 +++++++-- 1000_bots_webextension/background_ff.js | 33 ++-- 1000_bots_webextension/checkUser.js | 35 ++++ 1000_bots_webextension/content.js | 18 +- 1000_bots_webextension/content_chrome.js | 16 +- 1000_bots_webextension/content_ff.js | 16 +- .../fonts/texgyreheros-bolditalic.woff | Bin 0 -> 70424 bytes 1000_bots_webextension/manifest.json | 13 +- 1000_bots_webextension/manifest_chrome.json | 13 +- 1000_bots_webextension/manifest_ff.json | 8 +- 1000_bots_webextension/package_me.sh | 2 +- .../refused_to_be_human-0.0.3.xpi | Bin 12032 -> 24167 bytes .../refused_to_be_human-0.0.3.zip | Bin 12718 -> 24852 bytes .../refused_to_be_human-0.0.4.xpi | Bin 0 -> 166221 bytes .../refused_to_be_human-0.0.4.zip | Bin 0 -> 167272 bytes 1000_bots_webextension/rtbh_style.css | 126 +++++++++++++ 1000_bots_webextension/style.css | 171 ------------------ 18 files changed, 367 insertions(+), 254 deletions(-) create mode 100644 1000_bots_webextension/checkUser.js create mode 100644 1000_bots_webextension/fonts/texgyreheros-bolditalic.woff create mode 100644 1000_bots_webextension/packaged/refused_to_be_human-0.0.4/refused_to_be_human-0.0.4.xpi create mode 100644 1000_bots_webextension/packaged/refused_to_be_human-0.0.4/refused_to_be_human-0.0.4.zip create mode 100644 1000_bots_webextension/rtbh_style.css delete mode 100644 1000_bots_webextension/style.css diff --git a/1000_bots_webextension/background.js b/1000_bots_webextension/background.js index 286273c..6f5ca8d 100644 --- a/1000_bots_webextension/background.js +++ b/1000_bots_webextension/background.js @@ -20,13 +20,13 @@ "use strict"; -const DEBUG = false; +const DEBUG = true; // Use chrome or browser depending on the environment const browser = chrome || browser; // Custom user-agent to spoof Googlebot -const user_agent = +let user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; const target_urls = "*://*/*"; @@ -43,6 +43,38 @@ browser.storage.sync console.error("Error setting duration:", error); }); +function check_user_agent() { + // On active tab execute script + browser.tabs + .query({ active: true, currentWindow: true }) + .then((tabs) => { + browser.scripting.executeScript({ + target: { tabId: tabs[0].id }, + files: ["checkUser.js"], + }); + }) + .catch((error) => { + console.error(`Failed to execute script: ${error}`); + }); +} + +function if_user_agent_mobile() { + // Get boolean from storage + browser.storage.sync.get("isMobile").then((result) => { + if (result.isMobile) { + if (DEBUG) + console.log("User is on a mobile device, changing userAgent."); + user_agent = + "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; + if (DEBUG) console.log("User-Agent set to mobile device."); + if (DEBUG) console.log("User-Agent:", user_agent); + } else { + if (DEBUG) + console.log("User is not on a mobile device. Continuing..."); + } + }); +} + // Set extension status to ON function set_extension_status_ON() { browser.storage.sync @@ -56,6 +88,14 @@ function set_extension_status_ON() { title: "You are now surfing the web as a bot 🤖", }); }) + .then(() => { + // Check if the user is on a mobile device + check_user_agent(); + }) + .then(() => { + // If the user is on a mobile device change the user-agent + if_user_agent_mobile(); + }) .then(() => { // Start user-agent spoofing return startUserAgentSpoofing(); @@ -183,14 +223,21 @@ function stopUserAgentSpoofing() { function refreshAllTabs() { return browser.tabs.query({}).then((tabs) => { tabs.forEach((tab) => { - browser.tabs - .reload(tab.id) - .then(() => { - if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); - }) - .catch((error) => { - console.error(`Error refreshing tab ${tab.id}:`, error); - }); + if (tab.url.startsWith("https://")) { + browser.tabs + .reload(tab.id) + .then(() => { + if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); + }) + .catch((error) => { + console.error(`Error refreshing tab ${tab.id}:`, error); + }); + } else { + if (DEBUG) + console.log( + `Skipped refreshing tab ${tab.id} (URL does not start with "https://")` + ); + } }); }); } @@ -215,20 +262,24 @@ function injectContentScript() { `Content script injected into tab ${tab.id}` ); - // Use a hardcoded duration for removal - const duration = 80000; // 8 seconds or whatever you need - // Set a timeout to remove the content after the hardcoded duration setTimeout(() => { - browser.storage.sync.set({ - bannerInjected: true, - }); + browser.storage.sync + .set({ + bannerInjected: true, + }) + .then(() => { + if (DEBUG) + console.log( + "Banner injected flag set to true." + ); + }); if (DEBUG) console.log( "Duration expired. Removing content." ); removeInjectedContent(); // Ensure this is defined - }, duration); + }, DISPLAY_DURATION); }) .catch((error) => { console.error( diff --git a/1000_bots_webextension/background_chrome.js b/1000_bots_webextension/background_chrome.js index 286273c..6f5ca8d 100644 --- a/1000_bots_webextension/background_chrome.js +++ b/1000_bots_webextension/background_chrome.js @@ -20,13 +20,13 @@ "use strict"; -const DEBUG = false; +const DEBUG = true; // Use chrome or browser depending on the environment const browser = chrome || browser; // Custom user-agent to spoof Googlebot -const user_agent = +let user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; const target_urls = "*://*/*"; @@ -43,6 +43,38 @@ browser.storage.sync console.error("Error setting duration:", error); }); +function check_user_agent() { + // On active tab execute script + browser.tabs + .query({ active: true, currentWindow: true }) + .then((tabs) => { + browser.scripting.executeScript({ + target: { tabId: tabs[0].id }, + files: ["checkUser.js"], + }); + }) + .catch((error) => { + console.error(`Failed to execute script: ${error}`); + }); +} + +function if_user_agent_mobile() { + // Get boolean from storage + browser.storage.sync.get("isMobile").then((result) => { + if (result.isMobile) { + if (DEBUG) + console.log("User is on a mobile device, changing userAgent."); + user_agent = + "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; + if (DEBUG) console.log("User-Agent set to mobile device."); + if (DEBUG) console.log("User-Agent:", user_agent); + } else { + if (DEBUG) + console.log("User is not on a mobile device. Continuing..."); + } + }); +} + // Set extension status to ON function set_extension_status_ON() { browser.storage.sync @@ -56,6 +88,14 @@ function set_extension_status_ON() { title: "You are now surfing the web as a bot 🤖", }); }) + .then(() => { + // Check if the user is on a mobile device + check_user_agent(); + }) + .then(() => { + // If the user is on a mobile device change the user-agent + if_user_agent_mobile(); + }) .then(() => { // Start user-agent spoofing return startUserAgentSpoofing(); @@ -183,14 +223,21 @@ function stopUserAgentSpoofing() { function refreshAllTabs() { return browser.tabs.query({}).then((tabs) => { tabs.forEach((tab) => { - browser.tabs - .reload(tab.id) - .then(() => { - if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); - }) - .catch((error) => { - console.error(`Error refreshing tab ${tab.id}:`, error); - }); + if (tab.url.startsWith("https://")) { + browser.tabs + .reload(tab.id) + .then(() => { + if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); + }) + .catch((error) => { + console.error(`Error refreshing tab ${tab.id}:`, error); + }); + } else { + if (DEBUG) + console.log( + `Skipped refreshing tab ${tab.id} (URL does not start with "https://")` + ); + } }); }); } @@ -215,20 +262,24 @@ function injectContentScript() { `Content script injected into tab ${tab.id}` ); - // Use a hardcoded duration for removal - const duration = 80000; // 8 seconds or whatever you need - // Set a timeout to remove the content after the hardcoded duration setTimeout(() => { - browser.storage.sync.set({ - bannerInjected: true, - }); + browser.storage.sync + .set({ + bannerInjected: true, + }) + .then(() => { + if (DEBUG) + console.log( + "Banner injected flag set to true." + ); + }); if (DEBUG) console.log( "Duration expired. Removing content." ); removeInjectedContent(); // Ensure this is defined - }, duration); + }, DISPLAY_DURATION); }) .catch((error) => { console.error( diff --git a/1000_bots_webextension/background_ff.js b/1000_bots_webextension/background_ff.js index 3680bca..42bbcd4 100644 --- a/1000_bots_webextension/background_ff.js +++ b/1000_bots_webextension/background_ff.js @@ -26,7 +26,7 @@ var user_agent = var target_urls = "*://*/*"; var status = 0; -const DEBUG = false; // Set to true to enable debug mode +const DEBUG = true; // Set to true to enable debug mode // Duration to display the injected HTML (in milliseconds) const DISPLAY_DURATION = 8000; // Set to 8 seconds @@ -137,16 +137,23 @@ function removeInjectedContent() { function refreshAllTabs() { browser.tabs.query({}, (tabs) => { tabs.forEach((tab) => { - browser.tabs.reload(tab.id, () => { - if (browser.runtime.lastError) { - console.error( - `Error refreshing tab ${tab.id}:`, - browser.runtime.lastError + if (tab.url.startsWith("https://")) { + browser.tabs.reload(tab.id, () => { + if (browser.runtime.lastError) { + console.error( + `Error refreshing tab ${tab.id}:`, + browser.runtime.lastError + ); + } else { + if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); + } + }); + } else { + if (DEBUG) + console.log( + `Skipped refreshing tab ${tab.id} (URL does not start with https://)` ); - } else { - if (DEBUG) console.log(`Refreshed tab: ${tab.id}`); - } - }); + } }); }); } @@ -158,7 +165,11 @@ function set_extension_status_ON() { browser.browserAction.setTitle({ title: "You are now surfing the web as a bot 🤖", }); - injectContentScript(); + refreshAllTabs(); + + setTimeout(() => { + injectContentScript(); + }, 500); } function set_extension_status_OFF() { diff --git a/1000_bots_webextension/checkUser.js b/1000_bots_webextension/checkUser.js new file mode 100644 index 0000000..61f0010 --- /dev/null +++ b/1000_bots_webextension/checkUser.js @@ -0,0 +1,35 @@ +function isAgentMobile() { + const regex = + /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i; + return regex.test(navigator.userAgent); +} + +function hasTouchSupport() { + return "ontouchstart" in window || navigator.maxTouchPoints > 0; +} + +function isMobileScreen() { + const minWidth = 768; // Minimum width for desktop devices + return window.innerWidth < minWidth || screen.width < minWidth; +} + +function isMobile() { + // Check if at least 2 of the 3 conditions are true + + const isMobileAgent = isAgentMobile(); // Renamed variable to avoid conflict + const touchSupport = hasTouchSupport(); // Renamed variable to avoid conflict + const mobileScreen = isMobileScreen(); // Renamed variable to avoid conflict + + const conditions = [isMobileAgent, touchSupport, mobileScreen]; + const trueConditions = conditions.filter((condition) => condition); + + return trueConditions.length >= 2; // Return true if at least 2 conditions are true +} + +const user = isMobile(); + +// Check if the user is on a mobile device +if (user) { + if (DEBUG) console.log("User is on a mobile device, changing userAgent."); + browser.storage.sync.set({ isMobile: user }); +} diff --git a/1000_bots_webextension/content.js b/1000_bots_webextension/content.js index f9c47f9..ff4c33f 100644 --- a/1000_bots_webextension/content.js +++ b/1000_bots_webextension/content.js @@ -5,7 +5,7 @@ let DEBUG; // Declare the DEBUG variable in the outer scope browser.storage.sync.get("debug").then((result) => { DEBUG = result.debug; - console.log("DEBUG mode:", DEBUG); + if (DEBUG) console.log("DEBUG mode:", DEBUG); }); // Duration to show the banner (in milliseconds) @@ -37,7 +37,7 @@ function initializeCSSProperties(result) { function injectCSS() { // Inject the CSS file const link = document.createElement("link"); - link.href = browser.runtime.getURL("style.css"); + link.href = browser.runtime.getURL("rtbh_style.css"); link.rel = "stylesheet"; document.head.appendChild(link); @@ -48,17 +48,15 @@ function injectCSS() { function createBanner() { // Create the banner container const banner = document.createElement("div"); - banner.classList.add("extension-banner-container"); + banner.classList.add("banner"); const marqeeText = "YOU ARE NOW SURFING THE WEB AS A BOT 🤖 "; const bannerContent = ` -