mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
Tidy litcoffee
This commit is contained in:
parent
17c1bbc05f
commit
0b219951ac
2 changed files with 36 additions and 36 deletions
|
@ -1,7 +1,4 @@
|
||||||
# Just a test
|
# Just a test
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
config =
|
config =
|
||||||
scrollDown: "j"
|
scrollDown: "j"
|
||||||
|
|
|
@ -1,29 +1,19 @@
|
||||||
# main.litcoffee
|
# main.litcoffee
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
We're writing everything in CoffeeScript v2: http://coffeescript.org/v2/
|
We're writing everything in CoffeeScript v2: http://coffeescript.org/v2/
|
||||||
You can install it with `npm install --global coffeescript@next`. You need Firefox version 52+ to use the `await` command we are using here.
|
You can install it with `npm install --global coffeescript@next`. You need Firefox version 52+ to use the `await` command we are using here.
|
||||||
|
|
||||||
Functions declared here can be called in the debug window in ff. This is the main
|
Functions declared here can be called in the debug window in ff. This is the main background script that can access all of the WebExtension APIs.
|
||||||
background script that can access all of the WebExtension APIs.
|
|
||||||
|
|
||||||
## TODO:
|
## TODO:
|
||||||
This is a todolist
|
This is a todolist
|
||||||
- get web-ext to run FF dev (~/bin/firefox)
|
- get web-ext to run FF dev (~/bin/firefox)
|
||||||
- stop coffeescript vim thing from making newline # in markdown
|
- adapt vim-coffeescript to work with litcoffee2
|
||||||
- update vim-coffeescript to highlight await keywords, etc.
|
- stop coffeescript vim thing from making newline # in markdown
|
||||||
|
- update vim-coffeescript to highlight await keywords, etc.
|
||||||
|
|
||||||
handleBrowserAction = () ->
|
|
||||||
# .then takes a function that consumes at least one argument. this is an
|
|
||||||
# example of a named function, but anonymous functions are fine, too.
|
|
||||||
x = await browser.tabs.query({active: true}).then(console.log)
|
|
||||||
|
|
||||||
|
|
||||||
# Example of a listener. Presumably we wouldn't use the browserAction button in
|
|
||||||
# the real thing.
|
|
||||||
|
|
||||||
browser.browserAction.onClicked.addListener(handleBrowserAction)
|
|
||||||
|
|
||||||
incTab = (inc) ->
|
incTab = (inc) ->
|
||||||
try
|
try
|
||||||
|
@ -44,26 +34,10 @@ This is a todolist
|
||||||
desiredTab = tab for tab in tabs when tab.index == desIndex
|
desiredTab = tab for tab in tabs when tab.index == desIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
# modulus that always returns a non-negative number, as mathematicians expect.
|
|
||||||
#
|
|
||||||
# In mathematics, mod usually returns the remainder of euclidean division of
|
|
||||||
# two numbers and the remainder is always positive.
|
|
||||||
#
|
|
||||||
# In most programming languages, mod can return a negative number and the
|
|
||||||
# return value of mod always matches the sign of one or the other of the
|
|
||||||
# arguments. In JS the built-in % operator's returned value always has the same
|
|
||||||
# sign as the dividend, in python, the divisor.
|
|
||||||
|
|
||||||
Number.prototype.mod = (n) ->
|
|
||||||
Math.abs(this % n)
|
|
||||||
|
|
||||||
##
|
|
||||||
#
|
|
||||||
# First attempt at message parsing wrapper to avoid duplication of code
|
# First attempt at message parsing wrapper to avoid duplication of code
|
||||||
#
|
|
||||||
##
|
|
||||||
|
|
||||||
# The following functions all talk to the content.js script
|
The following functions all talk to the content.js script to perform functions that need to operate on, e.g., the `window.history` object.
|
||||||
|
|
||||||
goHistory = (n) ->
|
goHistory = (n) ->
|
||||||
sendMessageToActiveTab({command:"history", number:n})
|
sendMessageToActiveTab({command:"history", number:n})
|
||||||
|
@ -82,5 +56,34 @@ This is a todolist
|
||||||
sendMessageToActiveTab({command:"arbitrary",object,args})
|
sendMessageToActiveTab({command:"arbitrary",object,args})
|
||||||
# example: doArbitraryCodeInWindow("scrollBy",[0,100])
|
# example: doArbitraryCodeInWindow("scrollBy",[0,100])
|
||||||
|
|
||||||
|
## Listener test
|
||||||
|
|
||||||
|
handleBrowserAction = () ->
|
||||||
|
# .then takes a function that consumes at least one argument. this is an
|
||||||
|
# example of a named function, but anonymous functions are fine, too.
|
||||||
|
x = await browser.tabs.query({active: true}).then(console.log)
|
||||||
|
|
||||||
|
|
||||||
|
# Example of a listener. Presumably we wouldn't use the browserAction button in
|
||||||
|
# the real thing.
|
||||||
|
|
||||||
|
browser.browserAction.onClicked.addListener(handleBrowserAction)
|
||||||
|
|
||||||
|
# Misc helper functions
|
||||||
|
## Modulus
|
||||||
|
modulus that always returns a non-negative number, as mathematicians expect.
|
||||||
|
|
||||||
|
In mathematics, mod usually returns the remainder of euclidean division of
|
||||||
|
two numbers and the remainder is always positive.
|
||||||
|
|
||||||
|
In most programming languages, mod can return a negative number and the
|
||||||
|
return value of mod always matches the sign of one or the other of the
|
||||||
|
arguments. In JS the built-in % operator's returned value always has the same
|
||||||
|
sign as the dividend, in python, the divisor.
|
||||||
|
|
||||||
|
Number.prototype.mod = (n) ->
|
||||||
|
Math.abs(this % n)
|
||||||
|
|
||||||
|
## Check to see that the addon has been loaded successfully
|
||||||
|
|
||||||
console.log("Loaded Tridactyl")
|
console.log("Loaded Tridactyl")
|
||||||
|
|
Loading…
Add table
Reference in a new issue