Advertisement
rccharles

asc shortkut keys v5

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