From 027066fa41fc813fe5016ecdac077c5fededca95 Mon Sep 17 00:00:00 2001 From: Florent Daigniere Date: Wed, 13 Dec 2017 10:20:27 +0100 Subject: [PATCH] resolve #3: add medium.com --- README.MD | 1 + background.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.MD b/README.MD index 528c12a..310d3ff 100644 --- a/README.MD +++ b/README.MD @@ -43,6 +43,7 @@ This extension currently supports the following websites: * letemps.ch * mcall.com * medscape.com +* medium.com * nationalpost.com * newsweek.com * newyorker.com diff --git a/background.js b/background.js index 1e308cd..afda3aa 100644 --- a/background.js +++ b/background.js @@ -31,6 +31,7 @@ const websites = [ "*://*.letemps.ch/*", "*://*.mcall.com/*", "*://*.medscape.com/*", + "*://*.medium.com/*", "*://*.nationalpost.com/*", "*://*.newsweek.com/*", "*://*.newyorker.com/*", @@ -73,12 +74,14 @@ const UA_Desktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.c const UA_Mobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)" function evadePaywalls(details) { + const shouldDropUA = !details.url.includes("medium.com"); var useMobileUA = false; var reqHeaders = details.requestHeaders.filter(function(header) { // drop cookies, referer and UA switch(header.name) { case "User-Agent": useMobileUA = header.value.toLowerCase().includes("mobile") + return !shouldDropUA; case "Cookie": case "Referer": return false; @@ -93,10 +96,12 @@ function evadePaywalls(details) { "name": "Referer", "value": "https://www.google.com/" }) - reqHeaders.push({ - "name": "User-Agent", - "value": useMobileUA ? UA_Mobile : UA_Desktop - }) + if (shouldDropUA) { + reqHeaders.push({ + "name": "User-Agent", + "value": useMobileUA ? UA_Mobile : UA_Desktop + }) + } reqHeaders.push({ "name": "Cookie",