bookmark.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. bookmark.js
  3. //Require paramter
  4. opr = {write / read}
  5. rtype = {bookmark / titles}
  6. newBookmarkArray = JSON array to store into the database under write mode
  7. newTitleArray = JSON array to store titles
  8. */
  9. newDBTableIfNotExists("browser");
  10. if (typeof(rtype) == "undefined" || rtype == "bookmark"){
  11. if (opr == "write"){
  12. //Write
  13. writeDBItem("browser", USERNAME, newBookmarkArray);
  14. sendOK();
  15. }else{
  16. //Read
  17. var bookmarks = readDBItem("browser", USERNAME);
  18. if (bookmarks == ""){
  19. //Not initiated
  20. sendJSONResp([]);
  21. }else{
  22. sendJSONResp(bookmarks);
  23. }
  24. }
  25. }else if ( rtype == "titles"){
  26. //Write title
  27. if (opr == "write"){
  28. //Write
  29. writeDBItem("browser", USERNAME + "/titles", newTitleArray);
  30. sendOK();
  31. }else{
  32. //Read
  33. var titleMap = readDBItem("browser", USERNAME + "/titles");
  34. if (titleMap == ""){
  35. //Not initiated
  36. sendJSONResp({});
  37. }else{
  38. sendJSONResp(titleMap);
  39. }
  40. }
  41. }