This repository was archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuffer-install-check.js
More file actions
49 lines (39 loc) · 1.44 KB
/
buffer-install-check.js
File metadata and controls
49 lines (39 loc) · 1.44 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
/* globals chrome, safari */
// buffer-install-check.js
// (c) 2013 Buffer
// Adds an element to our app page that we can use to check if the browser has our extension installed.
var bufferMarkOurSite = function (version) {
if (window.top !== window) return;
if (document.location.host.match(/buffer.com/i) ||
document.location.host.match(/bufferapp.com/i)) {
var marker = document.querySelector('#browser-extension-marker');
if (!marker) return;
marker.setAttribute('data-version', version);
// Trigger a click to let the app know we have the version:
var evt = document.createEvent('HTMLEvents');
evt.initEvent('click', true, true );
marker.dispatchEvent(evt);
}
};
// Chrome doesn't expose the version so easily with the permissions
// we currently require, so we xhr for the manifest file to get the version.
function getVersionForChrome(callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('/manifest.json'));
xhr.onload = function (e) {
var manifest = JSON.parse(xhr.responseText);
callback(manifest.version);
}
xhr.send(null);
}
function getVersionForSafari(callback) {
xt.port.on('buffer_send_extesion_info', function(data){
callback(data.version);
});
xt.port.emit('buffer_get_extesion_info');
}
if (typeof chrome !== 'undefined') {
getVersionForChrome(bufferMarkOurSite);
} else if (typeof safari !== 'undefined'){
getVersionForSafari(bufferMarkOurSite);
}