Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!com) var com = {};
- if (!com.RealityRipple) com.RealityRipple = {};
- com.RealityRipple.GaiaFormat = function()
- {
- var pub = {};
- var priv = {};
- priv.Cc = Components.classes;
- priv.Ci = Components.interfaces;
- priv.CccI = function(cName, ifaceName)
- {
- return priv.Cc[cName].createInstance(priv.Ci[ifaceName]);
- }
- priv.CcgS = function(cName, ifaceName)
- {
- if (Cc[cName])
- return priv.Cc[cName].getService(priv.Ci[ifaceName]);
- else
- dumpError("CcgS fails for cName:" + cName);
- }
- priv.Prefs = priv.CcgS("@mozilla.org/preferences-service;1","nsIPrefService").getBranch("gaiaformat.");
- priv.gBundle = priv.CcgS("@mozilla.org/intl/stringbundle;1","priv.Ci.nsIStringBundleService");
- priv.locale = priv.gBundle.createBundle("chrome://gaiaformat/locale/gaiaformat.properties");
- priv.lclDisForm = priv.locale.GetStringFromName("disableformat.label");
- priv.trim = function(s)
- {
- s = s.replace(/(^\s*)|(\s*$)/gi, "");
- s = s.replace(/[ ]{2,}/gi, " ");
- s = s.replace(/\n /, "");
- return s;
- }
- priv.getElementsByAttribute = function(findme, attr)
- {
- var alltags = window._content.document.getElementsByTagName("*");
- var foundtags = new Array();
- for (var i = 0; i < alltags.length; i++)
- {
- if (attr == 'class')
- {
- if (alltags[i].className.indexOf(findme) >= 0)
- foundtags.push(alltags[i]);
- }
- else
- if (alltags[i].getAttribute(attr) == findme)
- foundtags.push(alltags[i]);
- }
- return foundtags;
- }
- var httpRequestObserver =
- {
- observe: function(subject, topic, data)
- {
- if (topic == "http-on-modify-request")
- {
- var httpChannel = subject.QueryInterface(priv.Ci.nsIHttpChannel);
- if (httpChannel.requestMethod == "POST")
- {
- alert('on-modify POST: ' + httpChannel.URI.asciiSpec);
- this.onModifyRequest(httpChannel);
- this.unregister();
- }
- }
- },
- get observerService()
- {
- return priv.CcgS("@mozilla.org/observer-service;1","nsIObserverService");
- },
- register: function()
- {
- this.observerService.addObserver(this, "http-on-modify-request", false);
- },
- unregister: function()
- {
- this.observerService.removeObserver(this, "http-on-modify-request");
- },
- onModifyRequest: function(oHttp)
- {
- var uri = oHttp.URI.asciiSpec;
- alert('URI: ' + uri);
- /* this.forceCaching(oHttp);
- var loadFlags = this.getStringVersionOfLoadFlags(oHttp.loadFlags);
- var loadFromCache = this.isLoadFromCache(oHttp.loadFlags);
- var cancelled = false; */
- var visitor = new HeaderInfoVisitor(oHttp);
- var requestHeaders = visitor.visitRequest();
- alert('Headers: ' + requestHeaders);
- var postData = visitor.getPostData();
- alert('Post Data: ' + postData);
- var postBodyHeaders = visitor.getPostBodyHeaders();
- alert('Full Info: ' + uri + ',' + requestHeaders + ',' + postBodyHeaders + ',' + postData);
- }
- /* requestResponse.setRequestData(uri, new Date(), oHttp.requestMethod, requestHeaders, postBodyHeaders, postData, loadFlags);
- var requestResponse = new TamperRequestResponse();
- requestResponse.setRequestData(uri, new Date(), oHttp.requestMethod, requestHeaders, postBodyHeaders, postData, loadFlags);
- if (cancelled)
- {
- requestResponse.cancel();
- }
- else if (loadFromCache)
- {
- requestResponse.setLoadFromCache();
- }
- this.addRow(requestResponse); */
- };
- function HeaderInfoVisitor(oHttp)
- {
- this.oHttp = oHttp;
- this.headers = new Array();
- }
- HeaderInfoVisitor.prototype =
- {
- extractPostData : function(visitor, oHttp)
- {
- function postData(stream)
- {
- this.seekablestream = stream;
- this.stream = TamperUtils.createScriptableInputStream(this.seekablestream);
- this.hasheaders = false;
- this.body = 0;
- this.isBinary = true;
- alert(this.seekablestream);
- if (this.seekablestream instanceof Components.interfaces.nsIMIMEInputStream)
- {
- this.seekablestream.QueryInterface(Components.interfaces.nsIMIMEInputStream);
- this.hasheaders = true;
- this.body = -1;
- this.isBinary = false;
- }
- else if (this.seekablestream instanceof Components.interfaces.nsIStringInputStream)
- {
- this.seekablestream.QueryInterface(Components.interfaces.nsIStringInputStream);
- this.hasheaders = true;
- this.body = -1;
- }
- this.rewind = function() { this..seekablestream.seek(0,0); };
- this.tell = function() { return this.seekablestream.tell(); };
- }
- postData.prototype =
- {
- readLine: function()
- {
- var line = "";
- var size = this.stream.available();
- for (var i = 0; i < size; i++)
- {
- var c = this.stream.read(1);
- if (c == '\r')
- {
- }
- else if (c == '\n')
- {
- break;
- }
- else
- {
- line += c;
- }
- }
- return line;
- },
- visitPostHeaders: function(visitor)
- {
- if (this.hasheaders)
- {
- this.rewind();
- var line = this.readLine();
- while(line)
- {
- if (visitor)
- {
- var tmp = line.match(/^([^:]+):\s?(.*)/);
- if (tmp)
- {
- visitor.visitPostHeader(tmp[1], tmp[2]);
- if (!this.isBinary && tmp[1].toLowerCase() == "content-type" && tmp[2].indexOf("multipart") != "-1")
- {
- this.isBinary = true;
- }
- }
- else
- {
- visitor.visitPostHeader(line, "");
- }
- }
- line = this.readLine();
- }
- this.body = this.tell();
- }
- },
- getPostBody: function(visitor)
- {
- if (this.body < 0 || this.seekablestream.tell() != this.body)
- {
- this.visitPostHeaders(visitor);
- }
- var size = this.stream.available();
- if (size == 0 && this.body != 0)
- {
- this.rewind();
- visitor.clearPostHeaders();
- this.hasheaders = false;
- this.isBinary = false;
- size = this.stream.available();
- }
- var postString = "";
- try
- {
- for (var i = 0; i < size; i++)
- {
- var c = this.stream.read(1);
- c ? postString += c : postString+='\0';
- }
- }
- catch (ex)
- {
- return "" + ex;
- }
- finally
- {
- this.rewind();
- }
- while (postString.indexOf("\r\n") == (postString.length - 2))
- {
- postString = postString.substring(0, postString.length - 2);
- }
- return postString;
- }
- };
- try
- {
- oHttp.QueryInterface(Components.interfaces.nsIUploadChannel);
- if (oHttp.uploadStream)
- {
- alert('Upload Stream!');
- oHttp.uploadStream.QueryInterface(priv.Ci.nsISeekableStream);
- alert(oHttp.uploadStream);
- return new postData(oHttp.uploadStream);
- }
- }
- catch (e)
- {
- return "crap";
- }
- return null;
- },
- visitHeader : function(name, value)
- {
- this.headers[name] = value;
- },
- visitPostHeader : function(name, value)
- {
- if (!this.postBodyHeaders)
- {
- this.postBodyHeaders = {};
- }
- this.postBodyHeaders[name] = value;
- },
- clearPostHeaders : function()
- {
- if (this.postBodyHeaders)
- {
- delete this.postBodyHeaders;
- }
- },
- visitRequest: function()
- {
- this.headers = {};
- this.oHttp.visitRequestHeaders(this);
- var postData = this.extractPostData(this, this.oHttp);
- if (postData)
- {
- var postBody = postData.getPostBody(this);
- if (postBody !== null)
- {
- this.postBody = {body : postBody, binary : postData.isBinary};
- }
- }
- return this.headers;
- },
- getPostData : function()
- {
- return this.postBody ? this.postBody : null;
- },
- getPostBodyHeaders : function()
- {
- return this.postBodyHeaders ? this.postBodyHeaders : null;
- },
- visitResponse: function()
- {
- this.headers = new Array();
- this.oHttp.visitResponseHeaders(this);
- return this.headers;
- }
- };
- priv.pagegrabber = function(doc)
- {
- if(priv.isGaia() && priv.isMsg() && !doc.getElementById("fmt_detector"))
- {
- var findurl = window._content.location.href;
- var textbox;
- if (priv.isMsg())
- {
- var fmtForum = priv.Prefs.getBoolPref("fmtForum");
- var fmtGuild = priv.Prefs.getBoolPref("fmtGuild");
- var fmtPM = priv.Prefs.getBoolPref("fmtPM");
- var fmtComm = priv.Prefs.getBoolPref("fmtComm");
- try
- {
- if (
- (!priv.isGuild() && !priv.isCom() && !priv.isPM() && fmtForum) ||
- (priv.isQR() && fmtForum) ||
- (priv.isGuild() && fmtGuild) ||
- (!priv.isCom() && priv.isPM() && fmtPM) ||
- (priv.isCom() && fmtComm)
- )
- {
- var postBox = priv.getBox();
- var postcheck = priv.trim(postBox.value);
- var alreadyformed = false;
- if (postcheck.indexOf('[quote]') > -1 && postcheck.substr(-8) != '[/quote]' || postcheck.indexOf('[/quote]') < 0 && postcheck.length > 0)
- alreadyformed = true;
- if (!doc.getElementById('fmt_skipauto'))
- {
- var submit_find;
- var insertData = "";
- var insertElement;
- var beforeElement;
- if (priv.isPM())
- {
- submit_find = priv.getElementsByAttribute('attach_sig', 'name')[0].parentNode;
- beforeElement = null;
- insertData = "<input name='afrmchk_" + Math.random() + "' type='checkbox' id='fmt_skipauto' /> <label for='fmt_skipauto'>" + priv.lclDisForm + "</label>";
- insertElement = window._content.document.createElement('div');
- insertElement.setAttribute("class", "sig");
- }
- else if(priv.isCom())
- {
- submit_find = priv.getElementsByAttribute('Submit', 'value')[0];
- beforeElement = submit_find;
- insertData = "<br /><input name='afrmchk_" + Math.random() + "' type='checkbox' id='fmt_skipauto' /> <label for='fmt_skipauto'>" + priv.lclDisForm + "</label><br /><br />";
- insertElement = window._content.document.createElement('span');
- }
- else if(priv.isGuild())
- {
- submit_find = priv.getElementsByAttribute('attach_sig', 'name')[0].parentNode.parentNode.parentNode.parentNode;
- beforeElement = null;
- insertData = "<tr><td><input name='afrmchk_" + Math.random() + "' type='checkbox' id='fmt_skipauto' /></td><td><span class='gen'><label for='fmt_skipauto'>" + priv.lclDisForm + "</label></span></td></tr>";
- insertElement = window._content.document.createElement('table');
- insertElement.setAttribute("cellspacing","0");
- insertElement.setAttribute("cellpadding","1");
- insertElement.setAttribute("border","0");
- }
- else if(priv.isQR())
- {
- submit_find = doc.getElementById('qr_submit');
- beforeElement = submit_find;
- insertData = "<input name='afrmchk_" + Math.random() + "' type='checkbox' id='fmt_skipauto' /> <label for='fmt_skipauto'>" + priv.lclDisForm + "</label>";
- insertElement = window._content.document.createElement('span');
- insertElement.setAttribute("style","margin: 20px 15px 0px 15px; width: 220px; height: 20px; font-size: 11px; vertical-align: middle;");
- submit_find.addEventListener("click", com.RealityRipple.GaiaFormat.AutoFormat, true);
- httpRequestObserver.register();
- }
- else
- {
- submit_find = doc.getElementById("post_action");
- beforeElement = null;
- insertData = "<div id='post_formatting' class='gaia-info nofooter'><div class='hd'><div class='rc_top_left'> </div><div class='rc_top_right'> </div><h3>Post Formatting</h3></div><div class='bd'>";
- insertData+= "<input name='afrmchk_" + Math.random() + "' type='checkbox' id='fmt_skipauto' /> <label for='fmt_skipauto'>" + priv.lclDisForm + "</label><br />";
- insertData+= "</div><div class='ft'><div class='rc_bottom_left'> </div><div class='rc_bottom_right'> </div></div></div>";
- insertElement = window._content.document.createElement('div');
- }
- if (submit_find && !doc.getElementById('fmt_skipauto'))
- {
- insertElement.innerHTML = insertData;
- submit_find.parentNode.insertBefore(insertElement, beforeElement);
- if (alreadyformed)
- priv.getElementsByAttribute('fmt_skipauto', 'id')[0].checked = true;
- }
- }
- }
- }
- catch(e){}
- try
- {
- var autoArea = priv.getBox();
- var autoAreaForm = autoArea.form;
- autoAreaForm.addEventListener("submit", com.RealityRipple.GaiaFormat.AutoFormat, true);
- }
- catch(e){}
- }
- }
- }
- pub.pagegrabber_start = function()
- {
- var doc = gBrowser.selectedBrowser.contentDocument;
- priv.pagegrabber(doc);
- }
- pub.standardLoad = function()
- {
- window.addEventListener('DOMContentLoaded', com.RealityRipple.GaiaFormat.pagegrabber_start,false);
- }
- priv.buffer;
- pub.tablselect = function(event)
- {
- priv.buffer = gBrowser.getBrowserAtIndex(gBrowser.mTabContainer.selectedIndex);
- setTimeout(com.RealityRipple.GaiaFormat.bufferLoad, 155);
- }
- pub.bufferLoad = function()
- {
- if (priv.isGaia())
- priv.pagegrabber(priv.buffer.contentDocument);
- }
- pub.reLoad = function()
- {
- gBrowser.mPanelContainer.addEventListener("select", com.RealityRipple.GaiaFormat.tablselect, false);
- }
- priv.isGaia = function()
- {
- try
- {
- var x = window.content.location.href;
- }
- catch(e)
- {
- return false;
- }
- if (x.indexOf('gaiaonline.com') > 0)
- return true;
- else
- return false;
- }
- priv.isMsg = function()
- {
- var x = window._content.location.href;
- if (x.indexOf('compose/entry') > 0) return true;
- if (x.indexOf('compose/topic') > 0) return true;
- if (x.indexOf('posting.ph') > 0) return true;
- if (x.indexOf('mode=post') > 0) return true;
- if (x.indexOf('mode=reply') > 0) return true;
- if (x.indexOf('mode=entry') > 0) return true;
- if (x.indexOf('mode=comment') > 0) return true;
- if (x.indexOf('comment.AddComment') > 0) return true;
- if (x.indexOf('mode=addcomment') > 0) return true;
- if (x.indexOf('/t.') > 0) return true;
- if (x.substr(-11) == 'privmsg.php') return true;
- if (x.substr(-11) == 'journal.php') return true;
- if (x.substr(-18) == 'guilds/posting.php') return true;
- return false;
- }
- priv.isGuild = function()
- {
- var x = window._content.location.href;
- if (x.indexOf('gaiaonline.com/guilds') > 0)
- return true;
- else
- return false;
- }
- priv.isCom = function()
- {
- var x = window._content.location.href;
- if (x.indexOf('comment.AddComment') > 0 || x.indexOf('mode=addcomment') > 0)
- return true;
- else
- return false;
- }
- priv.isPM = function()
- {
- var x = window._content.location.href;
- if (x.indexOf('privmsg.php') > 0)
- return true;
- else
- return false;
- }
- priv.isQR = function()
- {
- var x = window._content.location.href;
- if (x.indexOf('/t.') > 0)
- return true;
- else
- return false;
- }
- priv.getBox = function()
- {
- try
- {
- var post = window._content.document.getElementsByName('message').item(0);
- if(!post)
- var post = window._content.document.getElementsByName("form[comment]").item(0);
- if(!post)
- var post = window._content.document.getElementsByName("comment").item(0);
- if(!post)
- var post = window._content.document.getElementById("comment");
- if(!post)
- var post = window._content.document.getElementById('qr_text');
- return post;
- }
- catch(e){}
- }
- priv.specialFormat = function(sIn)
- {
- var fmtExtras = priv.Prefs.getBoolPref("Extras");
- if (fmtExtras && !priv.isPM())
- {
- var fmtEItems = priv.Prefs.getIntPref("EItems");
- var i = 0;
- for(i = 0; i < fmtEItems; i++)
- {
- var sLeft = priv.Prefs.getCharPref("ELeft["+i+"]");
- var sRight = priv.Prefs.getCharPref("ERight["+i+"]");
- var sBegin = priv.Prefs.getCharPref("EBegin["+i+"]");
- var sEnd = priv.Prefs.getCharPref("EEnd["+i+"]");
- var lLeft = sIn.indexOf(sLeft);
- var lRight = sIn.indexOf(sRight, lLeft + 1);
- var lLook = 0;
- while (lLeft >= 0 && lRight > 0)
- {
- if(sIn.substring(0, lLeft).lastIndexOf('[url=') > sIn.substring(0, lLeft).lastIndexOf(']')){}
- else if(sIn.substring(0, lLeft).lastIndexOf('[img]') > sIn.substring(0, lLeft).lastIndexOf('[/img]')){}
- else if(sIn.substring(0, lLeft).lastIndexOf('[imgleft]') > sIn.substring(0, lLeft).lastIndexOf('[/imgleft]')){}
- else if(sIn.substring(0, lLeft).lastIndexOf('[imgright]') > sIn.substring(0, lLeft).lastIndexOf('[/imgright]')){}
- else if(sIn.substring(0, lLeft).lastIndexOf('[imgmap]') > sIn.substring(0, lLeft).lastIndexOf('[/imgmap]')){}
- else if(sIn.substring(0, lLeft).lastIndexOf('[code]') > sIn.substring(0, lLeft).lastIndexOf('[/code]')){}
- else
- sIn = sIn.substring(0, lLeft) + sBegin + sIn.substring(lLeft, lRight + sRight.length) + sEnd + sIn.substring(lRight + sRight.length);
- lLook = lRight + 1 + sBegin.length + sEnd.length;
- lLeft = sIn.indexOf(sLeft, lLook);
- lRight = sIn.indexOf(sRight, lLeft + 1);
- }
- }
- }
- return decodeURIComponent(sIn)
- }
- priv.doFormat = function()
- {
- try
- {
- var fmtBegin = priv.Prefs.getCharPref("Begin");
- var fmtEnd = priv.Prefs.getCharPref("End");
- var fmtStyle = priv.Prefs.getIntPref("Style");
- fmtBegin = decodeURIComponent(fmtBegin);
- fmtEnd = decodeURIComponent(fmtEnd);
- var post = priv.getBox();
- var postx = post.value+'';
- if (!priv.isCom() && !priv.isPM() && !priv.isGuild())
- {
- try
- {
- window._content.document.getElementsByName("basic_type")[0].selectedIndex = fmtStyle;
- }
- catch(e){}
- }
- if (post.selectionStart != post.selectionEnd)
- {
- var topstring = postx.substring(0, post.selectionStart);
- var midstring = encodeURIComponent(postx.substring(post.selectionStart, post.selectionEnd));
- var endstring = postx.substring(post.selectionEnd, post.value.length);
- post.value = topstring + fmtBegin + priv.specialFormat(midstring) + fmtEnd + endstring;
- }
- else
- {
- var postUp = postx.toUpperCase();
- var sTmp;
- var nest = 0;
- var nold = 0;
- var outQuote = ['0'];
- var inQuote = [];
- var i;
- var j;
- for (i=0; i < postx.length; i++)
- {
- if (postUp.substr(i, 6) == '[QUOTE')
- {
- if (nest == 0)
- inQuote.push(i);
- nest++;
- for (j=i+1; j < postx.length; j++)
- {
- if (postx.substr(j,1) == ']')
- {
- i=j;
- break;
- }
- }
- }
- else if (postUp.substr(i, 8) == '[/QUOTE]')
- {
- nest--;
- i += 7;
- if (nest == 0)
- outQuote.push(i+1);
- }
- nold=nest;
- }
- if (nest == 0)
- {
- inQuote.push(postx.length);
- sTmp = '';
- for (i = 0; i < inQuote.length; i++)
- {
- if (inQuote[i] - outQuote[i] > 0)
- sTmp += fmtBegin + priv.specialFormat(encodeURIComponent(postx.substr(outQuote[i], inQuote[i]-outQuote[i]))) + fmtEnd;
- if (i + 1 < outQuote.length)
- sTmp += postx.substr(inQuote[i], outQuote[i+1] - inQuote[i]);
- }
- post.value = sTmp;
- }
- }
- }
- catch(e){}
- }
- pub.AutoFormat = function()
- {
- try
- {
- var fmtForum = priv.Prefs.getBoolPref("fmtForum");
- var fmtGuild = priv.Prefs.getBoolPref("fmtGuild");
- var fmtPM = priv.Prefs.getBoolPref("fmtPM");
- var fmtComm = priv.Prefs.getBoolPref("fmtComm");
- var fmtEnd = decodeURIComponent(priv.Prefs.getCharPref("End"));
- var doc = gBrowser.selectedBrowser.contentDocument;
- var post = priv.getBox().value;
- var bFormed = false;
- if (post.substr(fmtEnd.length * -1) == fmtEnd) bFormed = true;
- try
- {
- if(!bFormed && doc.getElementById("fmt_skipauto").checked != true)
- {
- if (priv.isCom() && fmtComm)
- {
- if (fmtComm == 1) priv.doFormat();
- }
- if (!priv.isCom() && priv.isPM() && fmtPM)
- {
- if (fmtPM == 1) priv.doFormat();
- }
- if (priv.isGuild() && fmtGuild)
- {
- if (fmtGuild == 1) priv.doFormat();
- }
- if (!priv.isCom() && !priv.isPM() && !priv.isGuild() && fmtForum)
- {
- if (fmtForum == 1) priv.doFormat();
- }
- }
- }
- catch(e){}
- return true;
- }
- catch(e){}
- }
- return pub;
- }();
- setTimeout(com.RealityRipple.GaiaFormat.reLoad, 1777);
- window.addEventListener('load', com.RealityRipple.GaiaFormat.standardLoad, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement