Refined searches to be more accurate
This commit is contained in:
parent
7632af5fc5
commit
3398d0750a
|
@ -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}
|
|
@ -3,15 +3,19 @@ var found = 0;
|
|||
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("&");
|
||||
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 (){
|
||||
if(redirectUrl != ""){
|
||||
let creating = browser.tabs.create({
|
||||
url: redirectUrl,
|
||||
});
|
||||
redirectUrl = "";
|
||||
creating.then(onCreated, onError);
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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,6 +13,9 @@
|
|||
"scripts": ["background.js"]
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon":{
|
||||
"512": "icon.png"
|
||||
},
|
||||
"default_title": "MSN-redirect"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue