From 89038f482d2d341737981f614f4dab32c6ae9863 Mon Sep 17 00:00:00 2001 From: Rushil Srivastava Date: Sat, 18 Aug 2018 11:17:54 -0700 Subject: [PATCH] Add version 0.11 --- README.md | 3 ++ manifest.json | 66 +++++++++++++++++++++++++------------------- src/js/background.js | 50 +++++++++++++++++++++++++++++---- 3 files changed, 86 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c7a2b01..712dea0 100755 --- a/README.md +++ b/README.md @@ -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/) diff --git a/manifest.json b/manifest.json index cdce80a..d268a73 100755 --- a/manifest.json +++ b/manifest.json @@ -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", @@ -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/*" ] } diff --git a/src/js/background.js b/src/js/background.js index d3ff2f9..a308685 100755 --- a/src/js/background.js +++ b/src/js/background.js @@ -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; @@ -95,7 +116,7 @@ browser.webRequest.onBeforeRequest.addListener( cancel: true }; }, { - urls: script_urls, + urls: scriptURLs, // target is script types: ["script"] }, ["blocking"] @@ -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: [""] +});