diff --git a/README.md b/README.md index 6b41576..a352668 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ 1. Drag the `bypass-paywalls-chrome-master` folder anywhere on the page to import it. Notes: -* Every time you open Chrome it may warn you about running extensions in developer mode, just hit 🗙 to keep the extension enabled. +* Every time you open Chrome it may warn you about running extensions in developer mode, just click 🗙 to keep the extension enabled. * You will be logged out for any site you have checked. * This extension works best along side the adblocker uBlock Origin. @@ -75,7 +75,7 @@ Wired (wired.com) 3. Click on the same article from the Google search results page. If it loads without a paywall you can [submit a request](https://github.com/iamadamdev/bypass-paywalls-firefox/issues/new) to add the site, otherwise my extension cannot bypass it either. ### Troubleshooting -* If it doesn't work for an article try unchecking the site in Options, save, refresh the article, then re-check the site, save and refresh the article again. +* On WSJ if you are already viewing an article and click into another article and the paywall comes up, try refreshing the page (and click 🗙 to close the "Continue reading your article with a WSJ membership" popup). * For The Denver Post turn off uBlock. ### License diff --git a/background.js b/background.js index a618a3b..496f65a 100644 --- a/background.js +++ b/background.js @@ -144,7 +144,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { } }); - // Set and show default options on install chrome.runtime.onInstalled.addListener(function (details) { if (details.reason == "install") { @@ -159,10 +158,22 @@ chrome.webRequest.onBeforeRequest.addListener(function (details) { if (!isSiteEnabled(details)) { return; } - return { redirectUrl: details.url.replace(getParameterByName("mod", details.url), "rsswn") }; - }, - {urls:["*://*.wsj.com/*"]}, - ["blocking"] + + var param; + var updatedUrl; + + param = getParameterByName("mod", details.url); + + if (param === null) { + updatedUrl = stripQueryStringAndHashFromPath(details.url); + updatedUrl += "?mod=rsswn"; + } else { + updatedUrl = details.url.replace(param, "rsswn"); + } + return { redirectUrl: updatedUrl}; +}, +{urls:["*://*.wsj.com/*"], types:["main_frame"]}, +["blocking"] ); chrome.webRequest.onBeforeSendHeaders.addListener(function(details) { @@ -285,4 +296,8 @@ function getParameterByName(name, url) { if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); +} + +function stripQueryStringAndHashFromPath(url) { + return url.split("?")[0].split("#")[0]; } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 33d3b8b..deeda7c 100644 --- a/manifest.json +++ b/manifest.json @@ -18,5 +18,5 @@ "page": "options.html" }, "permissions": [ "cookies", "", "storage", "webRequest", "webRequestBlocking"], - "version": "1.4.1" + "version": "1.4.2" }