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

Commit

Permalink
v0.5: use a mobile user-agent where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
nextgens committed Nov 26, 2017
1 parent 7997646 commit 543ae13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ const cookies = ([
'n_regis=123456789'
]).join('; ').trim()

// from https://support.google.com/webmasters/answer/1061943
const UA_Desktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
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) {
var useMobileUA = false;
var reqHeaders = details.requestHeaders.filter(function(header) {
// drop cookies, referer and UA
if (header.name === "Cookie" || header.name === "Referer" || header.name === "User-Agent") {
return false;
switch(header.name) {
case "User-Agent":
useMobileUA = header.value.toLowerCase().includes("mobile")
case "Cookie":
case "Referer":
return false;
break;
default:
return true;
}

return true;
})

// Add the spoofed ones back
Expand All @@ -22,15 +32,14 @@ function evadePaywalls(details) {
})
reqHeaders.push({
"name": "User-Agent",
"value": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
"value": useMobileUA ? UA_Mobile : UA_Desktop
})

reqHeaders.push({
"name": "Cookie",
"value": cookies
})

// This seems to do the trick just fine for WSJ
reqHeaders.push({
"name": "X-Forwarded-For",
"value": "66.249.66.1"
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Anti-Paywall",
"version": "0.4",
"version": "0.5",
"description": "This extension will mangle your browser's requests to maximize the chances of bypassing paywalls.",
"permissions": ["webRequest", "webRequestBlocking",
"*://*.adelaidenow.com.au/*",
Expand Down

0 comments on commit 543ae13

Please sign in to comment.