Script - Plain Text URLS to HTML Page

Script - Plain Text URLS to HTML Page

18
Basic UserBasic User
18

    Feb 27, 2011#1

    At times, I will have a long list of urls that I want to download (e.g. zip files), and I don't want to do one at a time. So I have an add-on for firefox called "downthemall". When you have a page up in your browser, you can right click on the page and tell "downthemall" to download all or selected links on that page.

    So in another editor, I created a macro to create a webpage for the above use. It takes the list of urls, and creates a html page for it. Let's say your file contains this (I know these aren't valid urls... it's just to demo the process):

    a
    b

    After running the script you will get:

    Code: Select all

    <html>
    <head>
    <title>aaa</title>
    <body>
    <a href="a">a</a><br>
    <a href="b">b</a><br>
    </body>
    </html>
    After this, save it as an html file, open it in firefox, right click and select "downthemall", and you can download all the files... with minimal effort. The "title" is prompted when you run the script.

    Here is the script. Edit: See improved version by Mofi below.

    6,682583
    Grand MasterGrand Master
    6,682583

      Feb 27, 2011#2

      Using a tagged regular expression replace (in power tip with UltraEdit engine, here with Perl engine) makes the script much faster.

      Code: Select all

      if (UltraEdit.document.length > 0)
      {
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         UltraEdit.perlReOn();
         var str_title = UltraEdit.getString("What is the title for this page?",1);
         // Make sure that last line of the file has a line termination.
         UltraEdit.activeDocument.bottom();
         if (UltraEdit.activeDocument.isColNumGt(1))
         {
            UltraEdit.activeDocument.insertLine();
            if (UltraEdit.activeDocument.isColNumGt(1))
            {
               UltraEdit.activeDocument.deleteToStartOfLine();
            }
         }
         UltraEdit.activeDocument.top();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=false;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
         UltraEdit.activeDocument.findReplace.preserveCase=false;
         UltraEdit.activeDocument.findReplace.replaceAll=true;
         UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
         UltraEdit.activeDocument.findReplace.replace("^(.+)$", "<a href=\"\\1\">\\1</a><br>");
         UltraEdit.activeDocument.write("<html>\r\n<head>\r\n<title>"+str_title.trim()+"</title>\r\n</head>\r\n<body>\r\n<p>");
         UltraEdit.activeDocument.bottom();
         UltraEdit.activeDocument.findReplace.regExp=false;
         UltraEdit.activeDocument.findReplace.searchDown=false;
         UltraEdit.activeDocument.findReplace.find("<br>")
         UltraEdit.activeDocument.write("</p>\r\n</body>\r\n</html>");
         UltraEdit.activeDocument.top();
      }

      18
      Basic UserBasic User
      18

        Feb 27, 2011#3

        Neat!