Skip to content

Commit

Permalink
Add version 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
rushilsrivastava committed Aug 18, 2018
1 parent b29ecfb commit 89038f4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 33 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ I made this because as a student, it isn't practical for me to pay each company
* [The Globe and Mail](https://www.theglobeandmail.com/)
* [New York Daily News](http://www.nydailynews.com/)
* [Mercury News](https://www.mercurynews.com/)
* [Wired](https://wired.com/)
* [Medium](https://medium.com/)
* [Boston Globe](https://bostonglobe.com/)

66 changes: 38 additions & 28 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "OpenNews",
"version": "0.1",
"version": "0.11",
"manifest_version": 2,
"description": "Get around the paywall for many news sites, and experience an open, free web.",
"author": "Rushil Srivastava",
Expand All @@ -27,32 +27,42 @@
"permissions": [
"webRequest",
"webRequestBlocking",
"https://*.wsj.com/*",
"http://*.wsj.com/*",
"https://*.wsj.net/*",
"https://*.ft.com/*",
"http://*.ft.com/*",
"https://*.nytimes.com/*",
"http://*.nytimes.com/*",
"https://*.nyt.com/*",
"http://*.nyt.com/*",
"https://*.bloomberg.com/*",
"http://*.bloomberg.com/*",
"https://*.bwbx.io/*",
"http://*.bwbx.io/*",
"https://*.washingtonpost.com/*",
"http://*.washingtonpost.com/*",
"http://*.philly.com/*",
"https://*.bizjournals.com/*",
"http://*.bizjournals.com/*",
"http://www.kleinezeitung.at/*",
"https://*.theglobeandmail.com/*",
"http://*.theglobeandmail.com/*",
"https://*.nydailynews.com/*",
"http://*.nydailynews.com/*",
"https://*.tribdss.com/*",
"http://*.tribdss.com/*",
"https://*.mercurynews.com/*",
"http://*.mercurynews.com/*"
"cookies",
"*://*.wsj.com/*",
"*://.wsj.com/*",
"*://*.wsj.net/*",
"*://.wsj.net/*",
"*://*.ft.com/*",
"*://.ft.com/*",
"*://*.nytimes.com/*",
"*://.nytimes.com/*",
"*://*.nyt.com/*",
"*://.nyt.com/*",
"*://*.bloomberg.com/*",
"*://.bloomberg.com/*",
"*://*.bwbx.io/*",
"*://.bwbx.io/*",
"*://*.washingtonpost.com/*",
"*://.washingtonpost.com/*",
"*://*.philly.com/*",
"*://.philly.com/*",
"*://*.bizjournals.com/*",
"*://.bizjournals.com/*",
"*://*.kleinezeitung.at/*",
"*://.kleinezeitung.at/*",
"*://*.theglobeandmail.com/*",
"*://.theglobeandmail.com/*",
"*://*.nydailynews.com/*",
"*://.nydailynews.com/*",
"*://*.tribdss.com/*",
"*://.tribdss.com/*",
"*://*.mercurynews.com/*",
"*://.mercurynews.com/*",
"*://*.wired.com/*",
"*://.wired.com/*",
"*://*.medium.com/*",
"*://.medium.com/*",
"*://*.bostonglobe.com/*",
"*://.bostonglobe.com/*"
]
}
50 changes: 45 additions & 5 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,43 @@ const sites = {
mercurynews: {
url: "*://*.mercurynews.com/*",
js: [
"*://*.mercurynews.com/_static/*"
"*://*.mercurynews.com/_static/*.js*"
]
},
wired: {
url: "*://*.wired.com/*",
cookies: true
},
medium: {
url: "*://*.medium.com/*",
js: [
"*://cdn-static-1.medium.com/_/fp/gen-js/main-notes.bundle.84wyUGxUdUkjDoQr9oYsLg.js"
]
},
bostonglobe: {
url: "*://*.bostonglobe.com/*",
js: [
"*://meter.bostonglobe.com/js/meter.js"
]
}
};

// extract all script urls we want to block
var script_urls = Object.values(sites)
var scriptURLs = Object.values(sites)
.map(site => site.js)
.filter(Array.isArray)
.reduce((prev, curr) => prev.concat(curr), []);

// extract all main_frame urls we want to override
var main_frame_urls = Object.values(sites)
var mainFrameURLs = Object.values(sites)
.map(site => site.url)
.filter(url => url);

// extract all cookie based blocking
var cookieBasedURLs = Object.values(sites)
.filter(site => {return site.cookies == true})
.map(site => site.url);

// add Firefox and Edge support with the global `browser` object
browser = typeof browser !== "undefined" ? browser : chrome;

Expand All @@ -95,7 +116,7 @@ browser.webRequest.onBeforeRequest.addListener(
cancel: true
};
}, {
urls: script_urls,
urls: scriptURLs,
// target is script
types: ["script"]
}, ["blocking"]
Expand All @@ -122,8 +143,27 @@ browser.webRequest.onBeforeSendHeaders.addListener(
requestHeaders: details.requestHeaders
};
}, {
urls: main_frame_urls,
urls: mainFrameURLs,
// target is the document that is loaded for a top-level frame
types: ["main_frame"]
}, ["blocking", "requestHeaders"]
);

chrome.webRequest.onCompleted.addListener(function(details) {
for (var urlIndex in cookieBasedURLs) {
console.log("OpenNews [DEBUG]: Clearing cookies after load");
var url = cookieBasedURLs[urlIndex];
baseURL = url.substring(6, url.length - 2)
chrome.cookies.getAll({domain: baseURL}, function(cookies) {
for (var i = 0; i < cookies.length; i++) {

var protocol = cookies[i].secure ? 'https://' : 'http://';

chrome.cookies.remove({url: protocol + cookies[i].domain + cookies[i].path, name: cookies[i].name});

}
});
}
}, {
urls: ["<all_urls>"]
});

0 comments on commit 89038f4

Please sign in to comment.