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}
|
|
@ -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/*"];
|
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 found = 0;
|
||||||
var redirectUrl = "";
|
var redirectUrl = "";
|
||||||
//Finds original article URL from DuckDuckGo dork.
|
//Finds original article URL from DuckDuckGo dork.
|
||||||
async function findOrigUrl(title, site) {
|
async function findOrigUrl(title, site) {
|
||||||
console.log("3. Finding Original Article");
|
var siteUrl = await ddGet("https://duckduckgo.com/html/?q=" + site);
|
||||||
var results = await fetch('https://duckduckgo.com/html/?q=title:' + title + " inurl:" + 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());
|
.then(res => res.text());
|
||||||
console.log("4. Parsing Results")
|
|
||||||
var resultParse = results.split("<!-- This is the visible part -->");
|
var resultParse = results.split("<!-- This is the visible part -->");
|
||||||
var findUrl = resultParse[1].split('href="//duckduckgo.com/l/?uddg=');
|
var findUrl = resultParse[1].split('href="//duckduckgo.com/l/?uddg=');
|
||||||
var extractUrl = findUrl[1].split('>');
|
var extractUrl = findUrl[1].split('>');
|
||||||
var trimUrl = extractUrl[0].split("&");
|
var trimUrl = extractUrl[0].split("&");
|
||||||
console.log("5. Decoding URL")
|
|
||||||
var url = decodeURIComponent(trimUrl[0]);
|
var url = decodeURIComponent(trimUrl[0]);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +31,7 @@ async function redirect(requestDetails){
|
||||||
if(data.data.page.content.brand){
|
if(data.data.page.content.brand){
|
||||||
var brand = data.data.page.content.brand;
|
var brand = data.data.page.content.brand;
|
||||||
var title = data.data.page.content.title;
|
var title = data.data.page.content.title;
|
||||||
|
console.log(brand);
|
||||||
targetUrl = await findOrigUrl(title, brand);
|
targetUrl = await findOrigUrl(title, brand);
|
||||||
console.log(targetUrl);
|
console.log(targetUrl);
|
||||||
redirectUrl = targetUrl;
|
redirectUrl = targetUrl;
|
||||||
|
@ -43,7 +48,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
);
|
);
|
||||||
|
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
function (){
|
function (requestDetails){
|
||||||
found = 0;
|
found = 0;
|
||||||
},
|
},
|
||||||
{ urls: patterns },
|
{ urls: patterns },
|
||||||
|
@ -52,8 +57,12 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
|
||||||
browser.browserAction.onClicked.addListener(
|
browser.browserAction.onClicked.addListener(
|
||||||
function (){
|
function (){
|
||||||
let creating = browser.tabs.create({
|
if(redirectUrl != ""){
|
||||||
url: redirectUrl,
|
let creating = browser.tabs.create({
|
||||||
});
|
url: redirectUrl,
|
||||||
creating.then(onCreated, onError);
|
});
|
||||||
|
redirectUrl = "";
|
||||||
|
creating.then(onCreated, onError);
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "MSN-Redirect",
|
"name": "MSN-Redirect",
|
||||||
"version": "1.0",
|
"version": "0.1.1",
|
||||||
|
|
||||||
"description": "Redirects news articles from MSN/Microsoft Start to their original website.",
|
"description": "Redirects news articles from MSN/Microsoft Start to their original website.",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
@ -13,7 +13,10 @@
|
||||||
"scripts": ["background.js"]
|
"scripts": ["background.js"]
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
"default_icon":{
|
||||||
|
"512": "icon.png"
|
||||||
|
},
|
||||||
"default_title": "MSN-redirect"
|
"default_title": "MSN-redirect"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue