-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita
committed
Oct 14, 2020
1 parent
34df2d7
commit 659f53c
Showing
15 changed files
with
147 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import setHotkey from "hotkeys-js"; | ||
import { defaultStorage, IStorage } from "./common/storage"; | ||
import { startFiltersOnHotkey, startSwapHashtagsOnHotkey } from "./content_scripts/hotkey"; | ||
import { createObserver, highlight, renderTotalTime } from "./content_scripts/time"; | ||
|
||
// By default hotkeys are not enabled for INPUT, SELECT, TEXTAREA elements. | ||
setHotkey.filter = function (event) { | ||
return true; | ||
}; | ||
|
||
chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swapHashtags }: IStorage) => { | ||
// Start calculate total time | ||
if (calcTotalTime) { | ||
highlight(); | ||
renderTotalTime(); | ||
createObserver(); | ||
} | ||
|
||
startFiltersOnHotkey(filters); | ||
|
||
if (swapHashtags) { | ||
startSwapHashtagsOnHotkey(swapHashtags); | ||
} | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import setHotkey from "hotkeys-js"; | ||
import type { IStorage } from "../common/storage"; | ||
import { createHashtag } from "./dom"; | ||
|
||
export function startFiltersOnHotkey(filters: IStorage["filters"]) { | ||
for (const filter of filters) { | ||
setHotkey(`${filter.specialKey}+${filter.key}`, function (event, handler) { | ||
// Prevent the default refresh event under WINDOWS system | ||
event.preventDefault(); | ||
|
||
if (filter.hashtags) { | ||
location.hash = | ||
"?q=" + filter.hashtags.split(" ").reduce((acc, val) => `${acc}#${val} `, ""); | ||
} else { | ||
location.hash = ""; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export function startSwapHashtagsOnHotkey(swapHashtags: IStorage["swapHashtags"]) { | ||
setHotkey(`${swapHashtags.specialKey}+${swapHashtags.key}`, function (event, handler) { | ||
// Prevent the default refresh event under WINDOWS system | ||
event.preventDefault(); | ||
|
||
const activeElement = document.activeElement; | ||
const innerContentContainer = activeElement.querySelector(".innerContentContainer"); | ||
|
||
if (innerContentContainer) { | ||
const deleteTags = swapHashtags.delete ? swapHashtags.delete.split(" ") : []; | ||
const insertTags = swapHashtags.insert ? swapHashtags.insert.split(" ") : []; | ||
|
||
for (const tag of document.activeElement.querySelectorAll(".contentTag")) { | ||
const contentTagText = tag.querySelector(".contentTagText"); | ||
|
||
if (deleteTags.includes(contentTagText.textContent)) { | ||
tag.remove(); | ||
} | ||
} | ||
|
||
for (const tag of insertTags) { | ||
innerContentContainer.append(" "); | ||
innerContentContainer.append(createHashtag(tag)); | ||
// remove possible resulting double spaces | ||
innerContentContainer.innerHTML = innerContentContainer.innerHTML.replace( | ||
/\s{2,}\<span/g, | ||
" <span" | ||
); | ||
} | ||
|
||
// Reset focus to force save changes in workflowy | ||
(activeElement as HTMLElement).blur(); | ||
(activeElement as HTMLElement).focus(); | ||
} | ||
}); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import Options from "./components/Options.svelte"; | ||
import Options from "./options/components/Options.svelte"; | ||
|
||
new Options({ target: document.body }); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script lang="ts"> | ||
import { keys, specialKeys } from "../../common/keyboard-keys"; | ||
export let key = ""; | ||
export let specialKey = ""; | ||
</script> | ||
|
||
<style> | ||
</style> | ||
|
||
<td> | ||
<select bind:value={specialKey}> | ||
{#each specialKeys as specialKey} | ||
<option value={specialKey}>{specialKey}</option> | ||
{/each} | ||
</select> | ||
</td> | ||
<td> | ||
<select bind:value={key}> | ||
{#each keys as key} | ||
<option value={key}>{key}</option> | ||
{/each} | ||
</select> | ||
</td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters