diff --git a/background.js b/background.js index 0b4bddf..a988f3a 100644 --- a/background.js +++ b/background.js @@ -8,7 +8,7 @@ var ext_api = (typeof browser === 'object') ? browser : chrome; // var defaultSites = {}; const restrictions = { - 'barrons.com': /.+barrons\.com\/articles\/.+/, + 'barrons.com': /.+barrons\.com\/(amp\/)?article(s)?\/.+/, 'economist.com': /.+economist\.com\/.+\/\d{1,4}\/\d{1,2}\/\d{2}\/.+/, 'elcomercio.pe': /.+\/elcomercio.pe\/.+((\w)+(\-)+){3,}.+/, 'gestion.pe': /.+\/gestion.pe\/.+((\w)+(\-)+){3,}.+/, @@ -145,6 +145,7 @@ var blockedRegexes = { 'adweek.com': /.+\.lightboxcdn\.com\/.+/, 'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/, 'americanbanker.com': /.+\.tinypass\.com\/.+/, +'barrons.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/, 'bloomberg.com': /.+\.tinypass\.com\/.+/, 'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/, 'businessinsider.com': /(.+\.tinypass\.com\/.+|cdn\.onesignal\.com\/sdks\/.+\.js)/, diff --git a/contentScript.js b/contentScript.js index a67e02e..8a33bfb 100644 --- a/contentScript.js +++ b/contentScript.js @@ -509,15 +509,24 @@ else if (matchDomain('challenges.fr')) { } else if (matchDomain('barrons.com')) { - var href = ''; - const signin_links = document.querySelectorAll('a.primary-button--link'); - for (let i = 0; i < signin_links.length; i++) { - href = signin_links[i].href; - if (href.includes('target=')) { - href = href.split('target')[1].split('%3F')[0]; - href = href.replace('=', '').replace('%3A', ':').replace(/%2F/g, '/'); - signin_links[i].href = href; - signin_links[i].text = 'Click'; + document.addEventListener('DOMContentLoaded', () => { + let body_continuous = document.querySelector('body.is-continuous'); + let snippet = document.querySelector('meta[content="snippet"]'); + if (body_continuous && snippet) { + window.location.href = window.location.href.replace('barrons.com', 'barrons.com/amp'); + } + }); + if (!window.location.href.includes('barrons.com/amp/')) { + var href = ''; + let signin_links = document.querySelectorAll('a.primary-button--link'); + for (let signin_link of signin_links) { + href = signin_link.href; + if (href.includes('target=')) { + href = href.split('target')[1].split('%3F')[0]; + href = href.replace('=', '').replace('%3A', ':').replace(/%2F/g, '/'); + signin_link.href = href; + signin_link.text = 'Click'; + } } } }