Skip to content

Commit

Permalink
VARIABLES-RENAME Renamed Vars (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrai committed Feb 9, 2021
1 parent 47ee295 commit 871dd7f
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 165 deletions.
56 changes: 56 additions & 0 deletions AutoCapitaliseSentence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# /home/funkenn/.config/tmuxinator/AutoCapitaliseSentence.yml

name: AutoCapitaliseSentence
root: /mnt/1tb/auto-capitalise-sentence

# Optional tmux socket
# socket_name: foo

# Note that the pre and post options have been deprecated and will be replaced by
# project hooks.

# Project hooks
# Runs on project start, always
# on_project_start: command
# Run on project start, the first time
# on_project_first_start: command
# Run on project start, after the first time
# on_project_restart: command
# Run on project exit ( detaching from tmux session )
# on_project_exit: command
# Run on project stop
# on_project_stop: command

# Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions.
# pre_window: rbenv shell 2.0.0-p247

# Pass command line options to tmux. Useful for specifying a different tmux.conf.
# tmux_options: -f ~/.tmux.mac.conf

# Change the command to call tmux. This can be used by derivatives/wrappers like byobu.
# tmux_command: byobu

# Specifies (by name or index) which window will be selected on project startup. If not set, the first window is used.
startup_window: editor and test-build-watch

# Specifies (by index) which pane of the specified window will be selected on project startup. If not set, the first pane is used.
startup_pane: 1

# Controls whether the tmux session should be attached to automatically. Defaults to true.
# attach: false

windows:
- editor:
layout: main-vertical
# Synchronize all panes of this window, can be enabled before or after the pane commands run.
# 'before' represents legacy functionality and will be deprecated in a future release, in favour of 'after'
# synchronize: after
panes:
- vim
- test-build-watch:
layout: even-horizontal
panes:
- yarn test --watch
- yarn watch
- yarn web
- yarn start:chrome
4 changes: 2 additions & 2 deletions distribution/lib/background.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.

4 changes: 1 addition & 3 deletions distribution/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
"matches": ["<all_urls>"],
"js": [
"dependencies/jquery.min.js",
"dependencies/bootstrap.min.js",
"lib/main.bundle.js",
"lib/settings.bundle.js"
],
"css": ["dependencies/bootstrap.min.css"]
]
}
],
"icons": {
Expand Down
4 changes: 2 additions & 2 deletions distribution/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

<head>
<meta charset="utf-8">
<script charset="utf-8" src="/dependencies/jquery.min.js"></script>
<script charset="utf-8" src="/dependencies/bootstrap.min.js"></script>
<link rel="stylesheet" href="/dependencies/bootstrap.min.css" type="text/css" charset="utf-8">
</head>

Expand Down Expand Up @@ -63,6 +61,8 @@

</div>
</div>
<script charset="utf-8" src="/dependencies/jquery.min.js"></script>
<script charset="utf-8" src="/dependencies/bootstrap.min.js"></script>
<script charset="utf-8" src="/lib/settings.bundle.js"></script>
</body>

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"description": "Firefox add-on to automatically capitalise the first letter of a sentence while typing.",
"scripts": {
"start": "run-script-os",
"start:win32": "yarn build && web-ext run --firefox=\"c:/Program Files/Firefox Developer Edition/firefox.exe\"",
"start:darwin:linux": "yarn build && web-ext run --firefox=firefox-developer",
"start:chrome": "yarn build && cd distribution && web-ext run -t chromium",
"start:win32": "yarn build && web-ext run --firefox=\"c:/Program Files/Firefox Developer Edition/firefox.exe\" --start-url localhost:3000",
"start:darwin:linux": "yarn build && web-ext run --firefox=firefox-developer --start-url localhost:3000",
"start:chrome": "yarn build && cd distribution && web-ext run -t chromium --start-url localhost:3000",
"build": "yarn webpack",
"watch": "yarn webpack --watch",
"web": "nodemon app.js",
Expand Down
4 changes: 2 additions & 2 deletions src/abbreviation-constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const common_abbreviations = [
const commonAbbreviations = [
'AFR',
'AMD',
'AOL',
Expand Down Expand Up @@ -80,4 +80,4 @@ const common_abbreviations = [
'WTH',
];

export const abbreviations = common_abbreviations;
export const abbreviations = commonAbbreviations;
17 changes: 11 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import {
constantsKeyValuePairs,
namesKeyValuePairs,
abbreviationsKeyValuePairs,
} from './constants'
import browser from 'webextension-polyfill'
} from './constants';
import {
constantsKeyVal,
namesKeyVal,
abbreviationsKeyVal,
} from './plugin-constants';
import browser from 'webextension-polyfill';

browser.storage.local.set({
constants_key_val: constantsKeyValuePairs,
names_key_val: namesKeyValuePairs,
abbreviations_key_val: abbreviationsKeyValuePairs,
})
constantsKeyVal: constantsKeyValuePairs,
namesKeyVal: namesKeyValuePairs,
abbreviationsKeyVal: abbreviationsKeyValuePairs,
});
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const commonTechWords = [
'API',
'APIs',
'Artifactory',
'AWS',
'Baidu',
'BigQuery',
'BitTorrent',
Expand All @@ -48,6 +49,7 @@ const commonTechWords = [
'JavaScript',
'Jekyll',
'Jenkins',
'Jira',
'LibreOffice',
'MVC',
'MariaDB',
Expand Down
96 changes: 48 additions & 48 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,67 @@ import * as utils from './utils';
import browser from 'webextension-polyfill';
import {
pluginNamespace,
sites_to_ignore,
should_capitalise_i,
should_capitalise_names,
should_capitalise_abbreviations,
constants_key_val,
names_key_val,
abbreviations_key_val,
words_to_exclude,
sitesToIgnore,
shouldCapitaliseI,
shouldCapitaliseNames,
shouldCapitaliseAbbreviations,
constantsKeyVal,
namesKeyVal,
abbreviationsKeyVal,
wordsToExclude,
} from './plugin-constants';

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

browser.storage.local
.get([
sites_to_ignore,
should_capitalise_i,
should_capitalise_names,
should_capitalise_abbreviations,
constants_key_val,
names_key_val,
abbreviations_key_val,
words_to_exclude,
sitesToIgnore,
shouldCapitaliseI,
shouldCapitaliseNames,
shouldCapitaliseAbbreviations,
constantsKeyVal,
namesKeyVal,
abbreviationsKeyVal,
wordsToExclude,
])
.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 default after installing the extension.
* This block will capture the event and update the value of 'should_capitalise_i'.
* This block will capture the event and update the value of 'shouldCapitaliseI'.
*/
browser.storage.onChanged.addListener(function (
browser.storage.onChanged.addListener(function(
changes, // object
areaName // string
) {
if (areaName === 'local') {
if (changes.should_capitalise_i != null) {
const newValue = changes.should_capitalise_i.newValue;
if (changes.shouldCapitaliseI != null) {
const newValue = changes.shouldCapitaliseI.newValue;

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

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

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

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

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

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

if (newValue != null) {
utils.setWordsToExclude(newValue);
Expand All @@ -81,37 +81,37 @@ function hookupEventHandlers() {
}

function observeIframeInputTags() {
$('iframe').on('load', (event) => {
$('iframe').on('load', event => {
let iframe = event.target;
$(iframe)
.contents()
.find(':text,textarea')
.each((_, item) => {
//console.log(item);

$(item).on(`input.${pluginNamespace}`, function (event) {
$(item).on(`input.${pluginNamespace}`, function(event) {
capitaliseText(event.target);
});
});
});
}

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.setShouldCapitaliseAbbreviations(item.should_capitalise_abbreviations);
utils.setConstantsKeyVal(item.constants_key_val);
utils.setNamesKeyVal(item.names_key_val);
utils.setAbbreviationsKeyVal(item.abbreviations_key_val);
console.log(item.words_to_exclude);
utils.setWordsToExclude(item.words_to_exclude);
sitesToExclude = item.sitesToIgnore;
utils.setShouldCapitaliseI(item.shouldCapitaliseI);
utils.setShouldCapitaliseNames(item.shouldCapitaliseNames);
utils.setShouldCapitaliseAbbreviations(item.shouldCapitaliseAbbreviations);
utils.setConstantsKeyVal(item.constantsKeyVal);
utils.setNamesKeyVal(item.namesKeyVal);
utils.setAbbreviationsKeyVal(item.abbreviationsKeyVal);
console.log(item.wordsToExclude);
utils.setWordsToExclude(item.wordsToExclude);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
Expand All @@ -120,7 +120,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 @@ -148,8 +148,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 @@ -160,30 +160,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
6 changes: 3 additions & 3 deletions src/name-constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let person_names = [
let personNames = [
'Aaliyah',
'Abbott',
'Abby',
Expand Down Expand Up @@ -3672,7 +3672,7 @@ let person_names = [
'Zosma',
];

let company_names = [
let companyNames = [
'Wikileaks',
'Sega',
'Microsoft',
Expand All @@ -3697,4 +3697,4 @@ let company_names = [
'Google',
];

export let names = person_names.concat(company_names);
export let names = personNames.concat(companyNames);
16 changes: 8 additions & 8 deletions src/plugin-constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const pluginNamespace = 'auto-capitalise-extension';

export const sites_to_ignore = 'sites_to_ignore',
words_to_exclude = 'words_to_exclude',
should_capitalise_i = 'should_capitalise_i',
should_capitalise_names = 'should_capitalise_names',
should_capitalise_abbreviations = 'should_capitalise_abbreviations',
constants_key_val = 'constants_key_val',
names_key_val = 'names_key_val',
abbreviations_key_val = 'abbreviations_key_val';
export const sitesToIgnore = 'sitesToIgnore',
wordsToExclude = 'wordsToExclude',
shouldCapitaliseI = 'shouldCapitaliseI',
shouldCapitaliseNames = 'shouldCapitaliseNames',
shouldCapitaliseAbbreviations = 'shouldCapitaliseAbbreviations',
constantsKeyVal = 'constantsKeyVal',
namesKeyVal = 'namesKeyVal',
abbreviationsKeyVal = 'abbreviationsKeyVal';
Loading

0 comments on commit 871dd7f

Please sign in to comment.