recent_searches.js 985 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const fs = require('fs')
  2. const plist = require('../../util/plist')
  3. const fileHash = require('../../util/backup_filehash')
  4. const SAFARI_PLIST = fileHash('Library/Preferences/com.apple.mobilesafari.plist', 'AppDomain-com.apple.mobilesafari')
  5. module.exports = {
  6. version: 4,
  7. name: 'safari.recent_searches',
  8. description: `Show Safari recent searches`,
  9. requiresBackup: true,
  10. // Run on a v3 lib / backup object
  11. run (lib, { backup }) {
  12. return safariRecentSearches(backup)
  13. },
  14. // Available fields.
  15. output: {
  16. searchString: el => el.SearchString,
  17. date: el => el.Date
  18. }
  19. }
  20. // Pull the recent searches out of the file
  21. const safariRecentSearches = (backup) => {
  22. return new Promise((resolve, reject) => {
  23. try {
  24. // Get the filename of the ID
  25. var filename = backup.getFileName(SAFARI_PLIST)
  26. let mobilesafariPlist = plist.parseFile(filename)
  27. resolve(mobilesafariPlist['RecentWebSearches'])
  28. } catch (e) {
  29. reject(e)
  30. }
  31. })
  32. }