[Pkg-mozext-commits] [itsalltext] 02/459: in progress
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:00 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository itsalltext.
commit b99068434df5ef0aa1eecd408d5d6c19d2633e96
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Sat Dec 9 16:51:45 2006 -0500
in progress
---
chrome.manifest | 3 +
chrome/content/about.xul | 15 ++++
chrome/content/icon.png | Bin 0 -> 209 bytes
chrome/content/itsalltext.js | 190 ++++++++++++++++++++++++++++++++++++++++++
chrome/content/itsalltext.xul | 5 ++
chrome/content/options.js | 0
chrome/content/options.xul | 18 ++++
install.rdf | 4 +-
8 files changed, 234 insertions(+), 1 deletion(-)
diff --git a/chrome.manifest b/chrome.manifest
new file mode 100644
index 0000000..d5b81d9
--- /dev/null
+++ b/chrome.manifest
@@ -0,0 +1,3 @@
+content itsalltext chrome/content/
+
+overlay chrome://browser/content/browser.xul chrome://itsalltext/content/itsalltext.xul
diff --git a/chrome/content/about.xul b/chrome/content/about.xul
new file mode 100644
index 0000000..ad7db68
--- /dev/null
+++ b/chrome/content/about.xul
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<dialog
+ id="ItsAllTextAbout"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ title="About for It's All Text"
+ buttons="accept,cancel"
+ >
+ <vbox>
+ <hbox>
+ <caption>Nothing Here Yet</caption>
+ </hbox>
+ </vbox>
+</dialog>
diff --git a/chrome/content/icon.png b/chrome/content/icon.png
new file mode 100644
index 0000000..fa3ebe8
Binary files /dev/null and b/chrome/content/icon.png differ
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
new file mode 100644
index 0000000..0f00a0a
--- /dev/null
+++ b/chrome/content/itsalltext.js
@@ -0,0 +1,190 @@
+/*
+ * Places I learned how to do some of this stuff and used as references:
+ * - Mozex
+ * - Stylish
+ */
+
+ /**
+ * Creates a mostly unique hash of a string
+ * Most of this code is from:
+ * http://developer.mozilla.org/en/docs/nsICryptoHash
+ * @param {String} some_string The string to hash.
+ * @returns {String} a hashed string.
+ */
+function hashString(some_string) {
+ var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+ converter.charset = "UTF-8";
+
+ /* result is the result of the hashing. It's not yet a string,
+ * that'll be in retval.
+ * result.value will contain the array length
+ */
+ var result = {};
+
+ /* data is an array of bytes */
+ var data = converter.convertToByteArray(some_string, result);
+ var ch = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
+
+ ch.init(ch.MD5);
+ ch.update(data, data.length);
+ var hash = ch.finish(true);
+
+ // return the two-digit hexadecimal code for a byte
+ toHexString = function(charCode) {
+ return ("0" + charCode.toString(36)).slice(-2);
+ };
+
+ // convert the binary hash data to a hex string.
+ var retval = [];
+ for(i in hash) {
+ retval[i] = toHexString(hash.charCodeAt(i));
+ }
+
+ return(retval.join(""));
+}
+
+function ItsAllTextOverlay() {
+ /* This data is all private, which prevents security problems and it
+ * prevents clutter and collection.
+ */
+ var that = this;
+ var cache = {};
+ var cron = {};
+
+ var makeLocalFile = function(path) {
+ var obj = Components.classes["@mozilla.org/file/local;1"].
+ createInstance(Components.interfaces.nsILocalFile);
+ obj.initWithPath(path);
+ return obj;
+ };
+
+ function CacheObj(node) {
+ var self = this;
+ self.timestamp = 0;
+ self.size = 0;
+ self.node = node;
+
+ self.uid = hashString([ node.ownerDocument.URL,
+ Math.random(),
+ node.getAttribute("name") ].join(':'));
+ node.setAttribute('ItsAllText_UID', self.uid);
+ cache[self.uid] = self;
+ // TODO: This would be better if it was smarter
+ self.filename = self.uid + '.txt';
+
+ self.toString = function() {
+ return [ "CacheObj",
+ " uid=",self.uid,
+ " timestamp=",self.timestamp,
+ " size=",self.size
+ ].join('');
+ };
+ }
+
+ /**
+ * This is a handy debug message. I'll remove it or disable it when
+ * I release this.
+ * @param {String} aMessage The message to log.
+ */
+ that.log = function() {
+ var args = Array.prototype.slice.apply(arguments,[0]);
+ var consoleService = Components.
+ classes["@mozilla.org/consoleservice;1"].
+ getService(Components.interfaces.nsIConsoleService);
+ consoleService.logStringMessage("ItsAllTextOverlay: " + args.join(' '));
+ };
+
+ // TODO: tempdir should be a preference.
+ // TODO: tempdir should be a method that makes sure it exists.
+
+ /**
+ * Returns a cache object
+ * Note: These UIDs are only unique for Its All Text.
+ * @param {Object} node A dom object node.
+ * @returns {String} the UID.
+ */
+ that.getCacheObj = function(node) {
+ var uid = node.getAttribute("ItsAllText_UID");
+ if (uid) {
+ return cache[uid];
+ } else {
+ return new CacheObj(node);
+ }
+ };
+
+ /**
+ * Refresh Textarea.
+ * @param {Object} textarea A specific textarea dom object to update.
+ */
+ that.refreshTextarea = function(textarea) {
+ var cobj = that.getCacheObj(textarea);
+ that.log('refreshTextarea(): '+cobj);
+ };
+
+ /**
+ * Refresh Document.
+ * @param {Object} doc The document to refresh.
+ */
+ that.refreshDocument = function(doc) {
+ that.log('refreshDocument()',doc.URL);
+ var nodes = doc.getElementsByTagName('textarea');
+ for(var i=0; i < nodes.length; i++) {
+ that.refreshTextarea(nodes[i]);
+ }
+ };
+
+ /**
+ * Callback whenever the DOM content in a window or tab is loaded.
+ * @param {Object} event An event passed in.
+ */
+ that.onDOMContentLoad = function(event) {
+ if (event.originalTarget.nodeName != "#document") { return; }
+ var doc = event.originalTarget;
+
+ that.log('onDOMContentLoad: start');
+
+ // Set up the autorefresh
+ cron[doc] = null;
+ cronjob = function() {
+ var lasttime = new Date().valueOf();
+
+ var fun = function () {
+ var last = cron[doc];
+ if(!last || last == lasttime) {
+ that.log('last:'+last,'lasttime:'+lasttime,doc);
+ that.refreshDocument(doc);
+ lasttime = new Date().valueOf();
+ cron[doc] = lasttime;
+ setTimeout(cronjob, 6000);
+ } else {
+ that.log('skipping', doc);
+ }
+ };
+ return fun;
+ }();
+ cronjob();
+
+ /*
+ TODO: Put edit button inside the lower right side of the text area.
+ */
+ that.log('onDOMContentLoad: done');
+ return;
+ };
+
+ /**
+ * Initialize the module. Should be called once, when a window is loaded.
+ * @private
+ */
+ var init = function() {
+ that.log('init');
+ var appcontent = document.getElementById("appcontent"); // The Browser
+ if (appcontent) {
+ appcontent.addEventListener("DOMContentLoaded", that.onDOMContentLoad,
+ true);
+ }
+ };
+
+ window.addEventListener("load", init, true);
+ that.log('loaded overlay');
+}
+var itsAllTextOverlay = new ItsAllTextOverlay();
diff --git a/chrome/content/itsalltext.xul b/chrome/content/itsalltext.xul
new file mode 100644
index 0000000..900691e
--- /dev/null
+++ b/chrome/content/itsalltext.xul
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/x-javascript" src="itsalltext.js"/>
+</overlay>
diff --git a/chrome/content/options.js b/chrome/content/options.js
new file mode 100644
index 0000000..e69de29
diff --git a/chrome/content/options.xul b/chrome/content/options.xul
new file mode 100644
index 0000000..7ae12ae
--- /dev/null
+++ b/chrome/content/options.xul
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<dialog
+ id="ItsAllTextOptions"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ ondialogaccept="itsalltextOptionsSave();"
+ onload="itsalltextOptionsLoad();"
+ title="Options for It's All Text"
+ buttons="accept,cancel"
+ >
+ <script type="application/x-javascript" src="options.js"/>
+ <vbox>
+ <hbox>
+ <caption>Nothing Here Yet</caption>
+ </hbox>
+ </vbox>
+</dialog>
diff --git a/install.rdf b/install.rdf
index e255f9e..c05a0dc 100644
--- a/install.rdf
+++ b/install.rdf
@@ -10,7 +10,9 @@
<!-- Front End Metadata -->
<em:name>It's All Text!</em:name>
- <em:description>Edit Textareas, and view source!</em:description>
+ <em:description>
+ Edit text and view source using your favorite editor!
+ </em:description>
<em:homepageURL>http://addons.mozilla.org/firefox/1234</em:homepageURL>
<em:optionsURL>chrome://itsalltext/content/options.xul</em:optionsURL>
<em:iconURL>chrome://itsalltext/content/icon.png</em:iconURL>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git
More information about the Pkg-mozext-commits
mailing list