FlyerTalk Forums - View Single Post - Portable DING! fix available (was Portable Ding no longer works)
Old May 13, 2011, 8:03 pm
  #8  
ftnoob
Moderator, Southwest Airlines and Choice Privileges
 
Join Date: Mar 2008
Location: Central Texas
Posts: 3,036
Here is the Beta 0.2 (19-Apr-2011) version of the bookmarklet that will perform the above transformation that restores usability to portable DING! URLs:
Code:
javascript:function $(a){return document.getElementsByTagName(a)}function $$(a,b,c){typeof c==="undefined"&&(c=document);typeof b==="undefined"&&(b=0);a=c.getElementsByTagName(a);return a.length<b+1?"":a[b].firstChild.data}function loadXMLDoc(a){if(window.XMLHttpRequest)xhttp=new XMLHttpRequest;else return alert("Sorry, your browser can't handle this!"),!1;xhttp.open("GET",a,!1);xhttp.send("");return xhttp.responseXML}function fnObj(a,b,c){return{attrName:a,attrVal:b,text:c}} function newNode(a){var b=document.createElementNS("http://www.w3.org/1999/xhtml",a),c;arguments.length>1&&(c=arguments[1],c.attrName.length&&c.attrVal.length&&b.setAttribute(c.attrName,c.attrVal),c.text.length&&b.appendChild(document.createTextNode(c.text)));return b}function link(a,b){return newNode("a",fnObj("href",a,b))}function nestNodes(a){for(var b=a.length-1;b>0;b--)a[b-1].appendChild(a[b])} function getDisc(){var a=window.location.toString().replace("getMessages","createSession"),a=loadXMLDoc(a);if($$("status",0,a)!=="0")alert("Unable to create session; verify installId and cksum");else return $$("disc",0,a)} function addBetaTag(){var a,b,c;a=newNode("html:div",fnObj("style","margin: 2.5em 5em; color: red; font-size: 90%; font-style: italic;",""));b=newNode("p",fnObj("style","padding: 5px;",""));c=newNode("span",fnObj("style","border: 1px solid black; padding:2px;","Caution: You are using Beta v0.2 of this script. Be sure to "));c.appendChild(link("http://www.flyertalk.com/forum/16382603-post.html","check periodically"));c.appendChild(document.createTextNode(" for an updated version.")); nestNodes([a,b,c]);return a} function showAll(){var a=$("headline"),b,c,g,f,e,d,h;if(a.length===0)alert("No messages!");else{g="&disc="+getDisc();c=newNode("ul",fnObj("style","margin:2em;",""),"");for(b=0;b<a.length;b++)f=$$("activationText",0,a[b]).replace(/(<([^>]+)>)/ig,""),e=$$("activationUrl",0,a[b]),e.length>0?($$("type",0,a[b])==="offer"?(e+=g,d=$$("activationNewDelta",0,a[b])*1,h=newNode("span",fnObj("style","margin-left:2em; font-size:80%;","Active in "+(d/60).toFixed(0)+":"+(d% 60/100).toFixed(2)*100))):d=0,nestNodes([c, newNode("li"),link(e,f)]),d>0&&nestNodes([c.lastChild,h])):nestNodes([c,newNode("li",fnObj("","",f))])}a=newNode("div");nestNodes([a,c]);nestNodes([a,addBetaTag()]);nestNodes([a,newNode("p",fnObj("style","font-size:80%; margin:2em;",document.lastModified))]);document.replaceChild(a,document.firstChild)}showAll();
Beta 0.2 is the first version that works in the CYW Add On for Firefox, and perhaps the first version compatible with GreaseMonkey as well. That means you don't have to save a bookmarklet and manually apply it every time you view your portable DING! XML getMessages response file. That could be especially important for portable devices, though I don't know how compatible those tend to be with user scripts.

I have recently learned that there are ways to run GM scripts in IE and other browsers, but this particular script uses an XML command that, at best, until recently (ever?) has not existed in IE; if it doesn't work for you and you are restricted to using IE, but can use a script add-on and would like an IE version of the script, please let me know.

Otherwise, here is what to do: Install GreaseMonkey and this script, and the script's transformation will be applied automatically with every visit to your portable DING! URL, assuming there are any Headlines. (A "No messages" alert is displayed if there are no headlines.)

To add to Firefox as a GM script, save the following code to portableDingFixer.user.js (or whatever, as long as it ends in user.js), and drag the file onto Firefox.
Code:
// ==UserScript==
// @name            Portable DING! Enhancer
// @author          wnProTips
// @namespace       http://www.flyertalk.com/forum/members/ftnoob.html
// @description     Generates session ID, creates clickable links from displayed portable DING! getMessages page
// @license         Creative Commons Attribution License
// @version	    Beta 0.2
// @include         http://ding.southwest.com/cgi-bin/systray?action=getMessages*
// @released        2011-05-17
// @updated         2011-05-19
// @compatible      Greasemonkey
// ==/UserScript==
 
/* 
 * This file is a Greasemonkey user script. To install it, you need 
 * the Firefox plugin "Greasemonkey" (URL: http://greasemonkey.mozdev.org/)
 * After you installed the extension, restart Firefox and revisit 
 * this script. Now you will see a new menu item "Install User Script"
 * in your tools menu.
 * 
 * To uninstall this script, go to your "Tools" menu and select 
 * "Manage User Scripts", then select this script from the list
 * and click uninstall :-)
 *
 * Creative Commons Attribution License (--> or Public Domain)
 * http://creativecommons.org/licenses/by/2.5/
*/
function $(a){return document.getElementsByTagName(a)}function $$(a,b,c){typeof c==="undefined"&&(c=document);typeof b==="undefined"&&(b=0);a=c.getElementsByTagName(a);return a.length<b+1?"":a[b].firstChild.data}function loadXMLDoc(a){if(window.XMLHttpRequest)xhttp=new XMLHttpRequest;else return alert("Sorry, your browser can't handle this!"),!1;xhttp.open("GET",a,!1);xhttp.send("");return xhttp.responseXML}function fnObj(a,b,c){return{attrName:a,attrVal:b,text:c}} function newNode(a){var b=document.createElementNS("http://www.w3.org/1999/xhtml",a),c;arguments.length>1&&(c=arguments[1],c.attrName.length&&c.attrVal.length&&b.setAttribute(c.attrName,c.attrVal),c.text.length&&b.appendChild(document.createTextNode(c.text)));return b}function link(a,b){return newNode("a",fnObj("href",a,b))}function nestNodes(a){for(var b=a.length-1;b>0;b--)a[b-1].appendChild(a[b])} function getDisc(){var a=window.location.toString().replace("getMessages","createSession"),a=loadXMLDoc(a);if($$("status",0,a)!=="0")alert("Unable to create session; verify installId and cksum");else return $$("disc",0,a)} function addBetaTag(){var a,b,c;a=newNode("html:div",fnObj("style","margin: 2.5em 5em; color: red; font-size: 90%; font-style: italic;",""));b=newNode("p",fnObj("style","padding: 5px;",""));c=newNode("span",fnObj("style","border: 1px solid black; padding:2px;","Caution: You are using Beta v0.2 of this script. Be sure to "));c.appendChild(link("http://www.flyertalk.com/forum/16382603-post.html","check periodically"));c.appendChild(document.createTextNode(" for an updated version.")); nestNodes([a,b,c]);return a} function showAll(){var a=$("headline"),b,c,g,f,e,d,h;if(a.length===0)alert("No messages!");else{g="&disc="+getDisc();c=newNode("ul",fnObj("style","margin:2em;",""),"");for(b=0;b<a.length;b++)f=$$("activationText",0,a[b]).replace(/(<([^>]+)>)/ig,""),e=$$("activationUrl",0,a[b]),e.length>0?($$("type",0,a[b])==="offer"?(e+=g,d=$$("activationNewDelta",0,a[b])*1,h=newNode("span",fnObj("style","margin-left:2em; font-size:80%;","Active in "+(d/60).toFixed(0)+":"+(d %60/100).toFixed(2)*100))):d=0,nestNodes([c, newNode("li"),link(e,f)]),d>0&&nestNodes([c.lastChild,h])):nestNodes([c,newNode("li",fnObj("","",f))])}a=newNode("div");nestNodes([a,c]);nestNodes([a,addBetaTag()]);nestNodes([a,newNode("p",fnObj("style","font-size:80%; margin:2em;",document.lastModified))]);document.replaceChild(a,document.firstChild)}showAll();

// you can completely copy this template, including
// the install description, have fun! :-)
This is the first time ever that yours truly has ever shared a GM script with anyone (sorry, no alpha testing, yet alone beta testing). Truth be told, it has only been a day or so since I tested my first 'Hello World' example GM user script, so go easy on me if it has problems.

What you need to do:
  • Install GreaseMonkey, if not already installed;
  • Save the script above as [something].user.js;
  • Add [something].user.js as one of your GM scripts;
  • Load your portable DING! URL as usual.
Voila! (If all goes well).

Stuck with a browser that doesn't support GreaseMonkey? Google IE greasemonkey user scripts" or similar and explore Trixie and such. No use if you can't install *anything* at work, but check it out otherwise.

Mobile device feedback specifically requested.

Last edited by ftnoob; Aug 31, 2011 at 10:45 pm
ftnoob is offline