Jump to content

RandomNumberGen

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by RandomNumberGen

  1. Cool, I did it.

    <!DOCTYPE html>
    <html>
    <style>
    .tk { border-collapse: collapse; }
    .tk th, td { border: 1px solid #ddd; padding: 6px }
    .tk th { width: 56px; background-color: #f7f7f7; font-size: 24px; font-weight: normal; }
    .tk td { width: 240px; text-align: left; font-size: 16px; }
    </style>
    <body onload="kanjiFormat()">
    
    <p id="jisho">#長#long, leader#ながい、おさ#チョウ#</p>
    
    <script>
    var codeKstart = '<table align="center" class="tk"><tr><th rowspan="2">'
    var codeMstart = '</th><td>'
    var codeRstart = '</td></tr><tr><td>'
    var codeComma = '、'
    var codeRend = '</td></tr></table>'
    
    function kanjiFormat() {
        var str = document.getElementById("jisho").innerHTML; 
        var txt = str.replace(/#/, codeKstart).replace(/#/, codeMstart).replace(/#/, codeRstart).replace(/#/, codeComma).replace(/#/, codeRend);
        document.getElementById("jisho").innerHTML = txt;
    }
    </script>
    
    </body>
    </html>

    Now:

    - How do I make the search for forward slashes (/)? I replaced them with # for the sake of testing. Nevermind, it will try to replace the forward slashes from html as well. Gotta replace them with another symbol when I paste it.

    - Also, sometimes there one less category (e.g. /電/electricity/デン), in that case I wouldn't need the comma var. Where do I put an if in this function?

  2. Hi, I would like to know if it's possible to use javascript (specially on Anki; if you know what it is) to format a text line into a html table.

    Basically, what I want is to copy the definition of an online dictionary (japanese in this case):

    長/long, leader/ながい、おさ/チョウ

    And have the javascript read the first "/", select what's behind it, put in a <th>, select what's between first and second /, put in a <td>, and so forth. I have the CSS set up already. All of this in real time, like, when the software tries to show the line above, the JS will format it to show the stylized table to me. 

    Is this even possible? Does the w3s guide teach this kind of stuff at some point?

×
×
  • Create New...