Skip to content

Commit

Permalink
Quota exceeded fix (#35)
Browse files Browse the repository at this point in the history
Quota exceeded fix
  • Loading branch information
DaniloNovakovic authored Aug 29, 2019
2 parents c0b5447 + 811de90 commit e93d0e5
Show file tree
Hide file tree
Showing 13 changed files with 6,122 additions and 146 deletions.
146 changes: 115 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-dynamic-bookmarks",
"version": "2.5.1",
"version": "2.6.0",
"description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.",
"scripts": {
"dev": "webpack --mode development",
Expand All @@ -9,6 +9,7 @@
},
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.4",
"babel-loader": "^8.0.6",
"buffer": "^5.2.1",
Expand Down
30 changes: 14 additions & 16 deletions src/js/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * as dbm from './lib/dynBookmarks';
import * as dbm from "./lib/dynBookmarks";
import { migrateStorage } from "./lib/storage/migrations";
import { logWarn } from "./utils/log";

migrateStorage();

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (!changeInfo.url) return;
Expand Down Expand Up @@ -30,8 +34,8 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
});
});

chrome.bookmarks.onRemoved.addListener((id) => {
dbm.findByIdAndRemove(id, (err) => {
chrome.bookmarks.onRemoved.addListener(id => {
dbm.findByIdAndRemove(id, err => {
if (err) {
console.warn(err);
} else {
Expand All @@ -44,22 +48,16 @@ chrome.bookmarks.onRemoved.addListener((id) => {

// maybe let user setup this in options in future?
const maxHistorySize = 10;

chrome.bookmarks.onChanged.addListener((id, changeInfo) => {
if (changeInfo.url) {
dbm.findAll((err, dynBook) => {
if (err) {
console.warn(err);
} else if (dynBook[id]) {
if (dynBook[id].history.length >= maxHistorySize) {
dynBook[id].history.pop();
}
dynBook[id].history.unshift(changeInfo.url);
dbm.overwrite(dynBook, (err) => {
if (err) {
console.warn(err);
}
});
dbm.findById(id, (err, item) => {
if (err) return console.warn(err);
if (item.history.length >= maxHistorySize) {
item.history.pop();
}
item.history.unshift(changeInfo.url);
dbm.findByIdAndUpdate(id, item, logWarn);
});
}
});
Loading

0 comments on commit e93d0e5

Please sign in to comment.