Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Commit

Permalink
resolve #3: add medium.com
Browse files Browse the repository at this point in the history
  • Loading branch information
nextgens committed Dec 13, 2017
1 parent 78e0133 commit 027066f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const websites = [
"*://*.letemps.ch/*",
"*://*.mcall.com/*",
"*://*.medscape.com/*",
"*://*.medium.com/*",
"*://*.nationalpost.com/*",
"*://*.newsweek.com/*",
"*://*.newyorker.com/*",
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand Down

0 comments on commit 027066f

Please sign in to comment.