/ contentScript_once.js
contentScript_once.js
  1  //'use strict';
  2  var ext_api = (typeof browser === 'object') ? browser : chrome;
  3  
  4  if (matchDomain('gitlab.com')) {
  5    window.setTimeout(function () {
  6      let bio = document.querySelector('p.profile-user-bio');
  7      if (bio) {
  8        let split = bio.innerText.split(/(https:[\w\-/.]+)|\|/g).filter(x => x && x.trim());
  9        bio.innerText = '';
 10        for (let part of split) {
 11          let elem;
 12          if (part.startsWith('https')) {
 13            elem = document.createElement('a');
 14            elem.innerText = part;
 15            elem.href = part;
 16            elem.appendChild(document.createElement('br'));
 17          } else {
 18            elem = document.createElement('b');
 19            elem.appendChild(document.createTextNode(part));
 20            if (!part.includes(':'))
 21              elem.appendChild(document.createElement('br'));
 22          }
 23          bio.appendChild(elem);
 24        }
 25      }
 26    }, 1000);
 27  }
 28  
 29  else {
 30  window.setTimeout(function () {
 31  
 32    let hostname = window.location.hostname;
 33    let custom_domain = getCookieDomain(hostname);
 34    let group;
 35    if (hostname) {
 36      if (document.querySelector('script[src*=".medium.com/"]') || matchDomain(['plainenglish.io']))
 37        group = 'medium.com';
 38      else if (document.querySelector('script[src*="/leaky-paywall"], link[href*="/leaky-paywall"]'))
 39        group = '###_wp_leaky_paywall';
 40      else if (document.querySelector('script[src*="/substackcdn.com/"], link[rel="stylesheet"][href*="/substackcdn.com/"]'))
 41        group = '###_substack_custom';// no fix
 42      else if (document.querySelector('script[src*="/wp-content/themes/pmgnews/scripts/promedia.js"], form[action^="https://go.promedia.nl/"]'))
 43        group = '###_nl_promedia';
 44      else if (hostname.match(/\.(com|net)\.au$/)) {
 45        if (document.querySelector('a[href^="https://austcommunitymedia.my.site.com/"]'))
 46          group = '###_au_comm_media';
 47        else if (hostname.endsWith('.com.au')) {
 48          if (document.querySelector('li > a[href*=".sevenwestmedia.com.au"]'))
 49            group = 'thewest.com.au';
 50        }
 51      } else if (hostname.endsWith('.be')) {
 52          if (matchDomain(['gva.be', 'hbvl.be', 'nieuwsblad.be', 'standaard.be']))
 53            group = '###_be_mediahuis';// no fix
 54      } else if (hostname.endsWith('.cl')) {
 55        if (document.querySelector('meta[property="og:image"][content*="/impresa.soy-chile.cl/"]'))
 56          group = 'elmercurio.com';
 57      } else if (hostname.match(/\.(de|at|ch)$/) || matchDomain(['horizont.net', 'lebensmittelzeitung.net'])) {
 58        if (document.querySelector('script[src*="/dfv.containers.piwik.pro/"]'))
 59          group = '###_de_dfv_medien';
 60        else if (document.querySelector('script[data-cmp-src*=".funkedigital.de/"], div#fmg-markenanker > a[href="https://www.funkemedien.de/"]'))
 61          group = '###_de_funke_medien';
 62        else if (document.querySelector('div.navigation__personalization > a[href^="https://www.haas-mediengruppe.de/"]'))
 63          group = '###_de_haas_medien';
 64        else if (document.querySelector('link[href*=".rndtech.de/"]'))
 65          group = '###_de_madsack';
 66        else if (document.querySelector('div.mgw-integration > a.mgw__link'))
 67          group = '###_de_mgw';
 68        else if (matchDomain(['cannstatter-zeitung.de', 'esslinger-zeitung.de', 'frankenpost.de', 'insuedthueringen.de', 'krzbb.de', 'kurier.de', 'np-coburg.de', 'verlagshaus-jaumann.de']))
 69          group = '###_de_mhs';
 70        else if (matchDomain(['aachener-nachrichten.de', 'aachener-zeitung.de', 'ga.de', 'rp-online.de', 'saarbruecker-zeitung.de', 'volksfreund.de']))
 71          group = '###_de_rp_aachen_medien';// no fix
 72        else if (matchDomain(['buerstaedter-zeitung.de', 'hochheimer-zeitung.de', 'lampertheimer-zeitung.de', 'lauterbacher-anzeiger.de', 'main-spitze.de', 'mittelhessen.de', 'oberhessische-zeitung.de', 'wormser-zeitung.de']))
 73          group = '###_de_vrm';
 74        else if (document.querySelector('link[href*="/assets.static-chmedia.ch/"]'))
 75          group = 'nzz.ch';
 76        else if (document.querySelector('link[href*=".tamedia.ch/"]'))
 77          group = '###_ch_tamedia';// no fix
 78      } else if (hostname.match(/\.(es|cat)$/) || matchDomain(['diariocordoba.com', 'elperiodicodearagon.com', 'elperiodicoextremadura.com', 'elperiodicomediterraneo.com', 'emporda.info'])) {
 79        if (document.querySelector('link[href*="/estaticos-cdn."]'))
 80          group = '###_es_epiberica';
 81        else if (document.querySelector('div > ul > li > a[href="https://www.sportlife.es/"]'))
 82          group = '###_es_sport_life';
 83      } else if (hostname.endsWith('.fi')) {
 84        if (document.querySelector('link[href^="https://assets.almatalent.fi"]'))
 85          group = '###_fi_alma_talent';// no fix
 86      } else if (hostname.endsWith('.fr')) {
 87        if (document.querySelector('link[href*=".fr/static/bloc/ripolinage/header/cf-header/"]'))
 88          group = '###_fr_gcf';
 89      } else if (hostname.endsWith('.it')) {
 90        if (document.querySelector('link[href^="//citynews.stgy.ovh/"]'))
 91          group = '###_it_citynews';// no fix
 92        else if (matchDomain(['gazzettadimodena.it', 'gazzettadireggio.it', 'lanuovaferrara.it']))
 93          group = '###_it_gruppo_sae';
 94      } else if (hostname.endsWith('.nl')) {
 95        if (document.querySelector('link[href*=".ndcmediagroep.nl/"]'))
 96          group = '###_nl_mediahuis_noord';
 97        else if (document.querySelector('link[rel="dns-prefetch"][href^="https://vmn-"][href$="imgix.net"]'))
 98         group = '###_nl_vmnmedia';// no fix
 99      } else if (hostname.endsWith('.se')) {
100        if (document.querySelector('footer > div > div > a[href="https://www.nwtmedia.se/"]'))
101          group = '###_se_nwt_media';
102      } else if (hostname.endsWith('.co.uk')) {
103        if (document.querySelector('footer > div a[href^="https://www.nationalworldplc.com"]'))
104          group = '###_uk_nat_world';
105      } else if (hostname.match(/\.(ca|com|net|news|org)$/)) {
106        if (document.querySelector('picture > source[srcset*="%2Fgcm.omerlocdn.com%2F"]'))
107          group = '###_ca_gcm';
108        else if (document.querySelector('script[src*=".postmedia.digital/"], meta[content*=".postmedia.digital/"]'))
109          group = '###_ca_postmedia';
110        else if (document.querySelector('script[src*=".axate.io/"], script[src*=".agate.io/"]'))
111          group = '###_uk_axate.io';
112        else if (document.querySelector('img[srcset^="https://www.gannett-cdn.com/"], link[href*=".gannett-cdn.com/"]'))
113          group = '###_usa_gannett';
114        else if (document.querySelector('script[src*="/treg.hearstnp.com/"]'))
115          group = '###_usa_hearst_comm';
116        else if (document.querySelector('script[src*=".townnews.com/"][src*="leetemplates.com/'))
117          group = '###_usa_lee_ent';
118        else if (document.querySelector('script[src*=".townnews.com/"][src*="/tncms/"]'))
119          group = '###_usa_townnews';
120        else if (document.querySelector('meta[content^="https://www.mcclatchy-wires.com/"], a[href^="https://classifieds.mcclatchy.com/"], script[src*=".mcclatchyinteractive.com/"]'))
121          group = '###_usa_mcc';
122        else if (document.querySelector('script[src*=".com/wp-content/plugins/dfm"], amp-img#paywall[src*=".com/wp-content/plugins/dfm-amp-mods/"]'))
123          group = '###_usa_mng';
124        else if (hostname.match(/\.com$/)) {
125          if (matchDomain(['journalauto.com', 'journaldupneu.com', 'j2rauto.com']))
126            group = '###_fr_synerj';
127          else if (document.querySelector('link[href*=".com/wp-content/themes/madavor/"]'))
128            group = '###_usa_madavor';
129          else if (document.querySelector('img[data-src*="/wp-content/plugins/pragmatic-pei-rebranding/"]'))
130            group = '###_usa_pei';
131          else if (matchDomain(['dayton.com', 'daytondailynews.com', 'journal-news.com', 'springfieldnewssun.com']))
132            group = 'ajc.com';// Cox First Media
133          else if (matchDomain(['accountingtoday.com', 'benefitnews.com', 'bondbuyer.com', 'dig-in.com', 'financial-planning.com', 'nationalmortgagenews.com']))
134            group = 'americanbanker.com';// Arizent
135        }
136      }
137  
138      ext_api.runtime.sendMessage({
139        request: 'custom_domain',
140        data: {
141          domain: custom_domain,
142          group: group
143        }
144      });
145    }
146  
147  }, 1000);	
148  }
149  
150  function matchDomain(domains, hostname) {
151    var matched_domain = false;
152    if (!hostname)
153      hostname = window.location.hostname;
154    if (typeof domains === 'string')
155      domains = [domains];
156    domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
157    return matched_domain;
158  }
159  
160  function getCookieDomain(hostname) {
161    let domain = hostname;
162    let n = 0;
163    let parts = hostname.split('.');
164    let str = '_gd' + (new Date()).getTime();
165    try {
166    while (n < (parts.length - 1) && document.cookie.indexOf(str + '=' + str) == -1) {
167      domain = parts.slice(-1 - (++n)).join('.');
168      document.cookie = str + "=" + str + ";domain=" + domain + ";";
169    }
170    document.cookie = str + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";";
171    } catch (e) {
172      console.log(e);
173    }
174    return domain;
175  }