commit 11f41fc540a4d08c59e449fd5b9de32ffc743639 Author: Adam Date: Sat Jul 8 10:40:29 2017 -0700 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..1494cc0 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +"# README" +Updates-- +2017-06-15 v1.08: Added browser_action icon, removed Barron's, fixed Financial Times (ft.com), added options link to popup +2017-05-14: Ported to Firefox +2017-04-16: Added MIT Technology Review (technologyreview.com), NRC (nrc.nl), The Courier Mail (couriermail.com.au). +2017-04-05: Added 'Nikkei Asian Review'. +2017-02-25: If you are trying to view NYT articles or tired of the WSJ popup, try installing an adblocker (I recommend 'uBlock Origin'). +2017-02-16: Added 'The Australian'. +2017-02-09: WSJ working again (bypass paywall)! Also added glassdoor, nytimes, seattletimes. + +Bypass the following sites' paywalls: + +The Age (theage.com.au) +The Australian (theaustralian.com.au) +Baltimore Sun (baltimoresun.com) +Barron's (barrons.com) +Crain's Chicago Business (chicagobusiness.com) +Chicago Tribune (chicagotribune.com) +Daily Press (dailypress.com) +The Economist (economist.com) +Financial Times (ft.com) +Glassdoor (glassdoor.com) +Hartford Courant (courant.com) +Harvard Business Review (hbr.org) +Inc.com (inc.com) +Los Angeles Times (latimes.com) +Medscape (medscape.com) +MIT Technology Review (technologyreview.com) +Nikkei Asian Review (asia.nikkei.com) +NRC (nrc.nl) +The Courier Mail (couriermail.com.au) +The Morning Call (mcall.com) +The Nation (thenation.com) +The New York Times (nytimes.com) +The New Yorker (newyorker.com) +OrlandoSentinel (orlandosentinel.com) +Quora (quora.com) +SunSentinel (sun-sentinel.com) +The Seattle Times (seattletimes.com) +The Sydney Morning Herald (smh.com.au) +The Telegraph (telegraph.co.uk) +The Washington Post (washingtonpost.com) +The Wall Street Journal (wsj.com) \ No newline at end of file diff --git a/background.js b/background.js new file mode 100644 index 0000000..3e66afc --- /dev/null +++ b/background.js @@ -0,0 +1,212 @@ +'use strict'; + +var defaultSites = { + 'The Age': 'theage.com.au', + 'The Australian': 'theaustralian.com.au', + 'Baltimore Sun': 'baltimoresun.com', + 'Crain\'s Chicago Business': 'chicagobusiness.com', + 'Chicago Tribune': 'chicagotribune.com', + 'Daily Press': 'dailypress.com', + 'The Economist': 'economist.com', + 'Financial Times': 'ft.com', + 'Glassdoor': 'glassdoor.com', + 'Hartford Courant': 'courant.com', + 'Harvard Business Review': 'hbr.org', + 'Inc.com': 'inc.com', + 'Los Angeles Times': 'latimes.com', + 'Medscape': 'medscape.com', + 'MIT Technology Review': 'technologyreview.com', + 'Nikkei Asian Review': 'asia.nikkei.com', + 'NRC': 'nrc.nl', + 'The Courier Mail': 'couriermail.com.au', + 'The Morning Call': 'mcall.com', + 'The Nation': 'thenation.com', + 'The New York Times': 'nytimes.com', + 'The New Yorker': 'newyorker.com', + 'OrlandoSentinel': 'orlandosentinel.com', + 'Quora': 'quora.com', + 'SunSentinel': 'sun-sentinel.com', + 'The Seattle Times': 'seattletimes.com', + 'The Sydney Morning Herald': 'smh.com.au', + 'The Telegraph': 'telegraph.co.uk', + 'The Washington Post': 'washingtonpost.com', + 'The Wall Street Journal': 'wsj.com' +}; + +var restrictions = { + 'barrons.com': 'barrons.com/articles' +} + +// Don't remove cookies before page load +var allow_cookies = [ +'theaustralian.com.au', +'asia.nikkei.com', +'nytimes.com', +'wsj.com', +'couriermail.com.au', +'ft.com' +] + +// Removes cookies after page load +var remove_cookies = [ +'theaustralian.com.au', +'asia.nikkei.com', +'couriermail.com.au', +'ft.com' +] + +function setDefaultOptions() { + browser.storage.sync.set({ + sites: defaultSites + }, function() { + browser.runtime.openOptionsPage(); + // browser.tabs.create({ 'url': 'browser://extensions/?options=' + browser.runtime.id }); + }); +} + + +var blockedRegexes = [ +/.+:\/\/.+\.tribdss\.com\//, +/thenation\.com\/.+\/paywall-script\.php/ +]; + +var enabledSites = []; + +// Get the enabled sites +browser.storage.sync.get({ + sites: {} +}, function(items) { + var sites = items.sites; + enabledSites = Object.keys(items.sites).map(function(key) { + return items.sites[key]; + }); +}); + + +// Listen for changes to options +browser.storage.onChanged.addListener(function(changes, namespace) { + var key; + for (key in changes) { + var storageChange = changes[key]; + if (key === 'sites') { + var sites = storageChange.newValue; + enabledSites = Object.keys(sites).map(function(key) { + return sites[key]; + }); + } + } +}); + + +// Set and show default options on install +browser.runtime.onInstalled.addListener(function (details) { + if (details.reason == "install") { + setDefaultOptions(); + } else if (details.reason == "update") { + // User updated extension + } +}); + + +browser.webRequest.onBeforeSendHeaders.addListener(function(details) { + if (blockedRegexes.some(function(regex) { return regex.test(details.url); })) { + return { cancel: true }; + } + + var isEnabled = enabledSites.some(function(enabledSite) { + + var useSite = details.url.indexOf(enabledSite) !== -1; + + if (enabledSite in restrictions) { + return useSite && details.url.indexOf(restrictions[enabledSite]) !== -1; + } + + return useSite; + + }); + + if (!isEnabled) { + return; + } + + var requestHeaders = details.requestHeaders; + var tabId = details.tabId; + + var setReferer = false; + + // if referer exists, set it to google + requestHeaders = requestHeaders.map(function(requestHeader) { + if (requestHeader.name === 'Referer') { + if (details.url.indexOf("wsj.com") !== -1) { + requestHeader.value = 'https://www.facebook.com/'; + } else { + requestHeader.value = 'https://www.google.com/'; + } + + setReferer = true; + } + return requestHeader; + }); + + // otherwise add it + if (!setReferer) { + if (details.url.indexOf("wsj.com") !== -1) { + requestHeaders.push({ + name: 'Referer', + value: 'https://www.facebook.com/' + }); + } else { + requestHeaders.push({ + name: 'Referer', + value: 'https://www.google.com/' + }); + } + + } + + // remove cookies before page load + requestHeaders = requestHeaders.map(function(requestHeader) { + for (var siteIndex in allow_cookies) { + if (details.url.indexOf(allow_cookies[siteIndex]) !== -1) { + return requestHeader; + } + } + if (requestHeader.name === 'Cookie') { + requestHeader.value = ''; + } + return requestHeader; + }); + + if (tabId !== -1) { + // run contentScript inside tab + browser.tabs.executeScript(tabId, { + file: 'contentScript.js', + runAt: 'document_start' + }, function(res) { + if (browser.runtime.lastError || res[0]) { + return; + } + }); + } + + return { requestHeaders: requestHeaders }; +}, { + urls: [''] +}, ['blocking', 'requestHeaders']); + +// remove cookies after page load +browser.webRequest.onCompleted.addListener(function(details) { + for (var domainIndex in remove_cookies) { + var domainVar = remove_cookies[domainIndex]; + if (!enabledSites.includes(domainVar) || details.url.indexOf(domainVar) === -1) { + continue; // don't remove cookies + } + browser.cookies.getAll({domain: domainVar}, function(cookies) { + for (var i=0; i"] +}); \ No newline at end of file diff --git a/bypass.png b/bypass.png new file mode 100644 index 0000000..6418ed9 Binary files /dev/null and b/bypass.png differ diff --git a/bypass.svg b/bypass.svg new file mode 100644 index 0000000..01d6a9f --- /dev/null +++ b/bypass.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/bypass_wsj_extension_screenshot.png b/bypass_wsj_extension_screenshot.png new file mode 100644 index 0000000..8832e17 Binary files /dev/null and b/bypass_wsj_extension_screenshot.png differ diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..c4a7069 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,42 @@ +Updates-- +2017-06-15 v1.08: Added browser_action icon, removed Barron's, fixed Financial Times (ft.com), added options link to popup +2017-05-14: Ported to Firefox +2017-04-16: Added MIT Technology Review (technologyreview.com), NRC (nrc.nl), The Courier Mail (couriermail.com.au). +2017-04-05: Added 'Nikkei Asian Review'. +2017-02-25: If you are trying to view NYT articles or tired of the WSJ popup, try installing an adblocker (I recommend 'uBlock Origin'). +2017-02-16: Added 'The Australian'. +2017-02-09: WSJ working again (bypass paywall)! Also added glassdoor, nytimes, seattletimes. + +Bypass the following sites' paywalls: + +The Age (theage.com.au) +The Australian (theaustralian.com.au) +Baltimore Sun (baltimoresun.com) +Barron's (barrons.com) +Crain's Chicago Business (chicagobusiness.com) +Chicago Tribune (chicagotribune.com) +Daily Press (dailypress.com) +The Economist (economist.com) +Financial Times (ft.com) +Glassdoor (glassdoor.com) +Hartford Courant (courant.com) +Harvard Business Review (hbr.org) +Inc.com (inc.com) +Los Angeles Times (latimes.com) +Medscape (medscape.com) +MIT Technology Review (technologyreview.com) +Nikkei Asian Review (asia.nikkei.com) +NRC (nrc.nl) +The Courier Mail (couriermail.com.au) +The Morning Call (mcall.com) +The Nation (thenation.com) +The New York Times (nytimes.com) +The New Yorker (newyorker.com) +OrlandoSentinel (orlandosentinel.com) +Quora (quora.com) +SunSentinel (sun-sentinel.com) +The Seattle Times (seattletimes.com) +The Sydney Morning Herald (smh.com.au) +The Telegraph (telegraph.co.uk) +The Washington Post (washingtonpost.com) +The Wall Street Journal (wsj.com) \ No newline at end of file diff --git a/contentScript.js b/contentScript.js new file mode 100644 index 0000000..395646e --- /dev/null +++ b/contentScript.js @@ -0,0 +1 @@ +window.localStorage.clear(); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..665bd40 --- /dev/null +++ b/manifest.json @@ -0,0 +1,29 @@ +{ + "background": { + "scripts": ["background.js"] + }, + "applications": { + "gecko": { + "id": "iamadamdev@hotmail.com" + } + }, + "browser_action": { + "default_popup": "popup.html", + "default_icon": { + "128": "bypass.png" + } + }, + "description": "Bypass News Sites' Paywalls", + "icons": { + "128": "bypass.png" + }, + "manifest_version": 2, + "name": "Bypass Paywalls", + "short_name": "Bypass Paywall", + "options_ui": { + "page": "options.html" + }, + + "permissions": [ "cookies", "", "storage", "webRequest", "webRequestBlocking"], + "version": "1.0.8" +} diff --git a/options.html b/options.html new file mode 100644 index 0000000..7a11219 --- /dev/null +++ b/options.html @@ -0,0 +1,34 @@ + + + + Bypass Paywalls Options + + + +
+ Selected sites will have their cookies cleared and referer set to Google. You should + uncheck sites you have an account with or else you will be logged out at every visit. +
+
+
+
+
+
+
+
+ + + + + + + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..a702bbd --- /dev/null +++ b/options.js @@ -0,0 +1,106 @@ +var defaultSites = { + 'The Age': 'theage.com.au', + 'The Australian': 'theaustralian.com.au', + 'Baltimore Sun': 'baltimoresun.com', + 'Crain\'s Chicago Business': 'chicagobusiness.com', + 'Chicago Tribune': 'chicagotribune.com', + 'Daily Press': 'dailypress.com', + 'The Economist': 'economist.com', + 'Financial Times': 'ft.com', + 'Glassdoor': 'glassdoor.com', + 'Hartford Courant': 'courant.com', + 'Harvard Business Review': 'hbr.org', + 'Inc.com': 'inc.com', + 'Los Angeles Times': 'latimes.com', + 'Medscape': 'medscape.com', + 'MIT Technology Review': 'technologyreview.com', + 'Nikkei Asian Review': 'asia.nikkei.com', + 'NRC': 'nrc.nl', + 'The Courier Mail': 'couriermail.com.au', + 'The Morning Call': 'mcall.com', + 'The Nation': 'thenation.com', + 'The New York Times': 'nytimes.com', + 'The New Yorker': 'newyorker.com', + 'OrlandoSentinel': 'orlandosentinel.com', + 'Quora': 'quora.com', + 'SunSentinel': 'sun-sentinel.com', + 'The Seattle Times': 'seattletimes.com', + 'The Sydney Morning Herald': 'smh.com.au', + 'The Telegraph': 'telegraph.co.uk', + 'The Washington Post': 'washingtonpost.com', + 'The Wall Street Journal': 'wsj.com' +}; + +// Saves options to browser.storage +function save_options() { + var gh_url = document.getElementById('bypass_sites').value; + var inputEls = document.querySelectorAll('#bypass_sites input'); + var sites = {}; + + var sites = Array.from(inputEls).reduce(function(memo, inputEl) { + if (inputEl.checked) { + memo[inputEl.dataset.key] = inputEl.dataset.value; + } + return memo; + }, {}); + + browser.storage.sync.set({ + sites: sites + }, function() { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + // status.textContent = 'Options saved.'; + setTimeout(function() { + // status.textContent = ''; + window.close(); + }, 500); + }); +} + +// Restores checkbox input states using the preferences +// stored in browser.storage. +function renderOptions() { + browser.storage.sync.get({ + sites: {} + }, function(items) { + var sites = items.sites; + var sitesEl = document.getElementById('bypass_sites'); + for (var key in defaultSites) { + if (!defaultSites.hasOwnProperty(key)) { + continue; + } + + var value = defaultSites[key]; + var labelEl = document.createElement('label'); + var inputEl = document.createElement('input'); + inputEl.type = 'checkbox'; + inputEl.dataset.key = key; + inputEl.dataset.value = value; + inputEl.checked = key in sites; + + labelEl.appendChild(inputEl); + labelEl.appendChild(document.createTextNode(' '+key)); + sitesEl.appendChild(labelEl); + } + }); +} + +function selectAll() { + var inputEls = Array.from(document.querySelectorAll('input')); + inputEls.forEach(function(inputEl) { + inputEl.checked = true; + }); +} + +function selectNone() { + var inputEls = Array.from(document.querySelectorAll('input')); + inputEls.forEach(function(inputEl) { + inputEl.checked = false; + }); +} + +document.addEventListener('DOMContentLoaded', renderOptions); +document.getElementById('save').addEventListener('click', save_options); +document.getElementById('select-all').addEventListener('click', selectAll); +document.getElementById('select-none').addEventListener('click', selectNone); + diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..110cfcd --- /dev/null +++ b/popup.html @@ -0,0 +1,7 @@ + + + +
Bypass Paywalls v1.08 by Adam +Options
+ +