1
- let matchingPayWallSelector = "" ;
2
-
3
1
/**
4
2
* The structure of the HTML (and the pay wall) is not always the same.
5
3
* So we need to check different possible pay wall locations on the page.
@@ -12,41 +10,52 @@ const payWallSelectors = [
12
10
13
11
const overlaySelector = "div.bg-black\\/30" ; // this is the element creating the gray semi-transparent overlay effect
14
12
const contentWrapperSelector = ".contents" ;
15
- const articleSelector = "main article section " ;
13
+ const contentSelector = "[data-test-id='content-container'] " ;
16
14
const adSelector = "main + div" ; // might contain "special offer" ads
17
15
18
- // Store the original non-pay-walled content
19
- const content = document . querySelector ( articleSelector ) . innerHTML ;
20
-
21
- removeAds ( ) ;
16
+ let matchingPayWallSelector = "" ;
17
+ let content = "" ; // Stores the original full non-pay-walled content
22
18
23
- // Code executed once the paywall is shown
19
+ // Code executed once the loader has finished loading the full content
24
20
new window . MutationObserver ( function ( mutations ) {
25
21
for ( const mutation of mutations ) {
26
- payWallSelectors . forEach ( ( selector ) => {
27
- if ( mutation . target . matches ( selector ) ) {
28
- matchingPayWallSelector = selector ;
29
- }
30
- } ) ;
31
-
32
- if ( matchingPayWallSelector ) {
33
- removeBodyScrollLock ( ) ;
34
- hidePayWall ( ) ;
35
- restoreContent ( ) ;
22
+ if ( mutation . target . matches ( contentSelector ) ) {
23
+ storeContent ( ) ;
24
+ preparePayWallRemover ( ) ;
36
25
this . disconnect ( ) ;
37
26
}
38
27
}
39
28
} ) . observe ( document , { subtree : true , childList : true } ) ;
40
29
41
- // Code that removes the interactivity lock if it gets added by some script
42
- new window . MutationObserver ( function ( mutations ) {
43
- for ( const mutation of mutations ) {
44
- if ( mutation . target . matches ( contentWrapperSelector ) ) {
45
- removeInteractivityLock ( ) ;
46
- this . disconnect ( ) ;
30
+ 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
+ } ) ;
39
+
40
+ if ( matchingPayWallSelector ) {
41
+ removeBodyScrollLock ( ) ;
42
+ hidePayWall ( ) ;
43
+ restoreContent ( ) ;
44
+ this . disconnect ( ) ;
45
+ }
47
46
}
48
- }
49
- } ) . observe ( document , { subtree : true , attributes : true } ) ;
47
+ } ) . observe ( document , { subtree : true , childList : true } ) ;
48
+
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
+ }
56
+ }
57
+ } ) . observe ( document , { subtree : true , attributes : true } ) ;
58
+ }
50
59
51
60
function hidePayWall ( ) {
52
61
const payWallDialog = document . querySelector ( matchingPayWallSelector ) ;
@@ -73,13 +82,10 @@ function removeInteractivityLock() {
73
82
} ) ;
74
83
}
75
84
76
- function restoreContent ( ) {
77
- document . querySelector ( articleSelector ) . innerHTML = content ;
85
+ function storeContent ( ) {
86
+ content = document . querySelector ( contentSelector ) . innerHTML ;
78
87
}
79
88
80
- function removeAds ( ) {
81
- const ad = document . querySelector ( adSelector ) ;
82
- if ( ad ) {
83
- ad . remove ( ) ;
84
- }
89
+ function restoreContent ( ) {
90
+ document . querySelector ( contentSelector ) . innerHTML = content ;
85
91
}
0 commit comments