@@ -9,54 +9,49 @@ const payWallSelectors = [
9
9
] ;
10
10
11
11
const overlaySelector = "div.bg-black\\/30" ; // this is the element creating the gray semi-transparent overlay effect
12
- const contentWrapperSelector = ".contents" ;
13
- const contentSelector = "[data-test-id='content-container']" ;
14
- const adSelector = "main + div" ; // might contain "special offer" ads
12
+ const articleSelector = "main article section" ;
15
13
16
14
let matchingPayWallSelector = "" ;
17
15
let content = "" ; // Stores the original full non-pay-walled content
18
16
19
- // Code executed once the loader has finished loading the full content
20
- new window . MutationObserver ( function ( mutations ) {
21
- for ( const mutation of mutations ) {
22
- if ( mutation . target . matches ( contentSelector ) ) {
23
- storeContent ( ) ;
24
- preparePayWallRemover ( ) ;
25
- this . disconnect ( ) ;
26
- }
17
+ // Code checking if the page has finished loading the full content
18
+ let fullArticleLoadedCheck = setInterval ( ( ) => {
19
+ // Here we assume that the page contains at least one paragraph
20
+ const hasFullArticleLoaded = document . querySelector ( "p.paywall-full-content" ) != null ;
21
+
22
+ if ( hasFullArticleLoaded ) {
23
+ removePayWallFlags ( ) ;
24
+ storeContent ( ) ;
25
+ preparePayWallRemover ( ) ;
26
+ clearInterval ( fullArticleLoadedCheck ) ;
27
27
}
28
- } ) . observe ( document , { subtree : true , childList : true } ) ;
28
+ } , 10 ) ;
29
29
30
+ // Code checking if the paywall has been displayed
30
31
function preparePayWallRemover ( ) {
31
- // Code executed once the paywall is shown
32
- new window . MutationObserver ( function ( mutations ) {
33
- for ( const mutation of mutations ) {
34
- payWallSelectors . forEach ( ( selector ) => {
35
- if ( mutation . target . matches ( selector ) ) {
36
- matchingPayWallSelector = selector ;
37
- }
38
- } ) ;
32
+ let payWallLoadedCheck = setInterval ( ( ) => {
33
+ payWallSelectors . forEach ( ( selector ) => {
34
+ const payWall = document . querySelector ( selector ) ;
39
35
40
- if ( matchingPayWallSelector ) {
41
- removeBodyScrollLock ( ) ;
42
- hidePayWall ( ) ;
43
- restoreContent ( ) ;
44
- this . disconnect ( ) ;
36
+ if ( payWall && payWall . innerHTML != "" ) {
37
+ matchingPayWallSelector = selector ;
45
38
}
46
- }
47
- } ) . observe ( document , { subtree : true , childList : true } ) ;
39
+ } ) ;
48
40
49
- // Code that removes the interactivity lock if it gets added by some script
50
- new window . MutationObserver ( function ( mutations ) {
51
- for ( const mutation of mutations ) {
52
- if ( mutation . target . matches ( contentWrapperSelector ) ) {
53
- removeInteractivityLock ( ) ;
54
- this . disconnect ( ) ;
55
- }
41
+ if ( matchingPayWallSelector ) {
42
+ removeBodyScrollLock ( ) ;
43
+ hidePayWall ( ) ;
44
+ restoreContent ( ) ;
45
+ clearInterval ( payWallLoadedCheck ) ;
56
46
}
57
- } ) . observe ( document , { subtree : true , attributes : true } ) ;
47
+ } , 10 ) ;
58
48
}
59
49
50
+ // Code that keeps removing interactivity locks from the page
51
+ setInterval ( ( ) => {
52
+ removeInteractivityLock ( ) ;
53
+ } , 1000 ) ;
54
+
60
55
function hidePayWall ( ) {
61
56
const payWallDialog = document . querySelector ( matchingPayWallSelector ) ;
62
57
if ( payWallDialog ) {
@@ -71,7 +66,7 @@ function hidePayWall() {
71
66
72
67
function removeBodyScrollLock ( ) {
73
68
const body = document . body ;
74
- body . classList . remove ( "scrollLock " ) ;
69
+ body . classList . remove ( "lockScroll " ) ;
75
70
body . removeAttribute ( "style" ) ; // there is an additional "overflow:hidden" to remove
76
71
}
77
72
@@ -82,10 +77,16 @@ function removeInteractivityLock() {
82
77
} ) ;
83
78
}
84
79
80
+ function removePayWallFlags ( ) {
81
+ document . querySelectorAll ( ".paywall-full-content" ) . forEach ( ( item ) => {
82
+ item . classList . remove ( "paywall-full-content" ) ;
83
+ } ) ;
84
+ }
85
+
85
86
function storeContent ( ) {
86
- content = document . querySelector ( contentSelector ) . innerHTML ;
87
+ content = document . querySelector ( articleSelector ) . innerHTML ;
87
88
}
88
89
89
90
function restoreContent ( ) {
90
- document . querySelector ( contentSelector ) . innerHTML = content ;
91
+ document . querySelector ( articleSelector ) . innerHTML = content ;
91
92
}
0 commit comments