-
Notifications
You must be signed in to change notification settings - Fork 13
/
memberspace observe log in status.html
119 lines (63 loc) · 2.84 KB
/
memberspace observe log in status.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script>
$( ( ) => {
/*
memberspace observe log in status
License : < https://tinyurl.com/s872fb68 >
Version : 0.1d0
SS Version : 7.1
Dependencies : jQuery
Note : this code is a base for other effects. on its own it
doesn't do anything. this code is not the end all be all
of mutation observers. it may not cover your needs
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
*/
/*
isLoggedInCallback is a custom function that is called when ms indicates a
member is logged in. replace undefined with the name of your custom
function
*/
const isLoggedInCallback = undefined;
/*
isNotLoggedInCallback is a custom function that is called when ms
indicates a member is not logged in. replace undefined with the name of
your custom function
*/
const isNotLoggedInCallback = undefined;
// do not change anything below, there be the borg here
// bail if no mutation observer available
if ( ! ( 'MutationObserver' in window ) ) return;
const observer = new MutationObserver ( mutations => {
$.each ( mutations, function ( ) {
if ( ! this.addedNodes.length ) return; // bail if not added nodes
let $element = $( this.addedNodes [ 0 ] );
const tagName = $element.prop ( 'tagName' );
const b = [ 'MS-WIDGET-CSS-SEED', 'MS-BUTTON' ].includes ( tagName );
if ( ! b ) return; // bail if tags not of interest
$element = $( 'ms-widget-root > ms-widget-css-seed > ms-button' );
if ( ! $element.length ) return; // bail if element not found
observer.disconnect ( );
const buttonText = $element
.text ( );
switch ( buttonText ) {
case 'Log In / Sign Up' :
// bail if callback undefined
if ( isNotLoggedInCallback == undefined ) return;
isNotLoggedInCallback ( );
break;
case 'Your Account' :
// bail if callback undefined
if ( isLoggedInCallback !== undefined ) return;
isLoggedInCallback ( );
break;
}
} );
} );
// begin listening for changes in specified element
const element = $( 'body' )
.get ( 0 );
observer.observe ( element, {
childList : true,
subtree : true
} );
} );
</script>