From 0b219951ac037ba925174fa6ec1a0a8dffa0e0cf Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Sat, 25 Feb 2017 15:18:11 +0000 Subject: [PATCH] Tidy litcoffee --- addon/src/content.litcoffee | 3 -- addon/src/main.litcoffee | 69 +++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/addon/src/content.litcoffee b/addon/src/content.litcoffee index 23be44da..e6a6d420 100644 --- a/addon/src/content.litcoffee +++ b/addon/src/content.litcoffee @@ -1,7 +1,4 @@ # Just a test -# -# -# config = scrollDown: "j" diff --git a/addon/src/main.litcoffee b/addon/src/main.litcoffee index 36957e2a..1bae53d1 100644 --- a/addon/src/main.litcoffee +++ b/addon/src/main.litcoffee @@ -1,29 +1,19 @@ # main.litcoffee -## Introduction +## Introduction 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. -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. +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. -## TODO: +## TODO: This is a todolist - get web-ext to run FF dev (~/bin/firefox) - - stop coffeescript vim thing from making newline # in markdown - - update vim-coffeescript to highlight await keywords, etc. + - adapt vim-coffeescript to work with litcoffee2 + - 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) -> try @@ -44,26 +34,10 @@ This is a todolist 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 -# -## -# 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) -> sendMessageToActiveTab({command:"history", number:n}) @@ -82,5 +56,34 @@ This is a todolist sendMessageToActiveTab({command:"arbitrary",object,args}) # 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")