@ -57,7 +57,7 @@ if (!matchDomain(arr_localstorage_hold)) {
}
function runOnMessage ( bg2csData , dompurify _loaded ) {
// custom/updated sites: load text from json
// custom/updated sites: load text from json (script[type="application/ld+json"])
if ( bg2csData . ld _json && dompurify _loaded ) {
if ( bg2csData . ld _json . includes ( '|' ) ) {
window . setTimeout ( function ( ) {
@ -82,14 +82,14 @@ if (bg2csData.ld_json && dompurify_loaded) {
json _key = Object . keys ( json ) . find ( key => key . match ( /^articlebody$/i ) ) || Object . keys ( json ) . find ( key => key . match ( /^text$/i ) ) ;
json _text = parseHtmlEntities ( json [ json _key ] ) ;
}
if ( json _text && article . parentNode ) {
if ( json _text ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div style="margin: 25px 0px">' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let doc = parser . parseFromString ( '<div style="margin: 25px 0px">' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] , ADD _ATTR : [ 'frameborder' ] } ) + '</div>' , 'text/html' ) ;
let article _new = doc . querySelector ( 'div' ) ;
if ( article _append || ! article . parentNode ) {
article . innerHTML = '' ;
article . appendChild ( article _new ) ;
} else
} else if ( article . parentNode )
article . parentNode . replaceChild ( article _new , article ) ;
}
} catch ( err ) {
@ -101,6 +101,7 @@ if (bg2csData.ld_json && dompurify_loaded) {
}
}
// custom/updated sites: load text from json (script#__NEXT_DATA__)
if ( bg2csData . ld _json _next && dompurify _loaded ) {
if ( bg2csData . ld _json _next . includes ( '|' ) ) {
window . setTimeout ( function ( ) {
@ -109,25 +110,29 @@ if (bg2csData.ld_json_next && dompurify_loaded) {
let article _sel = ld _json _next _split [ 1 ] ;
let paywall = document . querySelectorAll ( paywall _sel ) ;
let article = document . querySelector ( article _sel ) ;
let article _append = ld _json _next _split [ 2 ] ; // optional
let article _append = ld _json _next _split [ 2 ] ; // optional
if ( paywall . length && article ) {
removeDOMElement ( ... paywall ) ;
let json _script = document . querySelector ( 'script#__NEXT_DATA__' ) ;
let json = JSON . parse ( json _script . text ) ;
if ( json ) {
let url _next = findKeyJson ( json , [ 'slug' ] ) ;
if ( url _next && ! window . location . pathname . endsWith ( url _next ) )
refreshCurrentTab ( ) ;
let json _text = parseHtmlEntities ( findKeyJson ( json , [ 'body' , 'content' , 'description' ] , 500 ) ) ;
if ( json _text && article . parentNode ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
if ( json _script ) {
try {
let json = JSON . parse ( json _script . text ) ;
let url _next = findKeyJson ( json , [ 'slug' ] ) ;
if ( url _next && ! window . location . pathname . endsWith ( url _next ) )
refreshCurrentTab ( ) ;
let json _text = parseHtmlEntities ( findKeyJson ( json , [ 'body' , 'content' , 'description' ] , 500 ) ) ;
if ( json _text ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] , ADD _ATTR : [ 'frameborder' ] } ) + '</div>' , 'text/html' ) ;
let article _new = doc . querySelector ( 'div' ) ;
if ( article _append || ! article . parentNode ) {
article . innerHTML = '' ;
article . appendChild ( article _new ) ;
} else
} else if ( article . parentNode )
article . parentNode . replaceChild ( article _new , article ) ;
}
} catch ( err ) {
console . log ( err ) ;
}
}
}
@ -135,6 +140,45 @@ if (bg2csData.ld_json_next && dompurify_loaded) {
}
}
// custom/updated sites: load text from json (link[rel="alternate"][type="application/json"][href])
if ( bg2csData . ld _json _url && dompurify _loaded ) {
if ( bg2csData . ld _json _url . includes ( '|' ) ) {
window . setTimeout ( function ( ) {
let ld _json _url _split = bg2csData . ld _json _url . split ( '|' ) ;
let paywall _sel = ld _json _url _split [ 0 ] ;
let article _sel = ld _json _url _split [ 1 ] ;
let paywall = document . querySelectorAll ( paywall _sel ) ;
let article = document . querySelector ( article _sel ) ;
let article _append = ld _json _url _split [ 2 ] ; // optional
if ( paywall . length && article ) {
removeDOMElement ( ... paywall ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = parseHtmlEntities ( json . content . rendered ) ;
if ( json _text ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div style="margin: 25px 0px">' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] , ADD _ATTR : [ 'frameborder' ] } ) + '</div>' , 'text/html' ) ;
let article _new = doc . querySelector ( 'div' ) ;
if ( article _append || ! article . parentNode ) {
article . innerHTML = '' ;
article . appendChild ( article _new ) ;
} else if ( article . parentNode )
article . parentNode . replaceChild ( article _new , article ) ;
}
} ) ;
}
} ) ;
}
}
} , 1000 ) ;
}
}
// custom/updated sites: load text from Google webcache
if ( bg2csData . ld _google _webcache && dompurify _loaded ) {
if ( bg2csData . ld _google _webcache . includes ( '|' ) ) {
@ -211,9 +255,7 @@ if (bg2csData.amp_redirect) {
let amphtml = document . querySelector ( 'link[rel="amphtml"]' ) ;
let amp _page = amp _script && ! amphtml ;
if ( ! amp _page ) {
let paywall = true ;
if ( bg2csData . amp _redirect . paywall )
paywall = document . querySelector ( bg2csData . amp _redirect . paywall ) ;
let paywall = document . querySelector ( bg2csData . amp _redirect ) ;
if ( paywall && amphtml ) {
removeDOMElement ( paywall ) ;
window . location . href = amphtml . href ;
@ -325,22 +367,24 @@ if (matchDomain('crikey.com.au')) {
if ( paywall && dompurify _loaded ) {
removeDOMElement ( paywall ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'div.article-body > div.paywall' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . parentNode . replaceChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'div.article-body > div.paywall' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . parentNode . replaceChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
}
let fade = document . querySelector ( 'article.article-locked' ) ;
if ( fade )
fade . classList . remove ( 'article-locked' ) ;
@ -1113,22 +1157,24 @@ else if (matchDomain('ruhrnachrichten.de') || document.querySelector('div.mgw-in
if ( paywall && dompurify _loaded ) {
paywall . classList . remove ( 'is_plus_article' ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'article' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] } ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . appendChild ( content _new ) ;
}
} ) ;
}
} ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'article' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] } ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . appendChild ( content _new ) ;
}
} ) ;
}
} ) ;
}
}
let ads = document . querySelector ( 'div.OUTBRAIN' ) ;
removeDOMElement ( ads ) ;
@ -2869,22 +2915,24 @@ else if (matchDomain('the-tls.co.uk')) {
if ( paywall && dompurify _loaded ) {
removeDOMElement ( paywall ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'div.tls-article-body' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div class="tls-article-body">' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . parentNode . replaceChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
let content = document . querySelector ( 'div.tls-article-body' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div class="tls-article-body">' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . parentNode . replaceChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
}
}
let fade = document . querySelector ( 'div.tls-single-article__closed-paywall-wrapper' ) ;
removeDOMElement ( fade ) ;
@ -4403,27 +4451,29 @@ else if (matchDomain('stereogum.com')) {
if ( paywall && dompurify _loaded ) {
removeDOMElement ( paywall ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
try {
let json _text = json . acf . article _modules [ 0 ] . copy . replace ( /data-src/g , 'src' ) ;
let content = document . querySelector ( 'div.article__content div.text-block__inner' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] , ADD _ATTR : [ 'frameborder' , 'allow' , 'allowfullscreen' ] } ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . innerHTML = '' ;
content . appendChild ( content _new ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
try {
let json _text = json . acf . article _modules [ 0 ] . copy . replace ( /data-src/g , 'src' ) ;
let content = document . querySelector ( 'div.article__content div.text-block__inner' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text , { ADD _TAGS : [ 'iframe' ] , ADD _ATTR : [ 'frameborder' , 'allow' , 'allowfullscreen' ] } ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . innerHTML = '' ;
content . appendChild ( content _new ) ;
}
} catch ( err ) {
console . log ( err ) ;
}
} catch ( err ) {
console . log ( err ) ;
}
} ) ;
}
} ) ;
} ) ;
}
} ) ;
}
}
}
@ -4515,27 +4565,29 @@ else if (matchDomain('theamericanconservative.com')) {
if ( paywall && dompurify _loaded ) {
paywall . classList . remove ( 'c-blog-post__body--locked' ) ;
let json _url _dom = document . querySelector ( 'link[rel="alternate"][type="application/json"][href]' ) ;
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
if ( json _text . includes ( '<p class="has-drop-cap">' ) ) {
let split = json _text . split ( /(<p class="has-drop-cap">)/ ) ;
json _text = split [ 1 ] + split [ 2 ] ;
}
let content = document . querySelector ( 'div.c-blog-post__content' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . innerHTML = '' ;
content . appendChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
if ( json _url _dom ) {
let json _url = json _url _dom . href ;
fetch ( json _url )
. then ( response => {
if ( response . ok ) {
response . json ( ) . then ( json => {
let json _text = json . content . rendered ;
if ( json _text . includes ( '<p class="has-drop-cap">' ) ) {
let split = json _text . split ( /(<p class="has-drop-cap">)/ ) ;
json _text = split [ 1 ] + split [ 2 ] ;
}
let content = document . querySelector ( 'div.c-blog-post__content' ) ;
if ( json _text && content ) {
let parser = new DOMParser ( ) ;
let doc = parser . parseFromString ( '<div>' + DOMPurify . sanitize ( json _text ) + '</div>' , 'text/html' ) ;
let content _new = doc . querySelector ( 'div' ) ;
content . innerHTML = '' ;
content . appendChild ( content _new , content ) ;
}
} ) ;
}
} ) ;
}
} else {
let img _dark = document . querySelector ( 'div.c-hero-article__image-img.o-image' ) ;
if ( img _dark )