The Un-Official Proxomitron Forum

Full Version: Select code button for CODE/PRE blocks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Not sure how to present this but here goes.

These two filters combined will add a SELECT CODE button to any PRE or CODE tags in can find on a page, this is useful when a forum does not provide a "select code" function out of the box, like this forum for example. It helps you select the code quickly. As a bonus it wraps CODE and PRE tags in a table so you can press left-ctrl + mousebutton to select the code in Gecko based browsers (Firefox). It doesn't copy the code the clipboard as I prefer to do that myself Wink

Step 1 - create a block list, add urls for website you want to use these filters on here - one per line say prxbx.com
Code:
List.CodeList = "..\Lists\CodeList.txt"

Step 2 - add these two filters
Code:
Name = "Forum CodeList JS"
Active = TRUE
URL = "$LST(CodeList)"
Limit = 4096
Match = "</head>"
Replace = "<script type="text/javascript">"
          "    function selectElementContents(el) {"
          "        var body = document.body, range, sel;"
          "        if (document.createRange && window.getSelection) {"
          "            range = document.createRange();"
          "            sel = window.getSelection();"
          "            sel.removeAllRanges();"
          "            try {"
          "                range.selectNodeContents(el);"
          "                sel.addRange(range);"
          "            } catch (e) {"
          "                range.selectNode(el);"
          "                sel.addRange(range);"
          "            }"
          "        } else if (body.createTextRange) {"
          "            range = body.createTextRange();"
          "            range.moveToElementText(el);"
          "            range.select();"
          "        }"
          "    }"
          "</script>"
          "</head>"

Name = "Forum CodeList Select Button"
Active = TRUE
URL = "$LST(CodeList)"
Limit = 4096
Match = "<(pre|code)\2\1/(pre|code)>"
        "$TST(($GET(PreIdC)+)=$LST(Count)|*)$SET(PreIdC=$GET(i))"
Replace = "<input type="button" value="select code" onclickfoofoo="selectElementContents( document.getElementById('pre$GET(PreIdC)') );">"
          "<table border="0" id="pre$GET(PreIdC)"><tr><td><\2\1/\2></td></tr></table>"

If you wish you could move the JS code to a JS file and load it that way. Not sure where I found that code, I think it comes from JQuery but could be mistaken.

Many thanks to JJoe for helping to figure out how to use LST Count - see here http://prxbx.com/forums/showthread.php?tid=2069
Reference URL's