Skip to content

Commit

Permalink
Early loading of storage data (#37)
Browse files Browse the repository at this point in the history
* EARLY-LOADING Early Loading Local Storage Data

* EARLY-LOADING Cleanup

* EARLY-LOADING Upgraded Packages And Fixed Bugs

* EARLY-LOADING Cleanup

* EARLY-LOADING Downgraded Sinon

* EARLY-LOADING Downgraded Jest
  • Loading branch information
hrai committed Oct 12, 2020
1 parent 800ce26 commit 5e456d5
Show file tree
Hide file tree
Showing 6 changed files with 2,479 additions and 2,744 deletions.
26 changes: 17 additions & 9 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,9 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var errorMsg = 'breaking loop';
var sitesToExclude = [];

_webextensionPolyfill["default"].storage.local.get('sites_to_ignore').then(processResponse, utils.onError);
_webextensionPolyfill["default"].storage.local.get(['sites_to_ignore', 'should_capitalise_i']).then(processResponse, utils.onError);

function hookupEventHandlers() {
observeInputTags();
Expand All @@ -1255,7 +1256,8 @@ function observeInputTags() {
}

function processResponse(item) {
var sitesToExclude = item.sites_to_ignore;
sitesToExclude = item.sites_to_ignore;
utils.setShouldCapitaliseI(item.should_capitalise_i);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
Expand Down Expand Up @@ -1451,6 +1453,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.shouldCapitaliseForI = shouldCapitaliseForI;
exports.setShouldCapitaliseI = setShouldCapitaliseI;
exports.shouldCapitalise = shouldCapitalise;
exports.onError = onError;
exports.getText = getText;
Expand All @@ -1465,13 +1468,22 @@ exports.isContentEditable = isContentEditable;
exports.getFilteredElements = getFilteredElements;
exports.shouldCapitaliseContent = shouldCapitaliseContent;
exports.isEditableElement = isEditableElement;
exports.should_capitalise_i = void 0;
var should_capitalise_i = false;
exports.should_capitalise_i = should_capitalise_i;

function shouldCapitaliseForI(text) {
var regex = /\s+i(\s+|')$/;
var matches = regex.test(text);
return matches;
}

function setShouldCapitaliseI(value) {
if (value != null) {
exports.should_capitalise_i = should_capitalise_i = value;
}
}

function shouldCapitalise(text) {
var multilineRegex = /\s*\n+\s*\w$/;
var matches = multilineRegex.test(text);
Expand Down Expand Up @@ -1592,14 +1604,10 @@ function capitaliseText(element, shouldCapitalise, shouldCapitaliseForI, getText
return;
}

if (text.length >= 2 && shouldCapitaliseForI(text)) {
browser.storage.local.get('should_capitalise_i').then(function (items) {
if (items.should_capitalise_i) {
var _updatedStr = getCapitalisedContentForI(text);
if (text.length >= 2 && shouldCapitaliseForI(text) && should_capitalise_i) {
var _updatedStr = getCapitalisedContentForI(text);

setText(element, tagName, _updatedStr, shouldAppendBr);
}
});
setText(element, tagName, _updatedStr, shouldAppendBr);
return;
}
}
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"web-ext-win": "yarn web-ext run --verbose --firefox='/mnt/c/Program Files/Firefox Developer Edition/firefox.exe'",
"watch": "watchify src/*.js -o lib/bundle.js -t [ babelify --presets [ @babel/preset-env ] --plugins [ @babel/plugin-proposal-class-properties ] ]",
"web-ext-linux": "yarn web-ext run",
"test": "jest",
"test-watch": "jest --watch",
"test": "jest test/",
"test-watch": "jest --watch test/",
"lint": "eslint .",
"lint-fix": "eslint --fix .",
"start:firefox": "web-ext run"
Expand All @@ -25,17 +25,17 @@
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.0",
"babel-jest": "^24.9.0",
"babel-jest": "^26.5.2",
"babelify": "^10.0.0",
"browserify": "^16.5.0",
"eslint": "^4.19.1",
"husky": "^3.1.0",
"browserify": "^17.0.0",
"eslint": "^7.11.0",
"husky": "^4.3.0",
"jest": "^24.9.0",
"jquery": "^3.5.1",
"lint-staged": "^9.5.0",
"lint-staged": "^10.4.0",
"sinon": "^7.5.0",
"watchify": "^3.11.1",
"web-ext": "^5.1.0",
"web-ext": "^5.2.0",
"webextension-polyfill": "^0.6.0"
},
"repository": {
Expand Down Expand Up @@ -63,6 +63,6 @@
],
"homepage": "https://github.com/hrai/auto-capitalise",
"dependencies": {
"babel-eslint": "^7.2.3"
"babel-eslint": "^10.1.0"
}
}
9 changes: 6 additions & 3 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as utils from './utils';
import browser from 'webextension-polyfill';

var errorMsg = 'breaking loop';
const errorMsg = 'breaking loop';
let sitesToExclude = [];

browser.storage.local
.get('sites_to_ignore')
.get(['sites_to_ignore', 'should_capitalise_i'])
.then(processResponse, utils.onError);

function hookupEventHandlers() {
Expand All @@ -18,7 +20,8 @@ function observeInputTags() {
}

function processResponse(item) {
var sitesToExclude = item.sites_to_ignore;
sitesToExclude = item.sites_to_ignore;
utils.setShouldCapitaliseI(item.should_capitalise_i);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
Expand Down
18 changes: 11 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
export let should_capitalise_i = false;

export function shouldCapitaliseForI(text) {
const regex = /\s+i(\s+|')$/;
const matches = regex.test(text);

return matches;
}

export function setShouldCapitaliseI(value) {
if (value != null) {
should_capitalise_i = value;
}
}

export function shouldCapitalise(text) {
const multilineRegex = /\s*\n+\s*\w$/;
let matches = multilineRegex.test(text);
Expand Down Expand Up @@ -142,14 +150,10 @@ export function capitaliseText(
return;
}

if (text.length >= 2 && shouldCapitaliseForI(text)) {
browser.storage.local.get('should_capitalise_i').then(items => {
if (items.should_capitalise_i) {
const updatedStr = getCapitalisedContentForI(text);
if (text.length >= 2 && shouldCapitaliseForI(text) && should_capitalise_i) {
const updatedStr = getCapitalisedContentForI(text);

setText(element, tagName, updatedStr, shouldAppendBr);
}
});
setText(element, tagName, updatedStr, shouldAppendBr);
return;
}
}
Expand Down
Loading

0 comments on commit 5e456d5

Please sign in to comment.