diff --git a/.gitignore b/.gitignore index f9ce37f..d312556 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ - +.idea bower_components/ dist/ node_modules/ diff --git a/js/background.js b/js/background.js index 1f331cd..4042d6d 100644 --- a/js/background.js +++ b/js/background.js @@ -3,6 +3,7 @@ * * This only does anything when the bookmarking button is clicked */ +var executedScript = false; chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) { // If no institution has been set, go to the options page to set one getActiveTenant(function (tenantCode) { @@ -14,8 +15,16 @@ chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) { }); } } - - console.log(new Date().getTime() + ': background.js: already have bookmarker.js SENDING'); - chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenantCode: tenantCode}); + if (!executedScript) { + chromeOrBrowser().tabs.executeScript(null, { + file: "/js/bookmarker.js", + runAt: 'document_end' + }, function () { + executedScript = true; + chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenantCode: tenantCode}); + }); + } else { + chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenantCode: tenantCode}); + } }); }); \ No newline at end of file diff --git a/js/bookmarker.js b/js/bookmarker.js index ac971bf..c0adf04 100644 --- a/js/bookmarker.js +++ b/js/bookmarker.js @@ -5,13 +5,16 @@ function chromeOrBrowser() { return this.browser || chrome; } -console.log(new Date().getTime() + ': bookmarker.js'); /** * Injected into page to redirect to the dynamic page parser * * @param {String} tenantCode */ function bookmarkPage(tenantCode) { + if (document.getElementById('bookmarkingScript')) { + document.getElementById('bookmarkingScript').remove(); + } + var bookmarker = document.createElement('script'); bookmarker.setAttribute( 'src', @@ -19,11 +22,12 @@ function bookmarkPage(tenantCode) { encodeURIComponent(encodeURI(window.location.href)) + '&bookmarkVersion=1&title=' + encodeURIComponent(document.title) + '&hasJquery=no' ); + bookmarker.setAttribute('id', 'bookmarkingScript'); + if (document.body) { document.body.appendChild(bookmarker); } } chromeOrBrowser().runtime.onMessage.addListener(function(message) { - console.log(new Date().getTime() + ': bookmarker.js: onMessage callback'); bookmarkPage(message.tenantCode); }); \ No newline at end of file