14 votes

Tildes Formatting Toolbar - Userscript adds text formatting buttons and keyboard shortcuts

8 comments

  1. [3]
    pseudochron
    Link
    This userscript adds a toolbar to the comment box with buttons for bold, italic, and links. It also will format highlighted text with keyboard shortcuts: Ctrl+B = bold, Ctrl+I = italic, Ctrl+K =...
    • Exemplary

    This userscript adds a toolbar to the comment box with buttons for bold, italic, and links. It also will format highlighted text with keyboard shortcuts: Ctrl+B = bold, Ctrl+I = italic, Ctrl+K = link.

    https://i.imgur.com/3r0NHO2.png

    12 votes
    1. [2]
      pseudochron
      Link Parent
      I've updated this to add 10 more buttons: https://i.imgur.com/Ly59leJ.png Some features that I think are useful (that the other Markdown toolbar add-on doesn't do): list and quote buttons: inserts...

      I've updated this to add 10 more buttons: https://i.imgur.com/Ly59leJ.png

      Some features that I think are useful (that the other Markdown toolbar add-on doesn't do):

      • list and quote buttons:
        • inserts the relevant characters at the beginning of the current line if no text is selected, instead of at the current cursor position.
        • if multiple lines are selected, will insert the characters at the beginning of each line
        • if the line already starts with the characters for quote or list, the button will toggle it off instead of adding another
      • code button: it will use inline code if one or less lines are selected, and block code if multiple lines are selected, instead of having two different "code" buttons
      6 votes
      1. AugustusFerdinand
        Link Parent
        A bug: On Chrome the last two buttons look like this. Some feature requests as compared to RES and ReExtended: When bolding something on RES it'll ignore trailing spaces so that if you highlight...

        A bug:

        1. On Chrome the last two buttons look like this.

        Some feature requests as compared to RES and ReExtended:

        1. When bolding something on RES it'll ignore trailing spaces so that if you highlight something and hit bold (or any other formatting) it stops at the end of the last word. **Bold **with script/ReExtended, with a trailing space, for example.

        2. The link button on the script keeps the highlighted text selected and puts "url" in the parentheses following it, in ReExtended the cursor moves automatically to the "url" area for pasting the address. This may be personal preference, but I'd think that more people have the URL at the ready to paste vs needing to add additional formatting to the selected text.

        Thanks a ton!

        I've been wanting a hotkey enabled text formatting for some time and you've delivered that. So thank you very much for this.

        2 votes
  2. [4]
    cfabbro
    (edited )
    Link
    Not to rain on your parade, @pseudochron, but rather to just inform people who are interested in similar features; @Bauke's Tildes ReExtended (Firefox add-on) also has something like this as well,...

    Not to rain on your parade, @pseudochron, but rather to just inform people who are interested in similar features; @Bauke's Tildes ReExtended (Firefox add-on) also has something like this as well, but with a few more options: https://i.imgur.com/t3iatWQ.png

    11 votes
    1. [3]
      AugustusFerdinand
      Link Parent
      Huh... Don't know why I thought @bauke was gone, but I did and so had been continuing onward waiting for it to stop working entirely. I guess I'll send him a message with a couple of bugs.

      Huh... Don't know why I thought @bauke was gone, but I did and so had been continuing onward waiting for it to stop working entirely. I guess I'll send him a message with a couple of bugs.

      2 votes
      1. [2]
        cfabbro
        Link Parent
        If you have a GitLab account, you can submit the bug reports yourself, if you're so inclined: https://gitlab.com/tildes-community/tildes-reextended/-/issues If not, feel free to let me know what...

        If you have a GitLab account, you can submit the bug reports yourself, if you're so inclined:
        https://gitlab.com/tildes-community/tildes-reextended/-/issues

        If not, feel free to let me know what they are, and I can add them for you since I am a "Maintainer" on the Tildes ReExtended GitLab too. :P

        1 vote
        1. AugustusFerdinand
          Link Parent
          I do not have an account, so thanks for that. I'll shoot you a message.

          I do not have an account, so thanks for that. I'll shoot you a message.

          1 vote
  3. asterisk
    Link
    Interesting. I didnʼt know about it, so I made my own script. I updated it today, so I just checked similar here, and I found this thread. My script // ==UserScript== // @name Format Hotkeys for...

    Interesting. I didnʼt know about it, so I made my own script. I updated it today, so I just checked similar here, and I found this thread.

    My script
    // ==UserScript==
    // @name        Format Hotkeys for Tildes
    // @version     16-August-2022
    // @author      Jurid
    // @description Format Hotkeys for tildes.net
    // @icon        https://tildes.net/favicon-16x16.png
    // @match       *://tildes.net/*
    // ==/UserScript==
    
    var ctrl = {                                  // mnemonic
      "Digit1": ["## ", ""],                      // 1+
      "Digit2": ["### ", ""],
      "Digit3": ["#### ", ""],
      "Digit4": ["##### ", ""],
      "Digit5": ["###### ", ""],
      "Digit6": ["<sup>", "</sup>"],              // ^
      "Digit8": ["0. ", ""],                      // *
      "Minus": ["<sub>", "</sub>"],               // _
      "Equal": ["<summary>", "</summary>"],       // +
      "KeyB": ["**"],                             // bold
      "KeyD": ["<details>", "</details>"],        // details
      "KeyH": ["\n---\n", ""],                    // horizontal
      "KeyI": ["_"],                              // italic
      "KeyL": ["[", "]( \"\")"],                  // link
      "KeyM": ["`"],                              // monospace
      "KeyS": ["~~"],                             // strikethrough
    
      "shift": {
        "KeyD": ["<details open>", "</details>"], // details opened
        "KeyI": ["<ins>", "</ins>"],              // insert
        "KeyM": ["```\n", "\n```"],               // monospace
        "KeyS": ["<small>", "</small>"],          // small
      }
    }
    
    function initiation() {
      [].forEach.call(document.querySelectorAll("textarea"), element =>
        element.addEventListener("keydown", combination, true)
      )
    } initiation()
    
    function combination(event) {
      for (let cmb of [
        [event.ctrlKey && event.shiftKey && ctrl.shift[event.code], ctrl.shift[event.code]],
        [event.ctrlKey && ctrl[event.code], ctrl[event.code]],
      ]) {
        if (cmb[0]) {
          event.preventDefault()
          modification(...cmb[1])
          break
        }
      }
    }
    
    function modification(open, close = open) {
      let field = document.activeElement
      let before = field.value.substring(0, field.selectionStart) + open
      let select = field.value.substring(field.selectionStart, field.selectionEnd)
      let after = close + field.value.substring(field.selectionEnd, field.value.length)
    
      document.execCommand("insertText", false, open + select + close)
    
      if ([open, close].every(tag => ctrl.KeyL.includes(tag)) && select.length) {
        field.selectionStart = field.value.length - after.length + 2
        field.selectionEnd = field.selectionStart
      } else {
        field.selectionStart = before.length
        field.selectionEnd = field.value.length - after.length
      }
    }
    
    new MutationObserver(() => initiation())
      .observe(document.body, { childList: true, subtree: true })
    

    Differences:

    • No toolbar, only hotkeys.
    • You can revert the last inputed markdown by Ctrl Z.
    2 votes