Advertisement
rccharles

add asc shortcut keys v2

Feb 14th, 2019
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.    multiple command key shortcuts#3 27-Jan-2019
  3.  
  4.    Function:
  5.       command + s    to save the post.
  6.       command + control + command + h    Toggles between showing the underlying html and back to normal.
  7.                                          Note: Apple filters the html.
  8.  
  9.       future commands
  10.         select picture
  11.         quote
  12.         strikeout
  13.  
  14.       Intercepts command + s.  "Clicks" on save/edit button. Prevent command+s bubbling.
  15.  
  16.  
  17.     interesting
  18.       https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
  19.       https://discussions.apple.com/thread/250079673?page=1
  20.  
  21.     from Greasemonkey hacks: tips & Tools for Remixing the web with Firefox
  22.     by Julien Couvreur
  23.     Code from book with his gracious permission
  24.  
  25.     Javascript: The Definitive Guide 6th Edition
  26.  
  27.     Avoids use of jquery.  jquery is not working for me at this time.
  28.  
  29. https://stackoverflow.com/questions/2878983/capture-key-press-without-placing-an-input-element-on-the-page
  30. window.addEventListener('keydown', function (e) {
  31.   if (e.ctrlKey && e.keyCode == 90) {
  32.     // Ctrl + z pressed
  33.   }
  34. });
  35.  
  36. Assigns each level of a brace to a different color.
  37. http://www.balancebraces.com/
  38.  
  39. show utf character codes:
  40. https://mothereff.in/js-escapes#1%E6%BC%A2%E5%AD%97
  41.  
  42. getting and setting css variables
  43. https://davidwalsh.name/css-variables-javascript
  44.   How to initialize
  45.   :root {
  46.     --my-variable-name: #999999;
  47.   }
  48.  
  49.   getComputedStyle(document.documentElement)
  50.     .getPropertyValue('--my-variable-name'); // #999999
  51.  
  52.   document.documentElement.style
  53.     .setProperty('--my-variable-name', 'pink');
  54.  
  55. What html characters do we need to escape?
  56.     &lt; (<)
  57.     &gt; (>)
  58.     &amp; (&)
  59.     &quot; double-quote (")
  60.     &apos; single quote (')
  61.   https://www.w3.org/International/questions/qa-escapes#use
  62.  
  63. Support for full regular expressions in include and exclude rules is also available.
  64. If the rule both starts and ends with a forward-slash (/) character,
  65. the contents inside those slashes are interpreted as a regular expression.
  66.  
  67. two types of url's we need to handle:
  68. https://discussions.apple.com/thread/250075737
  69. https://discussions.apple.com/create/question?communityId=2206020
  70. https://discussions.apple.com/create/userTip?communityId=2206020
  71. https://discussions.apple.com/docs/DOC-250000368
  72.  
  73. */
  74.  
  75. /* eslint                                        */
  76. /* https://eslint.org/docs/rules/no-multi-spaces */
  77. /* Most of these rule adjustment don't work in   */
  78. /*   this browser :-(.                            */
  79. /* eslint "ignoreEOLComments": "off", "ignoreComments": "off" */
  80. // /*eslint no-caller: "error"*/
  81. // /* eslint no-multi-spaces: ["error", { ignoreEOLComments: true }] */
  82.  
  83. // ==UserScript==
  84. // @name        multiple command key shortcuts#3 27-Jan-2019
  85. // @namespace   bubo-bubo/gmscripts
  86. // @description Implement save and html edit shortcut.
  87. // @include     /https://discussions\.apple\.com/+thread/+.*/
  88. // @include     /https://discussions\.apple\.com/create/question.*/
  89. // @include     /https://discussions\.apple\.com/create/userTip.*/
  90. // @include     /https://discussions\.apple\.com/docs/.*/
  91. // @version     19Jan2019
  92. // @grant       none
  93. // ==/UserScript==
  94.  
  95.  
  96. var debug = 2; // 0 -- no debug
  97.                // 1 -- normal debug
  98.                // 2 -- intense debug
  99.                // 3 -- extremely intense
  100.  
  101. // Keeps tracks of what stage we are in our HTML edit.
  102. //  0 is not editing
  103. //  1 is editing.  Thereby displaying actually html.
  104. var trackHTMLEdit = false;
  105.  
  106. // Is event listner load deployed?
  107. var deployListnerLoad = false;
  108.  
  109. let aDate = new Date();
  110. console.log ("====> starting command key shortcuts. " + aDate + " <====");
  111.  
  112. // Setup once page is loaded.
  113. // This program monitors incoming keypress.  When a known key is observed, this program takes the
  114. // assigned action.
  115.  
  116. /* Most likely will be interactive.
  117.     The script will run after the main page is loaded, but before other resources
  118.     (images, style sheets, etc.) have loaded.
  119.     https://wiki.greasespot.net/Metadata_Block#.40run-at  */
  120. if (debug) console.log("document.readyState is " + document.readyState);
  121.  
  122. //  ready to roll? More stuff for later?
  123. if (document.readyState=="complete") {
  124.   console.log("rolling along")
  125.   // rolling along
  126.   pageLoadComplete()
  127. }
  128. else {
  129.   if (debug>=2) console.log('adding listeners')
  130.   // wait out page loading.
  131.   window.addEventListener("load",
  132.                           pageLoadComplete,
  133.                           true);
  134.   deployListnerLoad = true;
  135. }
  136. // register event listeners
  137. // nothing like starting at the end ;-)
  138.  window.addEventListener('unload',
  139.         function(e)
  140.         {
  141.           if (debug) console.log('unloading.');
  142.           // may not be needed.  Wonder if that is bad?
  143.           if (deployListnerLoad) {
  144.             window.removeEventListener("load",
  145.                                        pageLoadComplete,
  146.                                        true);
  147.             deployListnerLoad = false;
  148.           }
  149.           window.removeEventListener("keypress",
  150.                                      processKey,
  151.                                      false);
  152.           if (debug) console.log('removing e.type is '+ e.type + " arg is " + arguments.callee);
  153.           // remove anonymous unload. [ Thus unload ]
  154.           window.removeEventListener(e.type,
  155.                                      arguments.callee,
  156.                                      true);
  157.         },
  158.         true);
  159.  
  160. // last set value is returned as return code.
  161. var done;
  162. done = 0;
  163.  
  164. // -----------------------------------------------------------------------------
  165. function pageLoadComplete() {
  166.   if (debug>=2) console.log("All page resources finished loading!")
  167.   // find how many reply buttons there are.  Not used for nothing.
  168.   var theNodes = document.querySelectorAll(
  169.     "button.button.button-black:not(.hidden):not(.button-checked)")
  170.   if (debug>=2) spew ("theNodes",theNodes)
  171.   if (debug)console.log("let's get started.")
  172.  
  173.   /* Let's get started. */
  174.   processPage()
  175.  
  176. } // end function pageLoadComplete
  177.  
  178. /* --------------------------------------------------------------------- */
  179. /* main line code */
  180. function processPage() {
  181.   if (debug) console.log ("--> processPage.  ");
  182.  
  183.   /* Who knows, we might have to wait a bit */
  184.   /* <div class="editor-section"> */
  185.   //var theNode = document.querySelector("div.editor-section")
  186.   var theNode = document.querySelector("div#main-content")
  187.   console.log("theNode is ",theNode)
  188.   theNode.addEventListener("keypress",
  189.                            processKey,
  190.                            false);
  191.  
  192.   if (debug) console.log ("done with processPage  ");
  193. } // end of processPage;
  194.  
  195. // -----------------------------------------;
  196. function processKey(event) {
  197.   if (debug) console.log("in processKey with event input event",event);
  198.   if (debug>=2) {
  199.     console.log("  event.altKey is " + event.altKey);
  200.     console.log("  event.ctrlKey is " + event.ctrlKey);
  201.     console.log("  event.metaKey is " + event.metaKey);
  202.     console.log("  event.shiftKey is " + event.shiftKey);
  203.     console.log("  event.charCode is " + event.charCode + "  event.key is " + event.key);
  204.   } // end if debug;
  205.  
  206.   // Check modifier keys;
  207.   /*
  208.   command + s for save post
  209.   control + command + h for html edit
  210.   control + command + p for pick picture
  211.   control + command + PageUp to decrease edit box size
  212.   control + command + PageDown to increase edit box size
  213.   */
  214.   if (event.altKey) {
  215.     // skip;
  216.     if (debug>=2) console.log ("  skipping altKey! no actions assigned.");
  217.   }
  218.   else if (event.shiftKey) {
  219.     // skip;
  220.     if (debug>=2) console.log ("  skipping shiftKey! no actions assigned.");
  221.   }
  222.   // meta key is required for save, html edit, quote and select picture;
  223.   else if (event.metaKey) {
  224.     if (debug>=2) console.log ("  metaKey found!");
  225.     // control key is required for html edit, quote and select picture;
  226.     if (event.ctrlKey) {
  227.       if (debug>=2) console.log ("  ctrlKey found!");
  228.       // could be control + command + h for html edit;
  229.       if (event.charCode === 104) {
  230.         if (debug>=2) console.log ("  command + control + h!");
  231.         htmlEdit(event);
  232.       }
  233.       // could be control + command + p for pick picture;
  234.       else if (event.charCode === 112) {
  235.         if (debug>=2) console.log ("  command + control + p!");
  236.         findPicture(event);
  237.         if (debug>=2) console.log ("  processed image");
  238.       }
  239.       // could be control + command + PageUp to decrease edit box size;
  240.       else if (event.key === "PageUp") {
  241.         if (debug>=2) console.log ("  command + control + PageUp!");
  242.         increaseEditBox(event,-100);
  243.         if (debug>=2) console.log ("  processed image");
  244.       }
  245.        // could be control + command + PageDown to increase edit box size;
  246.       else if (event.key === "PageDown" ) {
  247.         if (debug>=2) console.log ("  command + control + PageDown!");
  248.         increaseEditBox(event,100);
  249.         if (debug>=2) console.log ("  processed image");
  250.       }
  251.     } // end of ctrlKey;
  252.     else {
  253.       if (debug>=2) console.log ("  processing metaKey!");
  254.       // could be command + s for save post
  255.       if (event.charCode === 115 ){
  256.         if (debug>=2) console.log ("  found command + s!");
  257.         // <div class="editor-section hidden">;
  258.         //   ... clipped ...
  259.         // <button class="button" data-action="submit-post">Post</button>
  260.         // same for repy and edit.
  261.         // div.editor-section
  262.         // let saveButton = document.querySelector('button.button[data-action="submit-post"]')
  263.         // noticed after reply, reminants are left hidden :-(. So, avoid hidden.;
  264.         let saveButton = document.querySelector(
  265.                 'div.editor-section:not(.hidden) button.button[data-action="submit-post"], section.create-post div.create-post-buttons button.button.create-post-button');
  266.         if (debug>=2) console.log ("saveButton is ",saveButton);
  267.         if (saveButton) {
  268.           clickAnchorTag(saveButton);
  269.           //  we will take control of command+s, so don't pass up to other event handlers.;
  270.           event.preventDefault();
  271.         }
  272.         else {
  273.           if (debug) console.log("We have no reply to save; bubble up.");
  274.         }
  275.       } // 115 or s;
  276.     } // end of else not control key;
  277.   } // metaKey;
  278.   //GetDescriptionFor(e,"  ");
  279.   if (debug>=1) console.log("  done with processKey");
  280. } // end of processKey;
  281.  
  282. /* --------------------------------------------------------------------- */
  283. function htmlEdit(event)
  284. {
  285.   /*
  286.       This html is for the reply and edit reply.  There is a slightly different format for
  287.       a new post and a user tip.
  288.       <div class="editor-section">
  289.         <div id="editor-placeholder" ... >
  290.           <div class="editor ql-container" ... >
  291.             <div class="ql-editor"
  292.               data-gramm="false"
  293.               data-placeholder="Tell us what’s on your mind."
  294.               contenteditable="true">
  295.   */
  296.   // find the editor section.
  297.   // Reply and Edit Reply catch first selector.
  298.   // Create new post and new user tip catch on second selector.
  299.   let saveTextNode = document.querySelector(
  300.     'div.editor-section:not(.hidden) div#editor-placeholder div.ql-editor, section.create-post div.editor.ql-container div.ql-editor')
  301.   if (debug>=2) console.log("saveTextNode is ",saveTextNode)
  302.   // is the user really doing an edit?
  303.   if (saveTextNode) {
  304.     // should we begin the HTML edit?
  305.     if (trackHTMLEdit===false) {
  306.       // request to edit.
  307.       let savedInnerHTML = saveTextNode.innerHTML
  308.  
  309.       displayHexString(savedInnerHTML,"    ")
  310.  
  311.       if (debug>=2) console.log("savedInnerHTML is ",savedInnerHTML)
  312.       // Convert display to HTML
  313.       // amazing.
  314.       // https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript
  315.       saveTextNode.innerText = savedInnerHTML
  316.       // toggle
  317.       trackHTMLEdit = true
  318.       //  we will take control of control + command + h, so don't pass up
  319.       //    to other event handlers.
  320.       event.preventDefault()
  321.     }
  322.     else {
  323.       // end HTML edit.  Convert to regular text.
  324.       if (debug>=2) console.log("displaying html. Convert back. ")
  325.       // already doing HTML edit.
  326.       let displayedText=saveTextNode.innerText
  327.       if (debug>=2) console.log("displayedText is ",displayedText)
  328.       saveTextNode.innerHTML = displayedText
  329.       // toggle
  330.       trackHTMLEdit = false
  331.       //  we will take control of control + command + h, so don't pass up
  332.       //    to other event handlers.
  333.       event.preventDefault()
  334.     }
  335.   } // end doing an edit found "right" node
  336.   else {
  337.     if (debug) console.log("reply edit note not found.")
  338.   }
  339. } // end of function htmlEdit
  340.  
  341. /* --------------------------------------------------------------------- */
  342. function findPicture(event) {
  343.    if (debug>=1) console.log ("in findPicture")
  344.    var savePicture = document.querySelector('div.toolbar div.row  section.buttons-group:not(.hide-mobile) button.rte-button.rte-hl-bg-active:first-child')
  345.    if (debug>=2) console.log ("savePicture is ",savePicture)
  346.    if (savePicture) {
  347.      clickAnchorTag(savePicture)
  348.      //  we will take control of command+s, so don't pass up to other event handlers.
  349.      event.preventDefault();
  350.    }
  351. } // end of findPicture
  352.  
  353. /* --------------------------------------------------------------------- */
  354. /*
  355. // Set multiple styles in a single statement
  356. elt.style.cssText = "color: blue; border: 1px solid black";
  357. // Or
  358. elt.setAttribute("style", "color:red; border: 1px solid blue;");
  359.  
  360. // Set specific style while leaving other inline style values untouched
  361. elt.style.color = "blue";
  362.  
  363. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
  364.  
  365. */
  366. function increaseEditBox(event,changeSize) {
  367.   if (debug>=1) console.log ("in increaseEditBox")
  368.   // if we find a messed up style, continue on our merry way.
  369.   try {
  370.    var saveEdit = document.querySelector('div.editor.ql-container');
  371.    if (debug>=2) console.log ("saveEdit is ",saveEdit);
  372.    if (saveEdit) {
  373.      let allStyle = saveEdit.getAttribute("style")
  374.      if (debug>=2) console.log("allStyle are ",allStyle);
  375.      // Have we been through here before?
  376.      if ( allStyle.search(/!important;/)>=0) {
  377.        // been there done that
  378.        editorHeight=saveEdit.style.getPropertyValue('--editor-height');
  379.        console.log("editorHeight via html is ",editorHeight)      
  380.      }
  381.      else {
  382.        // need to take from composite style
  383.        editorHeight = window.getComputedStyle(saveEdit).getPropertyValue('--editor-height')
  384.        console.log("editorHeight via getComputedStyle is ",editorHeight)
  385.      }
  386.        
  387.      /* https://stackoverflow.com/questions/8811027/
  388.      get-elements-custom-css-properties-mystyle-using-javascript/36609605#36609605 */
  389.    
  390.      // fyi: returns an array
  391.      editorHeightNumber = editorHeight.split("px")
  392.      console.log("editorHeightNumber is ",editorHeightNumber)
  393.      let count = Number(editorHeightNumber[0])
  394.      count+=changeSize
  395.      if (count <= 100){ count = Math.abs(changeSize) }
  396.      console.log("count is ",count)
  397.      const injectionString = count.toString()+"px !important;"
  398.      console.log("injectionString is ",injectionString, "typeof injectionString is "
  399.                  + typeof injectionString)
  400.      console.log("saveEdit.attributes are now ",saveEdit.attributes);
  401.      console.log("~1~style is ",saveEdit.getAttribute("style"));
  402.      // Up cascade priority
  403.      // setting css variable, --editor-height, drops off second word, "!important;".  :-(.
  404.      editorHeightHTML=saveEdit.style.getPropertyValue('--editor-height');
  405.      console.log ("editorHeightHTML is ", editorHeightHTML)
  406.      const alteredString = allStyle.replace(editorHeightHTML,injectionString)  
  407.      console.log (" alteredString is ", alteredString)
  408.      saveEdit.style.cssText = alteredString
  409.      console.log("~2~style is ",saveEdit.getAttribute("style"));
  410.      
  411.      if (debug>=2) console.log ("eat character")
  412.      //  we will take control of command+s, so don't pass up to other event handlers.
  413.      event.preventDefault()
  414.    }  // end of if (saveEdit)
  415.    else {
  416.      console.log("\nCould not find edit box!!!\n")
  417.    }
  418.    if (debug>=2) console.log ("bye from increaseEditBox")
  419.  
  420.    //Object.keys(inputObj).forEach(e => console.log(`key=${e}  value=${inputObj[e]}`));
  421.   } // end of try
  422.   catch (err) {
  423.     console.log ("Don't understand style format.\"" + err.message + "\"" )
  424.   } // end catch
  425.  
  426. } // end function increaseEditBox
  427.  
  428. /* --------------------------------------------------------------------- */
  429. function decreaseEditBox(event) {
  430.  
  431. }
  432.  
  433. /* --------------------------------------------------------------------- */
  434. function GetDescriptionFor(e,inDent)
  435. {
  436. if (debug>=2) {
  437.   console.log (inDent + "in GetDescriptionFor")
  438.   console.log (inDent + "e.keyCode is " + e.keyCode )
  439.   console.log (inDent + "e.keyCode in hex is " +toHexString(e.keyCode,inDent+"  ") )
  440. }
  441. var result, code;
  442. if ((e.charCode) && (e.keyCode==0))
  443. {
  444.  result = "charCode: " + e.charCode;
  445.  code = e.charCode;
  446. } else {
  447.  result = "keyCode: " + e.keyCode;
  448.  code = e.keyCode;
  449. }
  450.  
  451. if (code == 8) result += " BKSP"
  452. else if (code == 9) result += " TAB"
  453. else if (code == 46) result += " DEL"
  454. else if ((code >= 41) && (code <=126)) result += " '" + String.fromCharCode(code) + "'";
  455.  
  456. if (e.altKey) result += " alt";
  457. if (e.ctrlKey) result += " ctrl";
  458. if (e.metaKey) result += " meta";
  459. if (e.shiftKey) result += " shift";
  460. console.log (inDent + "result is " + result)
  461. return result;
  462. } // end of GetDescriptionFor
  463.  
  464. /* --------------------------------------------------------------------- */
  465. /* print out objects:
  466.   https://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object
  467.   https://code-maven.com/logging-javascript-objects
  468. */
  469. function spew (objName,inputObj) {
  470.   if (debug>=1) console.log ("starting spew")
  471.   if (debug>=2) {
  472.     console.log (objName + " is: ", inputObj)
  473.     console.log ("inputObj.length is " + inputObj.length)
  474.     console.log ("typeof inputObj is " + typeof inputObj)
  475.     //this will show object gandalf IN ALL BROWSERS!
  476.     console.log(JSON.stringify(inputObj));
  477.     //this will show object gandalf IN ALL BROWSERS! with beautiful indent
  478.     console.log(JSON.stringify(inputObj, null, 4));
  479.     console.log("keys",Object.keys(inputObj));
  480.     console.log("lenght is " + Object.keys(inputObj).length)
  481.     console.log(Object.values(inputObj));
  482.  
  483.     //There is also this new option if you're using ECMAScript 2016 or newer:
  484.     try {
  485.       Object.keys(inputObj).forEach(e => console.log(`key=${e}  value=${inputObj[e]}`));
  486.     }
  487.     catch (err) {
  488.       console.log (" You must need ECMAScript 2016 or newer \""+ err.message + "\"" )
  489.     } // end catch
  490.  
  491.   } // end of if debug printing code
  492.   if (debug>=1) console.log ("ending spew")
  493. } // end of function spew
  494.  
  495. // -----------------------------------------
  496. //  demo
  497. //  http://mothereff.in/js-escapes#1%E6%BC%A2%E5%AD%97
  498. //;
  499. function displayHexString(value,inDent) {
  500.   if (debug>=1) console.log("in function displayHexString");
  501.   var hexString = value.hexEncode();
  502.   if (debug>=2) console.log (inDent + "hexString is " + hexString);
  503.   if (hexString.length % 2) {
  504.     hexString = '0' + hexString;
  505.   }
  506.   const increment = 16;
  507.   var prefixNumber = 0;
  508.   var prefixNumberSpan = increment;
  509.  
  510.   // print groups of sixteen;
  511.   while( hexString.length > increment ) {
  512.     let prefixHex = prefixNumber.toString(increment);
  513.     if (prefixHex.length % 2) {
  514.       prefixHex = '0' + prefixHex;
  515.     } // end of if;
  516.     // Print out on console.;
  517.     // four hex digits per one printable.;
  518.     console.log(prefixHex + " " + hexString.substring(0,increment) + "  " +
  519.                 value.substring(prefixNumber/4,prefixNumberSpan/4)               );
  520.     hexString = hexString.substring(increment);
  521.     if (debug>=3) console.log( "hexString is "+ hexString);
  522.     prefixNumber += increment;
  523.     prefixNumberSpan += increment;
  524.     if (debug>=3) console.log("prefixNumber is "+ prefixNumber + " prefixNumberSpan is " + prefixNumberSpan);
  525.   } // end of while;
  526.  
  527.   if (debug>=3) console.log("done with groups of  " + increment);
  528.   if ( hexString.length ) {
  529.     let prefixHex = prefixNumber.toString(increment);
  530.     if (prefixHex.length % 2) {
  531.       prefixHex = '0' + prefixHex;
  532.     } // end of if
  533.     // Print out on console.
  534.     console.log(prefixHex + " " + hexString);
  535.   } // end of if;
  536.  
  537. } // end of toHexString;
  538.  
  539. /* --------------------------------------------------------------------- */
  540. /*
  541. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
  542.  
  543. <!DOCTYPE HTML>
  544. <html>
  545.   <body style="font-weight:bold;">
  546.     <div style="color:red" id="myElement">..</div>
  547.   </body>
  548. </html>
  549.  
  550. The style property is not useful for completely learning about the styles applied on the element,
  551. since it represents only the CSS declarations set in the element's inline style attribute, not
  552. those that come from style rules elsewhere, such as style rules in the <head> section, or
  553. external style sheets. To get the values of all CSS properties for an element you should use
  554. Window.getComputedStyle() instead.
  555.  
  556. The output would be something like:
  557.  
  558. ...
  559. fontWeight = '' > 'bold'
  560. color = 'red' > 'rgb(255, 0, 0)'
  561. ...
  562.  
  563. Note the presence of the value "bold" for font-weight in the computed style and the absence
  564. of it in the element's style property
  565. */
  566. function printCombinedStyle(element) {
  567. //var element = document.getElementById("myElement");
  568. var out = "";
  569. var elementStyle = element.style;
  570. var computedStyle = window.getComputedStyle(element, null);
  571.  
  572. for (prop in elementStyle) {
  573.   if (elementStyle.hasOwnProperty(prop)) {
  574.     out += "  " + prop + " = '" + elementStyle[prop] + "' > '" + computedStyle[prop] + "'\n";
  575.   }
  576. }
  577. console.log(out)
  578. } // end of function printCombinedStyle
  579.  
  580. /* --------------------------------------------------------------------- */
  581. // https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex
  582. String.prototype.hexEncode = function(){
  583.     var hex, i;
  584.  
  585.     var result = "";
  586.     for (i=0; i<this.length; i++) {
  587.         hex = this.charCodeAt(i).toString(16);
  588.         result += ("000"+hex).slice(-4);
  589.     }
  590.  
  591.     return result
  592. }
  593. /* --------------------------------------------------------------------- */
  594. /* based on:
  595.      https://stackoverflow.com/questions/902713/how-do-i-programmatically-click-a-link-with-javascript
  596. */
  597. function clickAnchorTag(inputObj) {
  598.     if (debug>=1) console.log("in clickAnchorTag.\n inputObj is",inputObj)
  599.  
  600.     var event = document.createEvent('MouseEvent');
  601.     if (debug>=2) console.log ("proceeding to set new event")
  602.     event = new CustomEvent('click');
  603.     if (debug>=2) console.log ("clicking...")
  604.     inputObj.dispatchEvent(event);
  605. } // end of clickAnchorTag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement