Skip to content

Commit

Permalink
Added name constants which are common in English vernacular (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrai committed Dec 23, 2020
1 parent ee1760a commit 6343fc8
Show file tree
Hide file tree
Showing 21 changed files with 7,364 additions and 3,476 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Firefox/Microsoft Edge Chromium add-on to automatically capitalise words while t

- Capitalise the first letter of a sentence.
- Capitalise `I`.
- Capitalise constants such as [days](src/constants.js#L1), [months](src/constants.js#L11)
- Capitalise common [abbreviations](src/constants.js#L24)
- Capitalise constants such as [days](src/constants.js#L3), [months](src/constants.js#L13)
- Capitalise common [abbreviations](src/constants.js#L78)
- Capitalise common [names](src/name-constants.js#L1)

## Configuration

Expand Down
2 changes: 2 additions & 0 deletions distribution/lib/background.bundle.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions distribution/lib/constants.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions distribution/lib/main.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions distribution/lib/settings.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion distribution/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"default_popup": "popup/settings.html"
},
"background": {
"scripts": ["dependencies/jquery.min.js"]
"scripts": ["dependencies/jquery.min.js", "lib/background.bundle.js"]
},
"content_scripts": [
{
Expand Down
3 changes: 3 additions & 0 deletions distribution/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<div class="form-group" style="margin-top:5%">
<input type="checkbox" id="shouldCapitaliseI" name="shouldCapitaliseI" checked>
<label for="shouldCapitaliseI">Should capitalise 'I'?</label><br>

<input type="checkbox" id="shouldCapitaliseNames" name="shouldCapitaliseNames" checked>
<label for="shouldCapitaliseNames">Should capitalise names?</label><br>
</div>
</div>
</body>
Expand Down
Binary file modified imgs/settings.png
Loading
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "yarn webpack",
"watch": "yarn webpack --watch",
"test": "yarn jest",
"test-watch": "yarn jest --watch test/",
"test:watch": "yarn jest --watch test/",
"lint": "eslint .",
"lint-fix": "eslint --fix .",
"update-version": "yarn dot-json distribution/manifest.json version $VER",
Expand Down
7 changes: 7 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { constants_key_val, names_key_val } from './constants';
import browser from 'webextension-polyfill';

browser.storage.local.set({
constants_key_val: constants_key_val,
names_key_val: names_key_val,
});
119 changes: 115 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { names } from './name-constants';

const days = [
'Monday',
'Tuesday',
Expand All @@ -21,37 +23,146 @@ const months = [
'December',
];

const abbreviations = [
'AFAIK',
'AKA',
const common_tech_words = [
'API',
'APIs',
'CSS',
'CosmosDB',
'DevOps',
'DynamoDB',
'ECMAScript',
'GitHub',
'Google',
'HBase',
'Instagram',
'JavaScript',
'MVC',
'MariaDB',
'Microsoft',
'MongoDB',
'Motorola',
'Mozilla',
'MySQL',
'MySpace',
'Ocaml',
'OpenOffice',
'PHP',
'PR',
'PRs',
'PayPal',
'Perl',
'PostgreSQL',
'PowerPC',
'PowerPoint',
'PyTorch',
'Qualcomm',
'Redis',
'Redshift',
'S3',
'SQLite',
'SUSE',
'SVN',
'Scala',
'Sega',
'UI',
'Ubuntu',
'VoIP',
'eBay',
'iOS',
'iPad',
'iPhone',
'iPod',
'iTunes',
];

const abbreviations = [
'AFR',
'AMD',
'AOL',
'APM',
'ATM',
'AWS',
'BBB',
'BMW',
'BP',
'BRB',
'BSD',
'BTW',
'CRE',
'CVS',
'DIY',
'FAQ',
'FDR',
'FNMA',
'FSF',
'FTW',
'FYI',
'GE',
'GNU',
'GTE',
'GTG',
'HBO',
'HSBC',
'IBM',
'ICYMI',
'IDK',
'IKEA',
'IMO',
'ING',
'IOW',
'ISO',
'ITT',
'JFK',
'KFC',
'LGTM',
'LOL',
'MCI',
'MGM',
'MIT',
'MMW',
'MSDN',
'NASCAR',
'NORAD',
'NP',
'NSA',
'NVIDIA',
'NW',
'OMG',
'OTOH',
'POV',
'RCA',
'RDS',
'ROTFL',
'RSVP',
'SARS',
'SMH',
'TBA',
'TBC',
'TC',
'TGIF',
'THX',
'TIA',
'TTYL',
'TWA',
'UBS',
'UCLA',
'UPS',
'USB',
'WFH',
'WSL',
'WTF',
'WTH',
];

export let constants = days.concat(months, abbreviations);
let constants = days.concat(months, abbreviations, common_tech_words);

//convert array to key-value pairs
export let constants_key_val = constants.reduce((obj, val) => {
obj[val.toLowerCase()] = val;
return obj;
}, {});

export let names_key_val = names.reduce((obj, val) => {
obj[val.toLowerCase()] = val;
return obj;
}, {});
46 changes: 33 additions & 13 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ import {
pluginNamespace,
sites_to_ignore,
should_capitalise_i,
should_capitalise_names,
constants_key_val,
names_key_val,
} from './plugin-constants';

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

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

/* Updating the value of this local storage variable in settings.js happens AFTER content.js.
* The browser doesn't register the change and doesn't capitalise I by dfeault after installing the extension.
* This block will capture the event and update the value of 'should_capitalise_i'.
*/
browser.storage.onChanged.addListener(function(
browser.storage.onChanged.addListener(function (
changes, // object
areaName // string
) {
Expand All @@ -29,6 +38,14 @@ browser.storage.onChanged.addListener(function(
utils.setShouldCapitaliseI(newValue);
}
}

if (changes.should_capitalise_names != null) {
const newValue = changes.should_capitalise_names.newValue;

if (newValue != null) {
utils.setShouldCapitaliseNames(newValue);
}
}
}
});

Expand All @@ -38,14 +55,17 @@ function hookupEventHandlers() {
}

function observeInputTags() {
$(':text,textarea').on(`input.${pluginNamespace}`, function(event) {
$(':text,textarea').on(`input.${pluginNamespace}`, function (event) {
capitaliseText(event.target);
});
}

function processResponse(item) {
sitesToExclude = item.sites_to_ignore;
utils.setShouldCapitaliseI(item.should_capitalise_i);
utils.setShouldCapitaliseNames(item.should_capitalise_names);
utils.setConstantsKeyVal(item.constants_key_val);
utils.setNamesKeyVal(item.names_key_val);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
Expand All @@ -54,7 +74,7 @@ function processResponse(item) {
try {
var shouldEnableCapitalisingOnCurrentSite = true;

$.each(sitesToExclude, function(_i, siteToExclude) {
$.each(sitesToExclude, function (_i, siteToExclude) {
if (currentUrlDomain.includes(siteToExclude)) {
shouldEnableCapitalisingOnCurrentSite = false;
}
Expand Down Expand Up @@ -83,8 +103,8 @@ function observeHtmlBody() {
var tags = ['p', 'span'];
var inputTags = ['input[type=\'text\']', 'textarea'];

var observer = new MutationObserver(function(mutations) {
$.each(mutations, function(_i, mutation) {
var observer = new MutationObserver(function (mutations) {
$.each(mutations, function (_i, mutation) {
try {
if (mutation.type === 'childList') {
// add support for div block in gmail and outlook
Expand All @@ -96,30 +116,30 @@ function observeHtmlBody() {

var addedNodes = mutation.addedNodes;
if (addedNodes && addedNodes.length > 0) {
addedNodes.forEach(node => {
addedNodes.forEach((node) => {
if (utils.isFirstTextOfEditableTextNode(node)) {
capitaliseText(node.parentNode);
addedNodes = addedNodes.filter(addedNode => {
addedNodes = addedNodes.filter((addedNode) => {
addedNode != node;
});
}
});

$.each(tags, function(_i, tagName) {
$.each(tags, function (_i, tagName) {
var filteredEls = utils.getFilteredElements(addedNodes, tagName);

filteredEls.each(function(_index, element) {
filteredEls.each(function (_index, element) {
if (utils.shouldCapitaliseContent(element)) {
capitaliseText(element);
}
});
});

$.each(inputTags, function(_i, tagName) {
$.each(inputTags, function (_i, tagName) {
var filteredEls = utils.getFilteredElements(addedNodes, tagName);

filteredEls.each(function(_index, element) {
$(element).on(`input.${pluginNamespace}`, function(event) {
filteredEls.each(function (_index, element) {
$(element).on(`input.${pluginNamespace}`, function (event) {
capitaliseText(event.target);
});
});
Expand Down
Loading

0 comments on commit 6343fc8

Please sign in to comment.