chrome/0000755000000000000000000000000014144024174011032 5ustar rootrootchrome/content/0000755000000000000000000000000014256701226012510 5ustar rootrootchrome/content/xnote-window.js0000644000000000000000000003207514256701226015517 0ustar rootroot// encoding='UTF-8' /* # File : xnote-window.xul # Authors : Hugo Smadja, Lorenz Froihofer, Klaus Buecher # Description : Functions associated with the XNote window (xnote-window.xul). */ var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyScriptGetter( this, "PrintUtils", "chrome://messenger/content/printUtils.js" ); var { xnote } = ChromeUtils.import("resource://xnote/modules/xnote.jsm"); // This object lives inside the xnote window. This is the old // xnote.ns.Window object, which was falsly placed in the global xnode module. window.xnoteWindowObj = function () { // Variables for window movement var xBeforeMove, yBeforeMove; // Variables for window resizing. var widthBeforeMove, heightBeforeMove; var oldOpenerX, oldOpenerY; /** Displayed note. */ var note; // result var pub = {}; /** * APPELANT * type : évènement load de l'élément XUL * id : xnote-window * FONCTION * Exécutée au chargement du post-it avant qu'elle ne soit affichée à l'écran. * C'est ici, que l'on peut modifier le style de la fenêtre dynamiquement */ pub.onLoad = function (e) { //~ dump('\n->onLoad'); // premet l'accès au préférences /*try { self.document.getElementById('xnote-note').style.setProperty('-moz-opacity', pref.getIntPref('xnote.transparence')/10, ''); } catch(e) {}*/ Services.scriptloader.loadSubScript("chrome://xnote/content/scripts/notifyTools.js", pub, "UTF-8"); // Capture the Window focus lost event to update the XNote tag. addEventListener('blur', window.xnoteWindowObj.updateTag, true); addEventListener('unload', window.xnoteWindowObj.onUnload, false); //Necessary for correct shutdown as we are otherwise unable to correctly //save a modified note opener.addEventListener("unload", window.xnoteWindowObj.onOpenerUnload, false); //Unfortunately, there seems to be no better way to react on window //movement. setInterval(window.xnoteWindowObj.checkOpenerMoved, 500); note = self.arguments[0]; let texte = self.document.getElementById('xnote-texte'); texte.value = note.text; let fwd = self.document.getElementById('xnote-button-forward'); fwd.href = "mailto:?body=" + encodeURI(note.text); //PrintUtils.showPageSetup(); //self.print(); //set date in the titlebar let modificationdate = self.document.getElementById("xnote-mdate"); modificationdate.value = note.modificationDate; self.setTimeout(window.xnoteWindowObj.resizeWindow); if (window.arguments[1]) texte.focus(); else self.setTimeout(window.opener.focus); //~ dump('\n<-onLoad'); } function resizeWindow(width, height) { width = width < 58 ? 58 : width; //Consider background image for height because of textarea. height = height < 130 ? 130 : height; //~ dump('\nwidth='+width+', height='+height); window.resizeTo(width, height); document.getElementById("xnote-texte").style.height = (height - 40) + "px"; } pub.resizeWindow = function () { resizeWindow(note.width, note.height); } /** * CALLING XUL * Type: blur event of the XUL element * Id: XNote-window * FUNCTION * Function called when the window loses focus. It assigns a * tag to the selected mail if the note contains text. */ pub.updateTag = function () { //~ dump('\n->updateTag'); opener.xnoteOverlayObj.updateTag(document.getElementById('xnote-texte').value); //~ dump('\n<-updateTag'); } /** * CALLER XUL * Type: unload event in XUL element * Id: XNote-window * FUNCTION * Saves the note: location, size and content of the note, * A blank note will be deleted. */ pub.saveNote = function () { let dateformat = xnote.ns.Commons.xnotePrefs.dateformat; let date = xnote.ns.DateFormat; let dateStr = date.format(dateformat); //~ dump('\n->saveNote'); if (note.modified) { let oldText = note.text; note.text = document.getElementById('xnote-texte').value; if (note.text != '') { note.x = window.screenX - opener.screenX; note.y = window.screenY - opener.screenY; note.width = window.innerWidth; note.height = window.innerHeight; if (oldText != note.text) { note.modificationDate = dateStr; } note.saveNote(); } else { note.deleteNote(); } } // ~ dump('\n<-saveNote'); } /** * CALLER XUL * Type: event input from XUL element * Id: text * FUNCTION * Notification that the note was modified (edited, moved, ...). */ pub.noteModified = function () { //~ dump('\n->modifierNote'); note.modified = true; //~ dump('\n<-modifierNote'); } pub.bookmarkNote = function () { pub.notifyTools.notifyBackground({ command: "setBookmark" }); } pub.printNote = function () { //window.document.documentElement.textContent= note.text; // console.log("printwindow", window.document, "docEl", window.document.documentElement , "text", window.document.documentElement.textContent, window); // console.log("note", xnote.text); //window.print(); // self.print(); // window.document.print(); //window.top = window; //window.currentWindowGlobal = window; //PrintUtils.printWindow(window, {}); let mainWindow = Services.wm.getMostRecentWindow("mail:3pane"); /* */ let messageBrowser = mainWindow.document.getElementById("messagepane");//messagepane let msgBody = messageBrowser.contentDocument.documentElement.getElementsByTagName("body"); // console.log("body", msgBody[0], messageBrowser.contentDocument.children[0].children[2]); let messagePaneBrowser = mainWindow.document.getElementById("xnote-print"); messagePaneBrowser.setAttribute('style', 'white-space: pre-line;'); let modificationdate = self.document.getElementById("xnote-mdate"); let docEl = messagePaneBrowser.contentDocument.documentElement; let doc = messagePaneBrowser.contentDocument; var p = doc.createElement("p"); p.appendChild(doc.createTextNode("XNote " + modificationdate.value)); docEl.appendChild(p); docEl.appendChild(doc.createElement("br")); p = doc.createElement("p"); p.appendChild(doc.createTextNode(note.text)); docEl.appendChild(p); docEl.appendChild(doc.createElement("br")); let hr = doc.createElement("br"); docEl.appendChild(hr); NodeList.prototype.forEach = Array.prototype.forEach; var children = msgBody[0].childNodes; children.forEach(function (item) { var cln = item.cloneNode(true); docEl.appendChild(cln); }); //messagePaneBrowser.contentDocument.documentElement.textContent = //"XNote " +modificationdate.value +"\r\n" + note.text;//"eee"; mainWindow.PrintUtils.startPrintWindow(messagePaneBrowser.browsingContext, {}); // messagePaneBrowser.contentDocument.documentElement.textContent = ""; /*debugger; let messagePaneBrowser =document.getElementById("bb"); // messagePaneBrowser.top = window; //messagePaneBrowser.currentWindowGlobal = window; //messagePaneBrowser.top = window; //messagePaneBrowser.currentWindowGlobal = window; console.log("msbro", messagePaneBrowser); messagePaneBrowser.contentDocument.documentElement.textContent = "eee"; //messagePaneBrowser.contentDocument.textContent = "jjj"; console.log("brodoc", messagePaneBrowser.contentDocument); mainWindow.PrintUtils.startPrintWindow(messagePaneBrowser.browsingContext, {}); var printContents = document.getElementById("xnote-texte").cloneNode(true); w = window.open(); w.document.body.appendChild(printContents); w.print(); w.close(); let childWindow =window.open('', '', 'height=600,width=800');;// window.open('','childWindow','location=yes, menubar=yes, toolbar=yes'); childWindow.document.open(); childWindow.document.write(''); childWindow.document.write(xnote.text); //childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'
')); childWindow.document.write(''); childWindow.print(); childWindow.document.close(); childWindow.close(); /* */ } pub.forwardNote = function () { self.print(); } pub.copyNoteToClipboard = function () { let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper); clipboard.copyString(note.text); /* console.log("wnd", window, "doc", window.document); var res; window.document.designMode = "on"; // let docb = window.document.getElementById("body"); // console.log("body", docb); res = window.document.execCommand("selectAll"); console.log("selectAll", res); res = window.document.execCommand("copy"); console.log("copy", res); */ } /** * CALLER XUL * Type: event input from XUL element * Id: text * FUNCTION * Change the set the note to be modified the note to be deleted when * the save method is called. */ pub.deleteNote = function () { //~ dump('\n->supprimerNote'); document.getElementById('xnote-texte').value = ''; pub.noteModified(); pub.saveNote(); //~ dump('\n<-supprimerNote'); } /** * APPELANT XUL * type : évènement mousedown de l'élément XUL * id : redim * FONCTION * Quand le bouton de la souris est enfoncé, sauve la taille et * lance la capture des évènements de déplacement et de relâchement */ pub.startRedimensionnement = function (e) { if (e.button == 0) { xBeforeMove = e.screenX; widthBeforeMove = window.innerWidth; yBeforeMove = e.screenY; heightBeforeMove = window.innerHeight; //~ dump('\n xBeforeMove='+xBeforeMove+' ; yBeforeMove='+yBeforeMove); //~ dump('\n heightBeforeMove='+heightBeforeMove+' ; heightBeforeMove='+heightBeforeMove); document.addEventListener('mousemove', window.xnoteWindowObj.redimenssionnement, true); document.addEventListener('mouseup', window.xnoteWindowObj.stopRedimenssionnement, true); } } /** * lors du déplacement de la souris, redimensionne la fenêtre grâce à la taille * enregistrée lors du clic. */ pub.redimenssionnement = function (e) { //~ dump('\n w.document.width='+window.document.width+' ; w.document.height='+window.document.height); //~ dump('\nlargeur='+document.getElementById('xnote-texte').style.width); let newWidth = widthBeforeMove + e.screenX - xBeforeMove; let newHeight = heightBeforeMove + e.screenY - yBeforeMove; //~ dump('\nxAvantDeplacement='+xBeforeMove+', yAvantDeplacement='+yBeforeMove); //~ dump('\ne.screenX='+e.screenX+', e.screenY='+e.screenY); resizeWindow(newWidth, newHeight); pub.noteModified(); } /** * quand le bouton de la souris est relaché, on supprime la capture * du déplacement de la souris. */ pub.stopRedimenssionnement = function (e) { document.removeEventListener('mousemove', window.xnoteWindowObj.redimenssionnement, true); document.removeEventListener('mouseup', window.xnoteWindowObj.stopRedimenssionnement, true); let texte = document.getElementById('xnote-texte'); texte.focus(); } pub.checkOpenerMoved = function () { if (oldOpenerX != opener.screenX || oldOpenerY != opener.screenY) { window.moveTo(opener.screenX + note.x, opener.screenY + note.y) oldOpenerX = opener.screenX; oldOpenerY = opener.screenY; } } pub.onUnload = function (e) { // ~dump("\n->onUnload"); //console.log("note unLoad"); pub.saveNote(); removeEventListener('blur', window.xnoteWindowObj.updateTag); removeEventListener('load', window.xnoteWindowObj.onLoad); removeEventListener('unload', window.xnoteWindowObj.onUnload); opener.removeEventListener("unload", window.xnoteWindowObj.onOpenerUnload); } pub.onOpenerUnload = function (e) { pub.saveNote(); } return pub; }(); addEventListener('load', window.xnoteWindowObj.onLoad, false); chrome/content/scripts/0000755000000000000000000000000014256701226014177 5ustar rootrootchrome/content/scripts/README.md0000644000000000000000000000025014056255306015454 0ustar rootrootThis script is intended to be used together with the [NotifyTools API](https://github.com/thundernest/addon-developer-support/tree/master/auxiliary-apis/NotifyTools). chrome/content/scripts/notifyTools.js0000644000000000000000000001162514130141102017051 0ustar rootroot// Set this to the ID of your add-on, or call notifyTools.setAddOnId(). var ADDON_ID = "xnote@froihofer.net"; /* * This file is provided by the addon-developer-support repository at * https://github.com/thundernest/addon-developer-support * * For usage descriptions, please check: * https://github.com/thundernest/addon-developer-support/tree/master/scripts/notifyTools * * Version: 1.5 * - deprecate enable(), disable() and registerListener() * - add setAddOnId() * * Version: 1.4 * - auto enable/disable * * Version: 1.3 * - registered listeners for notifyExperiment can return a value * - remove WindowListener from name of observer * * Author: John Bieling (john@thunderbird.net) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); var notifyTools = { registeredCallbacks: {}, registeredCallbacksNextId: 1, addOnId: ADDON_ID, setAddOnId: function (addOnId) { this.addOnId = addOnId; }, onNotifyExperimentObserver: { observe: async function (aSubject, aTopic, aData) { if (notifyTools.addOnId == "") { throw new Error("notifyTools: ADDON_ID is empty!"); } if (aData != notifyTools.addOnId) { return; } let payload = aSubject.wrappedJSObject; // Make sure payload has a resolve function, which we use to resolve the // observer notification. if (payload.resolve) { let observerTrackerPromises = []; // Push listener into promise array, so they can run in parallel for (let registeredCallback of Object.values( notifyTools.registeredCallbacks )) { observerTrackerPromises.push(registeredCallback(payload.data)); } // We still have to await all of them but wait time is just the time needed // for the slowest one. let results = []; for (let observerTrackerPromise of observerTrackerPromises) { let rv = await observerTrackerPromise; if (rv != null) results.push(rv); } if (results.length == 0) { payload.resolve(); } else { if (results.length > 1) { console.warn( "Received multiple results from onNotifyExperiment listeners. Using the first one, which can lead to inconsistent behavior.", results ); } payload.resolve(results[0]); } } else { // Older version of NotifyTools, which is not sending a resolve function, deprecated. console.log("Please update the notifyTools API to at least v1.5"); for (let registeredCallback of Object.values( notifyTools.registeredCallbacks )) { registeredCallback(payload.data); } } }, }, addListener: function (listener) { if (Object.values(this.registeredCallbacks).length == 0) { Services.obs.addObserver( this.onNotifyExperimentObserver, "NotifyExperimentObserver", false ); } let id = this.registeredCallbacksNextId++; this.registeredCallbacks[id] = listener; return id; }, removeListener: function (id) { delete this.registeredCallbacks[id]; if (Object.values(this.registeredCallbacks).length == 0) { Services.obs.removeObserver( this.onNotifyExperimentObserver, "NotifyExperimentObserver" ); } }, removeAllListeners: function () { if (Object.values(this.registeredCallbacks).length != 0) { Services.obs.removeObserver( this.onNotifyExperimentObserver, "NotifyExperimentObserver" ); } this.registeredCallbacks = {}; }, notifyBackground: function (data) { if (this.addOnId == "") { throw new Error("notifyTools: ADDON_ID is empty!"); } return new Promise((resolve) => { Services.obs.notifyObservers( { data, resolve }, "NotifyBackgroundObserver", this.addOnId ); }); }, // Deprecated. enable: function () { console.log("Manually calling notifyTools.enable() is no longer needed."); }, disable: function () { console.log("notifyTools.disable() has been deprecated, use notifyTools.removeAllListeners() instead."); this.removeAllListeners(); }, registerListener: function (listener) { console.log("notifyTools.registerListener() has been deprecated, use notifyTools.addListener() instead."); this.addListener(listener); }, }; if (typeof window != "undefined" && window) { window.addEventListener( "unload", function (event) { notifyTools.removeAllListeners(); }, false ); }chrome/content/scripts/xn-xnote-overlay.js0000644000000000000000000000707014256701226020000 0ustar rootrootvar { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); // Load xnoteOverlayObj into the window. Services.scriptloader.loadSubScript("chrome://xnote/content/xnote-overlay.js", window, "UTF-8"); Services.scriptloader.loadSubScript("chrome://xnote/content/xnote-columnnote.js", window, "UTF-8"); function onLoad(activatedWhileWindowOpen) { //console.log (Services.appinfo.version); let layout = WL.injectCSS("resource://xnote/skin/xnote-overlay.css"); WL.injectElements(`