How do I edit the "Gmail Multiple Signatures" Greasemonkey script to insert my signature before all quoted messages (or at the current cursor location)?
April 7, 2007 3:13 PM Subscribe
How do I edit the "Gmail Multiple Signatures" Greasemonkey script to insert my signature before all quoted messages (or at the current cursor location)?
I want to combine the features of the Greasemonkey scripts "Gmail Multiple Signatures" (http://userscripts.org/scripts/source/1592) and "Gmail Signature Float" (http://userscripts.org/scripts/source/3067).
I have multiple accounts that I send message from in Gmail and would like to be able to choose between multiple signatures that would be inserted before all quoted messages. A (seemingly) simpler alternative would be modifying Gmail Multple Signatures script to just insert the signature at the current cursor location.
The more explicit/specific explanation, the better -- my Javascript skills are pretty minimal.
I want to combine the features of the Greasemonkey scripts "Gmail Multiple Signatures" (http://userscripts.org/scripts/source/1592) and "Gmail Signature Float" (http://userscripts.org/scripts/source/3067).
I have multiple accounts that I send message from in Gmail and would like to be able to choose between multiple signatures that would be inserted before all quoted messages. A (seemingly) simpler alternative would be modifying Gmail Multple Signatures script to just insert the signature at the current cursor location.
The more explicit/specific explanation, the better -- my Javascript skills are pretty minimal.
Try this GMail users group. I usually get my gmail questions answered there.
posted by JohnnyGunn at 7:45 PM on April 7, 2007
posted by JohnnyGunn at 7:45 PM on April 7, 2007
Response by poster: @Clyde Mnestra: The "Gmail Signature Float" script for the Greasemonkey extension is exactly what you are looking for (http://userscripts.org/scripts/show/3067)
posted by chefscotticus at 8:16 PM on April 7, 2007
posted by chefscotticus at 8:16 PM on April 7, 2007
Thanks to both of you -- that is the right one, and I saw it on the users group, too. Sorry for distracting from the OP.
posted by Clyde Mnestra at 8:30 PM on April 7, 2007
posted by Clyde Mnestra at 8:30 PM on April 7, 2007
Hmm, those scripts could use some clean-up. Oh well, I have code like that hanging around myself.
Anyway, here's the quickest hack that works for me while testing signature placement with two e-mail addresses. It will place the sigs at the beginning of the document. Take your Gmail multiple signature script, forget the signature float script. Look for this line:
" ele.appendChild(docFrag);\n" +
at line 124 or thereabouts (exact line depends on the script mods). This is the compose e-mail based code which stuffs the signature after the document body.
Comment out the line by putting a '//' in front like this:
// " ele.appendChild(docFrag);\n" +
OK, you probably knew how to comment out the line, but best not to assume. Add the following line right after the commented out line:
" ele.insertBefore(docFrag,ele.firstChild);\n" +
This code inserts the sig before the body of the document, placing the sig first in the e-mail rather than appended to the end.
Quick hack, huh? If it breaks on ya, or there are other modes it needs to work and doesn't, or you really need that place sig at cursor location idea, repost with the fail description and I'll see if a less quick hack will do the trick.
posted by mdevore at 2:12 AM on April 8, 2007
Anyway, here's the quickest hack that works for me while testing signature placement with two e-mail addresses. It will place the sigs at the beginning of the document. Take your Gmail multiple signature script, forget the signature float script. Look for this line:
" ele.appendChild(docFrag);\n" +
at line 124 or thereabouts (exact line depends on the script mods). This is the compose e-mail based code which stuffs the signature after the document body.
Comment out the line by putting a '//' in front like this:
// " ele.appendChild(docFrag);\n" +
OK, you probably knew how to comment out the line, but best not to assume. Add the following line right after the commented out line:
" ele.insertBefore(docFrag,ele.firstChild);\n" +
This code inserts the sig before the body of the document, placing the sig first in the e-mail rather than appended to the end.
Quick hack, huh? If it breaks on ya, or there are other modes it needs to work and doesn't, or you really need that place sig at cursor location idea, repost with the fail description and I'll see if a less quick hack will do the trick.
posted by mdevore at 2:12 AM on April 8, 2007
Response by poster: @ mdevore:
Close, but still doesn't address the problem. I want to be able to insert a signature after typing a response and have that signature inserted just above any quoted emails, or at least at the current cursor height/location.
Ideas? Thanks!
posted by chefscotticus at 1:06 PM on April 8, 2007
Close, but still doesn't address the problem. I want to be able to insert a signature after typing a response and have that signature inserted just above any quoted emails, or at least at the current cursor height/location.
Ideas? Thanks!
posted by chefscotticus at 1:06 PM on April 8, 2007
Welp, it's going to be the same script location, the same original line comment and the same basic type of change. The difference is the logical decision on the sig's placement at that point in the code.
You'd take the placing the sig at current cursor as a preferred solution, correct? I will likely have time to check what's needed for that logic change later tonight and post a new fragment, unless someone else here comes in with answer before then and saves me the trouble. Or unless you have a different idea on your preferred solution posted prior to my attention to it.
[Also e-mailed, since your response was also sent me there.]
posted by mdevore at 5:13 PM on April 8, 2007
You'd take the placing the sig at current cursor as a preferred solution, correct? I will likely have time to check what's needed for that logic change later tonight and post a new fragment, unless someone else here comes in with answer before then and saves me the trouble. Or unless you have a different idea on your preferred solution posted prior to my attention to it.
[Also e-mailed, since your response was also sent me there.]
posted by mdevore at 5:13 PM on April 8, 2007
Response by poster: All things equal, I think I'd prefer it to insert the signature just above any quoted messages (ie, at the bottom of the current email being composed), but whichever is simpler to implement is fine. Thanks!!
posted by chefscotticus at 7:02 PM on April 8, 2007
posted by chefscotticus at 7:02 PM on April 8, 2007
Alright, this might do the trick for you. It will place the signature immediately before a quoted section. It successfully tests here when replying to an e-mail, placing a sig after the new e-mail body and before the quoted body. If you intersperse new remarks with quoted remarks it might not work the way you want. If you don't have a quoted e-mail, sig should go at the end as previously.
Drill starts the same, comment out line 124-ish thusly:
// " ele.appendChild(docFrag);\n" +
and add the following code lines immediately after. Hopefully AskMe supports the PRE tag or this might be a little ugly.
posted by mdevore at 12:36 AM on April 9, 2007
Drill starts the same, comment out line 124-ish thusly:
// " ele.appendChild(docFrag);\n" +
and add the following code lines immediately after. Hopefully AskMe supports the PRE tag or this might be a little ugly.
" var xpath=\"//div/span[@class='gmail_quote']\";\n" + " var qNodes=document.evaluate(xpath,ele,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);\n" + " if (qNodes.snapshotLength>0){ele.insertBefore(docFrag,qNodes.snapshotItem(qNodes.snapshotLength-1).parentNode);}\n" + " else{ele.appendChild(docFrag);}\n" +This solution is brittle and prone to break if Google changes anything with Gmail, but that's true of the entire original script. The new code is a shameless hack written solely to fix the situation and would fail any contest for elegance. Questions, comments, further problems, post away.
posted by mdevore at 12:36 AM on April 9, 2007
Response by poster: It works perfectly for "replies", but when forwarding messages, it still puts the signature below all of the quoted messages.....
Once we (read: you) figure this out, are you OK with me posting it to Userscripts.org so anyone can use it (no obligation for maintenance, of course)?
posted by chefscotticus at 7:03 AM on April 9, 2007
Once we (read: you) figure this out, are you OK with me posting it to Userscripts.org so anyone can use it (no obligation for maintenance, of course)?
posted by chefscotticus at 7:03 AM on April 9, 2007
Best answer: Yoikes! The framework for this thing keeps getting more rickety. Well, in for a penny, in for a pound. PRE post of modifications with unchanged bracketing context lines follows:
Further problems, let me know. Hey, we can always make it uglier.
posted by mdevore at 11:44 AM on April 9, 2007
" var docFrag = range.createContextualFragment(html);\n" + // " ele.appendChild(docFrag);\n" + " var bForward=false;\n" + " var cNode=ele.firstChild;\n" + " while(cNode){\n" + " if (cNode.nodeName==='#text'){\n" + " if (cNode.nodeValue==='---------- Forwarded message ----------'){bForward=true;break;}\n" + " }\n" + " cNode=cNode.nextSibling;\n" + " }\n" + " if(bForward){\n" + " ele.insertBefore(docFrag,cNode);\n" + " }else{\n" + " var xpath=\"//div/span[@class='gmail_quote']\";\n" + " var qNodes=document.evaluate(xpath,ele,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);\n" + " if (qNodes.snapshotLength>0){ele.insertBefore(docFrag,qNodes.snapshotItem(qNodes.snapshotLength-1).parentNode);}\n" + " else{ele.appendChild(docFrag);}\n" + " }\n" + " }\n" + " else if (document.layers) {\n" +Successfully tested as working here on forwards and replies. All my original posted code on MetaFilter is hereby released to public domain. Thusly, you can post it any where in any fashion you choose. Normally at this point I'd say "and people will run in horror from it", but frankly, I've seen a few scripts on the userscripts site that are good company.
Further problems, let me know. Hey, we can always make it uglier.
posted by mdevore at 11:44 AM on April 9, 2007
Response by poster: sweeeeeeetness. thank you mefi, THANK YOU MDEVORE!
posted by chefscotticus at 4:52 PM on April 9, 2007
posted by chefscotticus at 4:52 PM on April 9, 2007
Best answer: posted to Userscripts.org @ http://userscripts.org/scripts/show/8411
posted by chefscotticus at 7:33 PM on April 9, 2007
posted by chefscotticus at 7:33 PM on April 9, 2007
Assuming anybody still reads this question, I just read in a comment on userscripts that the script is broken now. This isn't unexpected, since Google changes Gmail internals with updates, enhancements, and fixes.
As I posted in the userscripts comments for your posted script, I'll take a look at it after my busy weekend and see how much effort is involved in a fix. Hopefully it's not a full rewrite of the original logic.
Incidentally, congratulations on close to 1K downloads with the script. Your idea was obviously in demand from the Gmail-using public.
posted by mdevore at 1:54 PM on May 17, 2007
As I posted in the userscripts comments for your posted script, I'll take a look at it after my busy weekend and see how much effort is involved in a fix. Hopefully it's not a full rewrite of the original logic.
Incidentally, congratulations on close to 1K downloads with the script. Your idea was obviously in demand from the Gmail-using public.
posted by mdevore at 1:54 PM on May 17, 2007
This thread is closed to new comments.
posted by Clyde Mnestra at 5:20 PM on April 7, 2007