Skip to content

Commit a02cadf

Browse files
committed
#57 Selected html text can be saved to file
1 parent 8609914 commit a02cadf

20 files changed

+95
-16
lines changed

data/html/ConfirmPanel.html

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
<input id="confirmPanel" type="checkbox">
113113
</td>
114114
</tr>
115+
<tr>
116+
<td>
117+
<div data-l10n-id="html_title"></div>
118+
</td>
119+
<td>
120+
<input id="html" type="checkbox">
121+
</td>
122+
</tr>
115123
<tr>
116124
<td>
117125
<div data-l10n-id="showWidget_title"></div>

data/js/ConfirmPanel.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ window.addEventListener('click', function(event) {
3030
// functions available to Panel
3131
var SaveTextToFile_Panel = {
3232

33-
updateTimestampInFilename: function() {
34-
alert('c');
35-
},
36-
3733
selectDir: function() {
3834
self.port.emit("selectDir", '');
3935
},
@@ -55,6 +51,7 @@ var SaveTextToFile_Panel = {
5551
pagenameForFilename: document.getElementById("pagenameForFilename").checked,
5652
saveMode: document.getElementById("saveMode").value,
5753
confirmPanel: document.getElementById("confirmPanel").checked,
54+
html: document.getElementById("html").checked,
5855
showWidget: document.getElementById("showWidget").checked,
5956
showNotifications: document.getElementById("showNotifications").checked
6057
});
@@ -84,6 +81,7 @@ self.port.on("prefs", function (prefs) {
8481
document.getElementById("pagenameForFilename").checked = parsedPrefs.pagenameForFilename;
8582
document.getElementById("saveMode").value = parsedPrefs.saveMode;
8683
document.getElementById("confirmPanel").checked = parsedPrefs.confirmPanel;
84+
document.getElementById("html").checked = parsedPrefs.html;
8785
document.getElementById("showWidget").checked = parsedPrefs.showWidget;
8886
document.getElementById("showNotifications").checked = parsedPrefs.showNotifications;
8987

data/js/SendSelectedText.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
function getText(){
22

3-
self.postMessage(window.getSelection().toString());
3+
4+
var html = "";
5+
if (typeof window.getSelection != "undefined") {
6+
var sel = window.getSelection();
7+
if (sel.rangeCount) {
8+
var container = document.createElement("div");
9+
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
10+
container.appendChild(sel.getRangeAt(i).cloneContents());
11+
}
12+
html = container.innerHTML;
13+
}
14+
} else if (typeof document.selection != "undefined") {
15+
if (document.selection.type == "Text") {
16+
html = document.selection.createRange().htmlText;
17+
}
18+
}
19+
20+
self.postMessage(
21+
JSON.stringify({
22+
plain: window.getSelection().toString(),
23+
html: html
24+
})
25+
);
426
}

lib/ContextMenu.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var ContextMenu = require("sdk/context-menu"),
22
Localisation = require("./Localisation"),
33
File = require("./File"),
4-
Data = require("./Data");
4+
Data = require("./Data"),
5+
Preference = require("./Preference");
56

67
exports.init = function() {
78

@@ -10,9 +11,18 @@ exports.init = function() {
1011
label: Localisation.getString("saveTextToFile_id"),
1112
context: ContextMenu.SelectionContext(),
1213
contentScriptFile: [ Data.get("js/ListenForContextClick.js"), Data.get("js/SendSelectedText.js") ],
13-
onMessage: function (selectedText) {
14+
onMessage: function (text) {
1415

15-
File.saveTo(selectedText);
16+
console.log(Preference.get('html'));
17+
console.log('html: ' + JSON.parse(text).html);
18+
console.log('plain: ' + JSON.parse(text).plain);
19+
20+
21+
if (Preference.get('html')){
22+
File.saveTo(JSON.parse(text).html);
23+
}else {
24+
File.saveTo(JSON.parse(text).plain);
25+
}
1626
}
1727
});
1828
};

lib/Panel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exports.init = function() {
1111

1212
panel = Panel.Panel({
1313
width: 490,
14-
height: 500,
14+
height: 525,
1515
contentURL: Data.get("html/ConfirmPanel.html"),
1616
contentScriptFile: Data.get("js/ConfirmPanel.js"),
1717
onShow: function() {
@@ -41,6 +41,7 @@ exports.init = function() {
4141
Preference.set('pagenameForFilename', parsedPerfs.pagenameForFilename);
4242
Preference.set('saveMode', parseInt(parsedPerfs.saveMode));
4343
Preference.set('confirmPanel', parsedPerfs.confirmPanel);
44+
Preference.set('html', parsedPerfs.html);
4445
Preference.set('showWidget', parsedPerfs.showWidget);
4546
Preference.set('showNotifications', parsedPerfs.showNotifications);
4647

@@ -98,6 +99,7 @@ function getPreferences() {
9899
pagenameForFilename: Preference.get('pagenameForFilename'),
99100
saveMode: Preference.get('saveMode'),
100101
confirmPanel: Preference.get('confirmPanel'),
102+
html: Preference.get('html'),
101103
showWidget: Preference.get('showWidget'),
102104
showNotifications: Preference.get('showNotifications')
103105
});

lib/Selection.js

-6
This file was deleted.

locale/cs-CZ.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Připojit k existujícímu souboru
5757

5858
confirmPanel_title=Potvrdit dialogové okno preferencí?
5959
confirmPanel_description=Otevřít dialogové okno preferencí při "uložit text do souboru" kliknutí?
60+
61+
html_title=Uložit vybraného textu ve formátu HTML?
62+
html_description=Uložit vybraného textu ve formátu HTML?

locale/de-DE.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=An vorhandene Datei anh�ngen
5757

5858
confirmPanel_title=Best�tigen Einstellungen-Dialog ?
5959
confirmPanel_description=�ffnen -Dialog , wenn "Save Text to File" geklickt wird ?
60+
61+
html_title=Speichern ausgewählt html Text?
62+
html_description=Speichern ausgewählt html Text?

locale/en-GB.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Append to existing file
5757

5858
confirmPanel_title=Confirm settings?
5959
confirmPanel_description=Open preferences dialog when "Save Text to File" is clicked?
60+
61+
html_title=Save selected html text?
62+
html_description=Save selected html text?

locale/en-US.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Append to existing file
5757

5858
confirmPanel_title=Confirm settings?
5959
confirmPanel_description=Open preferences dialog when "Save Text to File" is clicked?
60+
61+
html_title=Save selected html text?
62+
html_description=Save selected html text?

locale/es-ES.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Anexar al archivo existente
5757

5858
confirmPanel_title=di�logo Confirmar preferencias?
5959
confirmPanel_description=abierto al di�logo de preferencias " Guardar texto en archivo " se hace clic ?
60+
61+
html_title=Guardar texto HTML seleccionado?
62+
html_description=Guardar texto HTML seleccionado?

locale/fr-FR.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Ajouter au fichier existant
5757

5858
confirmPanel_title=Confirmer dialogue des pr�f�rences ?
5959
confirmPanel_description=dialogue des pr�f�rences ouverte lorsque " Sauvegarder le texte en fichier " est cliqu� ?
60+
61+
html_title=Enregistrer le texte HTML sélectionné?
62+
html_description=Enregistrer le texte HTML sélectionné?

locale/it-IT.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Aggiunge a file
5757

5858
confirmPanel_title=finestra di dialogo Confirm preferenze ?
5959
confirmPanel_description=Quando "Salva testo su file" viene cliccato finestra di dialogo Apri le preferenze?
60+
61+
html_title=Salva html testo selezionato?
62+
html_description=Salva html testo selezionato?

locale/ja-JP.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=既存のファイルに追加
5757

5858
confirmPanel_title=設定を確認
5959
confirmPanel_description="テキストをファイルに保存"をクリックしたとき設定ダイアログを開く
60+
61+
html_title=選択されたHTMLテキストを保存しますか?
62+
html_description=選択されたHTMLテキストを保存しますか?

locale/ko-KR.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=기존 파일에 추가
5757

5858
confirmPanel_title=환경 설정 대화 상자를 확인?
5959
confirmPanel_description=환경 설정 열기 대화 상자가 때 "파일에 텍스트 저장"을 클릭?
60+
61+
html_title=선택한 HTML 텍스트를 저장 하시겠습니까?
62+
html_description=선택한 HTML 텍스트를 저장 하시겠습니까?

locale/pl-PL.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Dołącz do istniejącego pliku
5757

5858
confirmPanel_title=Potwierdź okno preferencji?
5959
confirmPanel_description=Otwórz okno preferencji, gdy "Zapisz tekst do pliku" kliknięciu?
60+
61+
html_title=Zapisz zaznaczony tekst HTML?
62+
html_description=Zapisz zaznaczony tekst HTML?

locale/ru-RU.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Добавление в существующий фай
5757

5858
confirmPanel_title=Подтвердите диалог настроек?
5959
confirmPanel_description=Открытый диалог настроек, когда "Сохранить текст в файл" нажата?
60+
61+
html_title=Сохранить выбранный HTML текст?
62+
html_description=Сохранить выбранный HTML текст?

locale/uk-UA.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=Dodavannya v isnuyuchyy̆ fay̆l
5757

5858
confirmPanel_title=Підтвердіть діалог налаштувань?
5959
confirmPanel_description=Відкритий діалог налаштувань, коли "Зберегти текст у файл" натиснута?
60+
61+
html_title=Зберегти обраний HTML текст?
62+
html_description=Зберегти обраний HTML текст?

locale/zh-CH.properties

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ saveMode_options.Append=附加到現有文件
5757

5858
confirmPanel_title=確認首選項對話框?
5959
confirmPanel_description=打開首選項“對話框中點擊”保存文本文件“?
60+
61+
html_title=保存所選的HTML文本?
62+
html_description=保存所選的HTML文本?

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Saves highlighted text to a file in a specified directory",
66
"author": "Robert Byrne",
77
"license": "GNU GPL v3",
8-
"version": "2.2.5",
8+
"version": "2.3",
99
"permissions": {"private-browsing": true},
1010
"preferences": [{
1111
"name": "fileName",
@@ -134,5 +134,11 @@
134134
"title": "Confirm settings?",
135135
"type": "bool",
136136
"value": true
137+
},
138+
{
139+
"name": "html",
140+
"title": "Save selected html text?",
141+
"type": "bool",
142+
"value": false
137143
}]
138144
}

0 commit comments

Comments
 (0)