Skip to content

Commit

Permalink
Merge pull request #131 from cleidigh/v2.1.2
Browse files Browse the repository at this point in the history
V2.1.3
  • Loading branch information
cleidigh authored Jul 9, 2022
2 parents e7d5591 + f3860d5 commit 6776320
Show file tree
Hide file tree
Showing 48 changed files with 1,356 additions and 830 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "PrintingTools NG",
"name": "printing-tools-ng",
"version": "2.1.1",
"version": "2.1.3",
"description": "Message Printing Tools NG",
"author": "Christopher Leidigh",
"engines": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions scripts/translate-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const translate = new Translate({ projectId, key });
// console.debug( translate );
var translationArray = [
// { key: "", text: "" },
{ key: "date_custom.label", text: "Custom"},
{ key: "messageBody", text: "Message Body"},


];
Expand Down Expand Up @@ -407,7 +407,7 @@ function loadTranslationArray(inputFiles, options) {
}

// manifest files
var options = {
var optionsM = {
inputLocaleDir: `./src/_locales/en-US`,
outputLocaleDir: "./src/_locales",
outputLocaleDirSuffix: "",
Expand All @@ -416,7 +416,7 @@ var options = {
};

// files from array
var options3 = {
var options = {
inputLocaleDir: `./src/chrome/locale/en-US/`,
outputLocaleDir: "./src/chrome/locale",
outputLocaleDirSuffix: "",
Expand Down Expand Up @@ -450,7 +450,7 @@ let inputFiles = ["printingtoolsng.dtd"];
// 'el', 'pl', 'da', 'pt-PT'];

// printingtools
var localeFolders = ['ca', 'da-DK', 'de', 'el', 'en-US', 'es-ES', 'fi', 'fr-FR', 'gl-ES', 'hu-HU',
var localeFolders = ['ja', 'ca', 'da-DK', 'de-DE', 'el', 'en-US', 'es-ES', 'fi', 'fr-FR', 'gl-ES', 'hu-HU',
'hy-AM', 'it-IT', 'ko-KR', 'nl', 'nb-NO', 'pl', 'pt-PT', 'ru', 'sk-SK', 'sl-SI', 'sv-SE', 'uk', 'zh-CN', 'zh-TW'];


Expand All @@ -460,16 +460,16 @@ var localeFolders = ['ca', 'da-DK', 'de', 'el', 'en-US', 'es-ES', 'fi', 'fr-FR',
// var localeFolders = ['ca', 'gl-ES', 'hu-HU', 'hy-AM',
// 'sk-SK', 'sl-SI', 'sv-SE'];

//localeFolders = ['zh-TW'];
//localeFolders = ['de-DE'];


// localeFolders = ['ru', 'hu-HU', 'hy-AM', 'ko-KR', 'pl', 'da', 'pt-PT'];
//localeFile = "settings.json";
// t();
translateHelpPage();
//translateHelpPage();
//translatePage();
// translateAll("printingtoolsng.properties", translationArray, options);
//translateAll(inputFiles, translationArray, options3);
translateAll(inputFiles, translationArray, options);
//translateAll("mboximport.dtd", translationArray, options);
//loadTranslationArray(inputFiles, options);
// let inputFiles = ["settings.dtd"];
15 changes: 15 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ browser.runtime.onInstalled.addListener(async (info) => {

messenger.NotifyTools.onNotifyBackground.addListener(async (info) => {
switch (info.command) {
case "getCurrentURL":
//console.log("geturl")
// method one: via tabs in focused window
try {
var w = await browser.windows.getAll({populate: true})
} catch {
return "unknown";
}

let cw = w.find(fw => fw.focused)
//console.log(cw)
let url1 = cw.tabs.find(t => t.active).url;
//console.log(url1);

return url1;
case "getAttatchmentList":

let rv = await getAttatchmentList(info.messageId);
Expand Down
143 changes: 109 additions & 34 deletions src/chrome/content/printingtoolsng-pengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ var printingtools = {
running: false,
extRunning: false,
externalQ: [],
msgRestoration: {},

/** Prints the messages selected in the thread pane. */
PrintSelectedMessages: async function (options) {
Expand Down Expand Up @@ -163,7 +164,7 @@ var printingtools = {


const br = printingtools.previewDoc.querySelector('br');

br.setAttribute("id", "sep1")
//console.log(t)
// Create new range for the page and main headers
const range = new Range();
Expand Down Expand Up @@ -239,6 +240,19 @@ var printingtools = {
printingtools.showAttatchmentBodyTable();
printingtools.restoreIMGstyle();

// restore msg fonts
if (printingtools.msgRestoration.msgFontFamilyOrig) {
printingtools.msgRestoration.msgDiv.style.fontFamily = printingtools.msgRestoration.msgFontFamilyOrig;
}

if (printingtools.msgRestoration.msgFontSizeOrig) {
printingtools.msgRestoration.msgDiv.style.fontSize = printingtools.msgRestoration.msgFontSizeOrig;
}

printingtools.doc.styleSheets[0].deleteRule(printingtools.msgRestoration.ruleIndex);



//console.log("after rest")
//console.log(printingtools.doc.documentElement.outerHTML);

Expand Down Expand Up @@ -454,7 +468,27 @@ var printingtools = {

cmd_printng: async function (options) {

//console.log("cmd_printng start" + this.running);
console.log("cmd_printng start" + this.running);

// only process mail types else use TB print #119
let url = await window.ptngAddon.notifyTools.notifyBackground({ command: "getCurrentURL" });
//console.log(url)

let mailType = false;
if ((url.startsWith("imap") ||
url.startsWith("mailbox") ||
url.startsWith("unknown") ||
url.startsWith("file")) &&
!url.includes("&type=")) {
mailType = true;
} else {
mailType = false;
}

if (!mailType) {
goDoCommand("cmd_print");
return;
}


options = options || {};
Expand Down Expand Up @@ -1087,30 +1121,61 @@ var printingtools = {
// if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.messages.black_text"))
// printingtools.doc.body.removeAttribute("text");

var hSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.headers.size");

var mSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.messages.size");

if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.messages.style")) {
var mSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.messages.size");
var mFamily = printingtools.getComplexPref("extensions.printingtoolsng.messages.font_family");
if (printingtools.prefs.getIntPref("extensions.printingtoolsng.messages.style_apply") == 0) {
rule = '* {font-size: +' + mSize + 'px !important; font-family: ' + mFamily + ' !important;}';
printingtools.doc.styleSheets[0].insertRule(rule, printingtools.doc.styleSheets[0].cssRules.length);

var rule;
let mozPlainTextDiv = printingtools.doc.querySelector("div.moz-text-plain");
let mozTextFlowedDiv = printingtools.doc.querySelector("div.moz-text-flowed");
let mozTextHtmlDiv = printingtools.doc.querySelector("div.moz-text-html");

if (mozPlainTextDiv) {
printingtools.msgRestoration.msgDiv = mozPlainTextDiv;
printingtools.msgRestoration.msgFontFamilyOrig = mozPlainTextDiv.style.fontFamily;
printingtools.msgRestoration.msgFontSizeOrig = mozPlainTextDiv.style.fontSize;
mozPlainTextDiv.style.fontFamily = mFamily;
mozPlainTextDiv.style.fontSize = mSize;
} else if (mozTextFlowedDiv) {
printingtools.msgRestoration.msgDiv = mozTextFlowedDiv;
printingtools.msgRestoration.msgFontFamilyOrig = mozTextFlowedDiv.style.fontFamily;
printingtools.msgRestoration.msgFontSizeOrig = mozTextFlowedDiv.style.fontSize;
mozTextFlowedDiv.style.fontFamily = mFamily;
mozTextFlowedDiv.style.fontSize = mSize;
} else {
printingtools.msgRestoration.msgDiv = mozTextHtmlDiv;
printingtools.msgRestoration.msgFontFamilyOrig = null;
printingtools.msgRestoration.msgFontSizeOrig = null;
}
else {
if (table1) {
// table1.style.width = "75%";
table1.style.fontFamily = mFamily;
table1.style.fontSize = mSize;
}
if (table2) {
table2.style.fontFamily = mFamily;
table2.style.fontSize = mSize;
}
if (!noExtHeaders && hpref == 2 && table3) {
table3.style.fontFamily = mFamily;
table3.style.fontSize = mSize;
}

rule = 'div.moz-text-html * {font-size: +' + mSize + 'px !important; font-family: ' + mFamily + ' !important;}';

//rule = '* {font-size: +' + mSize + 'px !important; font-family: ' + mFamily + ' !important;}';
printingtools.msgRestoration.ruleIndex = printingtools.doc.styleSheets[0].insertRule(rule, printingtools.doc.styleSheets[0].cssRules.length);

}

if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.headers.style")) {
var hFamily = printingtools.getComplexPref("extensions.printingtoolsng.headers.font_family");
if (table1) {
// table1.style.width = "75%";
table1.style.fontFamily = hFamily;
table1.style.fontSize = hSize;
}
if (table2) {
table2.style.fontFamily = hFamily;
table2.style.fontSize = hSize;
}
if (!noExtHeaders && hpref == 2 && table3) {
table3.style.fontFamily = hFamily;
table3.style.fontSize = hSize;
}
}


if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.cite.style")) {
var cSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.cite.size");
var cColor = printingtools.prefs.getCharPref("extensions.printingtoolsng.cite.color");
Expand Down Expand Up @@ -1268,11 +1333,11 @@ var printingtools = {
tw.setAttribute("cellspacing", "0");
// md.document.body.appendChild(tw);

if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.messages.style")) {
var mSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.messages.size");
var mFamily = printingtools.getComplexPref("extensions.printingtoolsng.messages.font_family");
tw.style.fontFamily = mFamily;
tw.style.fontSize = mSize;
if (printingtools.prefs.getBoolPref("extensions.printingtoolsng.headers.style")) {
var hSize = printingtools.prefs.getIntPref("extensions.printingtoolsng.headers.size");
var hFamily = printingtools.getComplexPref("extensions.printingtoolsng.headers.font_family");
tw.style.fontFamily = hFamily;
tw.style.fontSize = hSize;
}

if (!table3) {
Expand All @@ -1281,7 +1346,7 @@ var printingtools = {

} else {
printingtools.insertAfter(tw, table3);
var maxHdrWidth = tw.getBoundingClientRect().width;
var maxHdrWidth = tw.getBoundingClientRect().width + 12;
//console.log(maxHdrWidth)
}
//console.log(printingtools.doc.documentElement.outerHTML);
Expand All @@ -1293,18 +1358,22 @@ var printingtools = {
} else {
let locale = Services.locale.appLocaleAsBCP47.split("-")[0];
let alwaysCcBcc = printingtools.prefs.getBoolPref("extensions.printingtoolsng.headers.useCcBcc_always");
var fs = window.getComputedStyle(table1).getPropertyValue('font-size');
var fsn = Number(fs.split("px")[0])

switch (locale) {
case "de":
if (!alwaysCcBcc) {
maxHdrWidth = 130;
maxHdrWidth = 130 + 6*(fsn - 14);

} else {
maxHdrWidth = 110;
maxHdrWidth = 110 + 6*(fsn - 14);
}
break;

default:
maxHdrWidth = 110;

maxHdrWidth = 110 + 6*(fsn - 14);
break;
}

Expand Down Expand Up @@ -1576,12 +1645,12 @@ var printingtools = {
var imgs = printingtools.doc.getElementsByTagName("img");
for (i = 0; i < imgs.length; i++) {
if (imgs[i].getAttribute("class") != "attIcon") {

let display = imgs[i].getAttribute("_display");

if (display !== undefined && display !== null) {
if (display == "") {

imgs[i].style.display = null;
} else {
imgs[i].style.display = display;
Expand Down Expand Up @@ -1959,7 +2028,7 @@ var printingtools = {

let fileNames = [...printingtools.previewDoc.querySelectorAll(".moz-mime-attachment-table .moz-mime-attachment-file")].map(elm => elm.innerHTML)
let fileSizes = [...printingtools.previewDoc.querySelectorAll(".moz-mime-attachment-table .moz-mime-attachment-size")].map(elm => elm.innerHTML)

printingtoolsng.attList = fileNames.map((fn, i) => {
return { name: fn, size: fileSizes[i] };
});
Expand Down Expand Up @@ -2000,7 +2069,13 @@ var printingtools = {
attRowTR.appendChild(attTD);

attTD = printingtools.doc.createElement("TD");
attTD.textContent = printingtools.formatBytes(attEntry.size);
// fix for #125 eml files have string sizes for attachments
if(isNaN(attEntry.size)) {
attTD.textContent = attEntry.size;
} else {
attTD.textContent = printingtools.formatBytes(attEntry.size);
}

attRowTR.appendChild(attTD);

attTable.appendChild(attRowTR);
Expand Down
Loading

0 comments on commit 6776320

Please sign in to comment.