-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontentscript.js
More file actions
36 lines (32 loc) · 983 Bytes
/
Copy pathcontentscript.js
File metadata and controls
36 lines (32 loc) · 983 Bytes
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
// Global constants
const GOOGLE_PRODUCTS = {
DOCUMENT: 'documents',
SHEETS: 'sheets'
};
// Identify which google product you're currently on by URL
//TODO: optimize to only call the proper product function instead of looping through all logic ever interval
function initiateCurrentGoogleProduct(currentURL) {
if (currentURL.indexOf('document') !== -1) {
insertImageLinksToDocs();
} else if (currentURL.indexOf('spreadsheets') !== -1) {
insertImageLinksToSheets();
} else {
console.log('Unable to identify product from URL: ' + currentURL);
}
}
// Initiate after initial assets have loaded
window.addEventListener(
"load",
() => {
const currentURL = location.href;
// TODO: Filter out domain for home directory
initiateCurrentGoogleProduct(currentURL);
// Recheck for images because gDocs lazy loads images on scroll
setInterval(
() => {
initiateCurrentGoogleProduct(currentURL);
},
8000);
},
false
);