Refined searches to be more accurate

This commit is contained in:
Garrett Brown 2024-04-25 14:54:39 -05:00
parent 7632af5fc5
commit 3398d0750a
4 changed files with 27 additions and 12 deletions

3
.web-extension-id Normal file
View File

@ -0,0 +1,3 @@
# This file was created by https://github.com/mozilla/web-ext
# Your auto-generated extension ID for addons.mozilla.org is:
{f3024ea9-df75-435b-84f7-8940ca15c7b7}

View File

@ -1,17 +1,21 @@
const patterns = ["https://www.msn.com/*/news/*", "https://www.msn.com/*/tv/*","https://www.msn.com/*/movies/*" , "https://www.msn.com/*/sports/*", "https://www.msn.com/*/health/*", "https://www.msn.com/*/channel/*", "https://www.msn.com/*/travel/*", "https://www.msn.com/*/health/*", "https://www.msn.com/*/lifestyle/*"];
var found = 0;
var redirectUrl = "";
var redirectUrl = "";
//Finds original article URL from DuckDuckGo dork.
async function findOrigUrl(title, site) {
console.log("3. Finding Original Article");
var results = await fetch('https://duckduckgo.com/html/?q=title:' + title + " inurl:" + site)
var siteUrl = await ddGet("https://duckduckgo.com/html/?q=" + site);
console.log("Site Url: " + siteUrl);
var articleUrl = await ddGet("https://duckduckgo.com/html/?q=title:" + title + " site:" + siteUrl);
return articleUrl;
}
async function ddGet(url){
var results = await fetch(url)
.then(res => res.text());
console.log("4. Parsing Results")
var resultParse = results.split("<!-- This is the visible part -->");
var findUrl = resultParse[1].split('href="//duckduckgo.com/l/?uddg=');
var extractUrl = findUrl[1].split('>');
var trimUrl = extractUrl[0].split("&amp");
console.log("5. Decoding URL")
var url = decodeURIComponent(trimUrl[0]);
return url;
}
@ -27,6 +31,7 @@ async function redirect(requestDetails){
if(data.data.page.content.brand){
var brand = data.data.page.content.brand;
var title = data.data.page.content.title;
console.log(brand);
targetUrl = await findOrigUrl(title, brand);
console.log(targetUrl);
redirectUrl = targetUrl;
@ -43,7 +48,7 @@ browser.webRequest.onBeforeRequest.addListener(
);
browser.webRequest.onBeforeRequest.addListener(
function (){
function (requestDetails){
found = 0;
},
{ urls: patterns },
@ -52,8 +57,12 @@ browser.webRequest.onBeforeRequest.addListener(
browser.browserAction.onClicked.addListener(
function (){
let creating = browser.tabs.create({
url: redirectUrl,
});
creating.then(onCreated, onError);
if(redirectUrl != ""){
let creating = browser.tabs.create({
url: redirectUrl,
});
redirectUrl = "";
creating.then(onCreated, onError);
}
});

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "MSN-Redirect",
"version": "1.0",
"version": "0.1.1",
"description": "Redirects news articles from MSN/Microsoft Start to their original website.",
"permissions": [
@ -13,7 +13,10 @@
"scripts": ["background.js"]
},
"browser_action": {
"default_icon":{
"512": "icon.png"
},
"default_title": "MSN-redirect"
}
}