Skip to content

Commit

Permalink
WebExtensions conversion in progress. Mostly working.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-p committed Jun 13, 2016
1 parent dc1454e commit f228a34
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 40 deletions.
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
# WebExtensions notes

* Ampersand in context menu item (just remove? programmatically?)
* Toolbar logo looks crap on dark background
- Doesn't seem to be a way to detect theme and show appropriate icon. (See [this SO question](https://stackoverflow.com/questions/37366781/how-to-detect-firefox-theme)). Maybe will need to provide an option for user to choose icon.
* Hotkey doesn't work
* Build stuff and MetaScript stuff will need to change. Separate Firefox from Thunderbird et al.
* `applications` key can't be in `manifest.json` for Chrome
* Decide on whether to keep using AMO.


# ![Markdown Here logo](https://raw.github.com/adam-p/markdown-here/master/src/common/images/icon48.png) Markdown Here

[**Visit the website.**](http://markdown-here.com)
[**Get it for Chrome.**](https://chrome.google.com/webstore/detail/elifhakcjgalahccnjkneoccemfahfoa)
[**Get it for Firefox.**](https://addons.mozilla.org/en-US/firefox/addon/markdown-here/)
[**Get it for Safari.**](https://s3.amazonaws.com/markdown-here/markdown-here.safariextz)
[**Get it for Thunderbird and Postbox.**](https://addons.mozilla.org/en-US/thunderbird/addon/markdown-here/)
[**Get it for Opera.**](https://addons.opera.com/en/extensions/details/markdown-here/)
[**Discuss it and ask questions in the Google Group.**](https://groups.google.com/forum/?fromgroups#!forum/markdown-here/)
[**Visit the website.**](http://markdown-here.com)<br>
[**Get it for Chrome.**](https://chrome.google.com/webstore/detail/elifhakcjgalahccnjkneoccemfahfoa)<br>
[**Get it for Firefox.**](https://addons.mozilla.org/en-US/firefox/addon/markdown-here/)<br>
[**Get it for Safari.**](https://s3.amazonaws.com/markdown-here/markdown-here.safariextz)<br>
[**Get it for Thunderbird and Postbox.**](https://addons.mozilla.org/en-US/thunderbird/addon/markdown-here/)<br>
[**Get it for Opera.**](https://addons.opera.com/en/extensions/details/markdown-here/)<br>
[**Discuss it and ask questions in the Google Group.**](https://groups.google.com/forum/?fromgroups#!forum/markdown-here/)<br>

*Markdown Here* is a Google Chrome, Firefox, Safari, Opera, and Thunderbird extension that lets you write email<sup>&dagger;</sup> in Markdown<sup>&Dagger;</sup> and render them before sending. It also supports syntax highlighting (just specify the language in a fenced code block).

Writing email with code in it is pretty tedious. Writing Markdown with code in it is easy. I found myself writing email in Markdown in the Github in-browser editor, then copying the preview into email. This is a pretty absurd workflow, so I decided create a tool to write and render Markdown right in the email.

To discover what can be done with Markdown in *Markdown Here*, check out the [Markdown Here Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet) and the other [wiki pages](https://github.com/adam-p/markdown-here/wiki).

<sup>&dagger;: And Google Groups posts, and Blogger posts, and Evernote notes, and Wordpress posts! [See more](#compatibility).</sup>
<sup>&dagger;: And Google Groups posts, and Blogger posts, and Evernote notes, and Wordpress posts! [See more](#compatibility).</sup><br>
<sup>&Dagger;: And TeX mathematical formulae!</sup>

![screenshot of conversion](https://raw.github.com/adam-p/markdown-here/master/store-assets/markdown-here-image1.gimp.png)

### Table of Contents
**[Installation Instructions](#installation-instructions)**
**[Usage Instructions](#usage-instructions)**
**[Troubleshooting](#troubleshooting)**
**[Compatibility](#compatibility)**
**[Notes and Miscellaneous](#notes-and-miscellaneous)**
**[Building the Extension Bundles](#building-the-extension-bundles)**
**[Next Steps, Credits, Feedback, License](#next-steps)**
**[Installation Instructions](#installation-instructions)**<br>
**[Usage Instructions](#usage-instructions)**<br>
**[Troubleshooting](#troubleshooting)**<br>
**[Compatibility](#compatibility)**<br>
**[Notes and Miscellaneous](#notes-and-miscellaneous)**<br>
**[Building the Extension Bundles](#building-the-extension-bundles)**<br>
**[Next Steps, Credits, Feedback, License](#next-steps)**<br>

## Installation Instructions

Expand Down Expand Up @@ -66,7 +77,7 @@ After installing, make sure to restart Firefox/Thunderbird!

### Safari

[Download the extension directly.](https://s3.amazonaws.com/markdown-here/markdown-here.safariextz) When it has finished downloading, double click it to install.
[Download the extension directly.](https://s3.amazonaws.com/markdown-here/markdown-here.safariextz) When it has finished downloading, double click it to install.

#### Preferences

Expand Down Expand Up @@ -113,7 +124,7 @@ In Gmail, you can also use the browser's Undo command (<kbd>CTRL</kbd>+<kbd>Z</k

### Replies

In Gmail, Thunderbird, and Google Groups, you can use "Markdown Toggle" normally: just write your reply (top, bottom, inline, wherever) and then convert. The original email that you're replying to will be left alone. (Technically: Existing `blockquote` blocks will be left intact.)
In Gmail, Thunderbird, and Google Groups, you can use "Markdown Toggle" normally: just write your reply (top, bottom, inline, wherever) and then convert. The original email that you're replying to will be left alone. (Technically: Existing `blockquote` blocks will be left intact.)

In Hotmail and Yahoo (which don't put the original in a `blockquote`), and optionally in Gmail, Thunderbird, and Google Groups, you can ensure that only the part of the reply that you wrote gets converted by selecting what you want to convert and then clicking "Markdown Toggle" -- see the next section.

Expand Down Expand Up @@ -142,7 +153,7 @@ The *Markdown Here* Options page can be accessed via the Chrome, Firefox, Safari
* TeX math formulae processing enabling and customization.
* What the hotkey should be.

For Chrome and Firefox, any changes made in the *Markdown Here* Options are automatically synchronized between your other installations of that browser (if you have the sync feature enabled in the browser).
For Chrome and Firefox, any changes made in the *Markdown Here* Options are automatically synchronized between your other installations of that browser (if you have the sync feature enabled in the browser).

![screenshot of options](https://raw.githubusercontent.com/adam-p/markdown-here/master/store-assets/markdown-here-chrome-options-1.gimp.png)

Expand Down Expand Up @@ -182,8 +193,7 @@ See the [Compatibility wiki page](https://github.com/adam-p/markdown-here/wiki/C

Before zipping, delete the `src/common/test` directory. This will prevent the autotests from ending up in the release.

An important preparatory step is to remove any system-generated hidden files that shouldn't be
included in the release file (like Windows' `desktop.ini` and OS X's `.DS_Store`, etc.). This shell command will delete those unwanted files:
An important preparatory step is to remove any system-generated hidden files that shouldn't be included in the release file (like Windows' `desktop.ini` and OS X's `.DS_Store`, etc.). This shell command will delete those unwanted files:

```
find . -name "desktop.ini" -or -name ".*" -and -not -name "." -and -not -name ".git*" -print0 | xargs -0 rm -rf
Expand Down
10 changes: 5 additions & 5 deletions src/chrome/backgroundscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ chrome.contextMenus.create({

// Handle rendering requests from the content script.
// See the comment in markdown-render.js for why we do this.
chrome.extension.onMessage.addListener(function(request, sender, responseCallback) {
chrome.runtime.onMessage.addListener(function(request, sender, responseCallback) {
// The content script can load in a not-real tab (like the search box), which
// has an invalid `sender.tab` value. We should just ignore these pages.
if (typeof(sender.tab) === 'undefined' ||
Expand Down Expand Up @@ -95,8 +95,8 @@ chrome.extension.onMessage.addListener(function(request, sender, responseCallbac
tabId: sender.tab.id });
chrome.browserAction.setIcon({
path: {
19: Utils.getLocalURL('/common/images/icon19-button-monochrome.png'),
38: Utils.getLocalURL('/common/images/icon38-button-monochrome.png')
"19": Utils.getLocalURL('/common/images/icon19-button-monochrome.png'),
"38": Utils.getLocalURL('/common/images/icon38-button-monochrome.png')
},
tabId: sender.tab.id });
return false;
Expand All @@ -108,8 +108,8 @@ chrome.extension.onMessage.addListener(function(request, sender, responseCallbac
tabId: sender.tab.id });
chrome.browserAction.setIcon({
path: {
19: Utils.getLocalURL('/common/images/icon19-button-disabled.png'),
38: Utils.getLocalURL('/common/images/icon38-button-disabled.png')
"19": Utils.getLocalURL('/common/images/icon19-button-disabled.png'),
"38": Utils.getLocalURL('/common/images/icon38-button-disabled.png')
},
tabId: sender.tab.id });
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function requestHandler(request, sender, sendResponse) {
return false;
}
}
chrome.extension.onMessage.addListener(requestHandler);
chrome.runtime.onMessage.addListener(requestHandler);


// The rendering service provided to the content script.
Expand Down
15 changes: 8 additions & 7 deletions src/common/options-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var ChromeOptionsStore = {
// Note that chrome.storage.sync.QUOTA_BYTES_PER_ITEM is in bytes, but JavaScript
// strings are UTF-16, so we need to divide by 2.
// Some JS string info: http://rosettacode.org/wiki/String_length#JavaScript
if (chrome.storage) {
if (chrome.storage && chrome.storage.sync && chrome.storage.sync.QUOTA_BYTES_PER_ITEM) {
return chrome.storage.sync.QUOTA_BYTES_PER_ITEM / 2;
}
else {
Expand All @@ -153,7 +153,7 @@ var ChromeOptionsStore = {

_storageGet: function(callback) {
if (chrome.storage) {
chrome.storage.sync.get(null, function(obj) {
(chrome.storage.sync || chrome.storage.local).get(null, function(obj) {
var key;
for (key in obj) {
// Older settings aren't JSON-encoded, so they'll throw an exception.
Expand Down Expand Up @@ -194,7 +194,7 @@ var ChromeOptionsStore = {
}

if (chrome.storage) {
chrome.storage.sync.set(finalobj, callback);
(chrome.storage.sync || chrome.storage.local).set(finalobj, callback);
return;
}
else {
Expand All @@ -212,7 +212,7 @@ var ChromeOptionsStore = {

_storageRemove: function(keysToDelete, callback) {
if (chrome.storage) {
chrome.storage.sync.remove(keysToDelete, callback);
(chrome.storage.sync || chrome.storage.local).remove(keysToDelete, callback);
return;
}
else {
Expand Down Expand Up @@ -302,7 +302,7 @@ var MozillaOptionsStore = {
// When called from a background script, we're going to access the browser prefs
// directly. Unfortunately, this means duplicating some code from the background
// service.
_sendRequest: function(data, callback) { // analogue of chrome.extension.sendMessage
_sendRequest: function(data, callback) { // analogue of chrome.runtime.sendMessage
var extPrefsBranch, supportString, prefKeys, prefsObj, request, sender, i;

try {
Expand Down Expand Up @@ -488,13 +488,14 @@ var SafariOptionsStore = {


/*? if(platform!=='mozilla'){ */
if (typeof(navigator) !== 'undefined' && navigator.userAgent.indexOf('Chrome') >= 0) {
if (typeof(navigator) !== 'undefined' &&
(navigator.userAgent.indexOf('Chrome') >= 0 || navigator.userAgent.indexOf('Firefox') >= 0)) {
this.OptionsStore = ChromeOptionsStore;
}
else if (typeof(navigator) !== 'undefined' && navigator.userAgent.match(/AppleWebKit.*Version.*Safari/)) {
this.OptionsStore = SafariOptionsStore;
}
else /*? } */ {
else /*? } */ { // Thunderbird, Postbox, Icedove
this.OptionsStore = MozillaOptionsStore;
}

Expand Down
11 changes: 8 additions & 3 deletions src/common/test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,15 @@ describe('Utils', function() {

// The sibling of the selected node *is not* intersected.
expect(Utils.rangeIntersectsNode(range, $('#test-elem-2')[0])).to.be.false;
});

// I have found that Range.intersectsNode is broken on Chrome. I'm adding
// test to see if/when it gets fixed.
it('Range.intersectsNode is broken on Chrome', function() {
var range = document.createRange();
range.selectNode($('#test-elem-1')[0]);

// I have found that Range.intersectsNode is broken on Chrome. I'm adding
// test to see if/when it gets fixed.
if (typeof(window.chrome) !== 'undefined') {
if (typeof(window.chrome) !== 'undefined' && navigator.userAgent.indexOf('Chrome') >= 0) {
expect(range.intersectsNode($('#test-elem-2')[0])).to.be.true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ function makeRequestToPrivilegedScript(doc, requestObj, callback) {
// If `callback` is undefined and we pass it anyway, Chrome complains with this:
// Uncaught Error: Invocation of form extension.sendMessage(object, undefined, null) doesn't match definition extension.sendMessage(optional string extensionId, any message, optional function responseCallback)
if (callback) {
chrome.extension.sendMessage(requestObj, callback);
chrome.runtime.sendMessage(requestObj, callback);
}
else {
chrome.extension.sendMessage(requestObj);
chrome.runtime.sendMessage(requestObj);
}
}
else if (typeof(safari) !== 'undefined') {
Expand Down
13 changes: 11 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "2.12.0",
"description": "__MSG_app_slogan__",
"homepage_url": "http://markdown-here.com",
"minimum_chrome_version": "6",
"default_locale": "en",
"icons": {
"16": "common/images/icon16.png",
Expand Down Expand Up @@ -36,5 +35,15 @@
},
"default_title": "__MSG_toggle_button_tooltip__"
},
"options_page": "common/options.html"
"options_ui": {
"page": "common/options.html",
"open_in_tab": true
},

"applications": {
"gecko": {
"id": "[email protected]",
"update_url": "https://example.com/updates.json"
}
}
}

0 comments on commit f228a34

Please sign in to comment.