-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
2,223 additions
and
908 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,87 @@ | ||
// StopMalwareContent's Source Code for Firefox extension | ||
// Inspired from https://github.com/StopModReposts/Extension | ||
const API_URL = "https://smc.ldne.xyz/sites" | ||
let cachedSites = [] | ||
let ignoreList = [] | ||
const API_URL = "https://smc.ldne.xyz/sites"; | ||
let cachedSites = []; | ||
let ignoreList = []; | ||
let lastBlockedSite = { | ||
domain: "", | ||
reason: "", | ||
notes: "", | ||
path: "", | ||
url: "", | ||
} | ||
}; | ||
|
||
refreshCache() | ||
refreshCache(); | ||
|
||
function refreshCache() { | ||
fetch(API_URL) | ||
.then((response) => response.json()) | ||
.then((response) => { | ||
cachedSites = response | ||
}) | ||
cachedSites = response; | ||
}); | ||
} | ||
|
||
// some complex code | ||
chrome.runtime.onMessage.addListener((message, _, sendResponse) => { | ||
if (message.type === "get-blocked-site") { | ||
return sendResponse(lastBlockedSite) | ||
return sendResponse(lastBlockedSite); | ||
} | ||
if (message.type === "add-to-ignore") { | ||
ignoreList.push(lastBlockedSite.domain) | ||
console.log(ignoreList) | ||
return sendResponse(null) | ||
ignoreList.push(lastBlockedSite.domain); | ||
console.log(ignoreList); | ||
return sendResponse(null); | ||
} | ||
}) | ||
}); | ||
|
||
let lastNavUrl = "" | ||
let lastNavUrl = ""; | ||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { | ||
// If URL is empty, skip | ||
if (!tab.url) return | ||
if (!tab.url) return; | ||
|
||
// If URL has not changed, skip | ||
if (lastNavUrl == tab.url) return | ||
if (lastNavUrl == tab.url) return; | ||
|
||
// Making URL a real URL | ||
const parsed = new URL(tab.url) | ||
const parsed = new URL(tab.url); | ||
|
||
// Getting domain from URL | ||
const host = parsed.host | ||
const host = parsed.host; | ||
|
||
// We will need that for future | ||
lastNavUrl = tab.url | ||
lastNavUrl = tab.url; | ||
|
||
// Check if the site is flagged | ||
const flaggedSites = cachedSites.filter( | ||
(site) => site.domain === host || parsed.host.endsWith(`.${site.domain}`) | ||
) | ||
(site) => site.domain === host || parsed.host.endsWith(`.${site.domain}`), | ||
); | ||
|
||
if (!flaggedSites.length) return | ||
if (!flaggedSites.length) return; | ||
|
||
// Iterate through all flagged sites for this domain | ||
for (const site of flaggedSites) { | ||
// Check if user ignored this domain | ||
const isIgnored = ignoreList.includes(site.domain) | ||
if (isIgnored) continue | ||
const isIgnored = ignoreList.includes(site.domain); | ||
if (isIgnored) continue; | ||
|
||
// Check if the path matches | ||
const pathCorrect = site.path ? parsed.pathname.startsWith(site.path) : true | ||
if (!pathCorrect) continue | ||
const pathCorrect = site.path | ||
? parsed.pathname.startsWith(site.path) | ||
: true; | ||
if (!pathCorrect) continue; | ||
|
||
// Set variables so alert.html page will know site's domain, reason, and URL | ||
lastBlockedSite.domain = site.domain | ||
lastBlockedSite.reason = site.reason | ||
lastBlockedSite.notes = site.notes | ||
lastBlockedSite.path = site.path | ||
lastBlockedSite.url = tab.url | ||
lastBlockedSite.domain = site.domain; | ||
lastBlockedSite.reason = site.reason; | ||
lastBlockedSite.notes = site.notes; | ||
lastBlockedSite.path = site.path; | ||
lastBlockedSite.url = tab.url; | ||
|
||
// Redirect to the alert page | ||
chrome.tabs.update(tabId, { | ||
url: chrome.runtime.getURL(`/html/alert.html`), | ||
}) | ||
}); | ||
|
||
// Exit the loop as we found a match and handled it | ||
break | ||
break; | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ | |
"devDependencies": { | ||
"prettier": "^3.3.3", | ||
"web-ext": "^8.2.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Oops, something went wrong.