Skip to content

Commit

Permalink
Fix duplicate history event issue
Browse files Browse the repository at this point in the history
  • Loading branch information
minimul committed Oct 25, 2017
1 parent 4af9575 commit 9ec6df4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
7 changes: 1 addition & 6 deletions README.md
Expand Up @@ -7,14 +7,9 @@
- `cd qbo-audit-log-to-csv`
- `npm install --global yo gulp-cli bower`
- `npm install -g generator-chrome-extension`
- Goto `chrome://extensions`
- Within Chrome go to `chrome://extensions`
- Install the extension in developer mode.
- The folder you want to navigate to is `qbo-audit-log-to-csv\app`
- The `dist` folder is for production distribution
- `gulp watch`
- Almost all of the code is in `app\scripts.babel\contentscript.js`
- **Important**: Sometime the livereload doesn't work, which then you need to manual refresh from the `chrome://extensions` page.

### Todo
- Have in only run in qbo.intuit.com/audit/log

Binary file modified app/images/128-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/manifest.json
Expand Up @@ -14,7 +14,7 @@
]
},
"permissions": [
"activeTab",
"tabs",
"webNavigation",
"https://*.intuit.com/*/*"
],
Expand Down
13 changes: 11 additions & 2 deletions app/scripts.babel/background.js
Expand Up @@ -8,12 +8,21 @@ chrome.runtime.onInstalled.addListener(details => {

chrome.webNavigation.onHistoryStateUpdated.addListener( (details) => {
console.log('QboAudit Page uses History API and we heard a pushSate/replaceState.')
if(typeof chrome._URL === 'undefined' || chrome._URL !== details.url){
chrome._URL = details.url
if(typeof chrome._LAST_RUN === 'undefined' || notRunWithinTheLastSecond(details.timeStamp)){
chrome._LAST_RUN = details.timeStamp
chrome.tabs.getSelected(null, function (tab) {
if(tab.url.match(/.*\/app\/auditlog$/)){
chrome.tabs.sendRequest(tab.id, 'runQboAuditLog')
}
})
}
})

const notRunWithinTheLastSecond = (dt) => {
const diff = dt - chrome._LAST_RUN
if (diff < 1000){
return false
} else {
return true
}
}
Binary file modified image-src/128-icon.fw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ec6df4

Please sign in to comment.