diff --git a/.web-extension-id b/.web-extension-id new file mode 100644 index 0000000..4eb9ba3 --- /dev/null +++ b/.web-extension-id @@ -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} \ No newline at end of file diff --git a/background.js b/background.js index 4736d8d..51f93bf 100644 --- a/background.js +++ b/background.js @@ -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(""); var findUrl = resultParse[1].split('href="//duckduckgo.com/l/?uddg='); var extractUrl = findUrl[1].split('>'); var trimUrl = extractUrl[0].split("&"); - 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); + + } }); diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..6f99be2 Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json index b44c2a4..35c44e0 100644 --- a/manifest.json +++ b/manifest.json @@ -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" } } - \ No newline at end of file +