-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (55 loc) · 1.65 KB
/
script.js
File metadata and controls
60 lines (55 loc) · 1.65 KB
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
var button = document.getElementById( "button" );
var redirectOptions = {
kindle: {
android: 'kindle://',
ios: 'kindle://'
},
pocket: {
android: 'http://getpocket.com/app/',
ios: 'pocket://'
},
facebook: {
android: 'fb://now',
ios: 'fb://'
}
}
function getRedirectUri( app ) {
if ( ! app ) {
return '';
}
var system = 'ios';
if( /android/i.test( navigator.userAgent ) ) {
system = 'android';
}
return redirectOptions[ app ] ? redirectOptions[ app ][ system ] : null;
}
if (
!! window.navigator.standalone ||
(
!! /android/i.test( navigator.userAgent )&&
!! window.matchMedia( '(display-mode: standalone)') &&
!! window.matchMedia( '(display-mode: standalone)').matches
)
) {
urlParams = new URLSearchParams( window.location.search );
// This will non - deterministicly redirect to FB itself. Maybe sometimes we want to go there?
if (
urlParams.get( 'rate' ) &&
urlParams.get( 'rate' ) > 0 &&
Math.floor( Math.random() * 100 ) < urlParams.get( 'rate' )
) {
} else if ( urlParams.get( 'to' ) ) {
//Where to redirect?
button.setAttribute( 'href', getRedirectUri( urlParams.get( 'to' ) ) );
}
// Props IFTTT team for this code:
var clickEvent = document.createEvent( 'MouseEvents' );
clickEvent.initEvent( 'click', true, true );
setTimeout( function() {
button.dispatchEvent( clickEvent );
}, 25 );
} else {
var instructions = document.getElementById( "instructions" );
instructions.style["display"] = ""
button.style["display"] = "none";
}