Putting anchor points in a text file

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
Basically i have a 500 line javascript file i made that runs in grease monkey (a add on for firefox ) I'm using vb.net to "compile" this script depending on certain check boxes.

So for example. (this is part of my script)

VB.NET:
#RegionCapsEnforcer

var array=document.evaluate("//*[contains(@class, 'postbody')]", document, null, 6, null);
for(let i=0,item; (item=array.snapshotItem(i)); i++) item.innerHTML=item.innerHTML.toLowerCase()

#RegionRevealURLs

var postAs = document.querySelectorAll('.postbody a')
for(var i in postAs){
    var c = postAs[i];
    if(c.hasAttribute('href')){
        var np = document.createElement('p');
        np.innerHTML=c.getAttribute('href');
        var p = c.parentNode;
        var pl = c.nextElementSibling;
        if(!pl){
            p.appendChild(np);
        }
        else{
            p.insertBefore(np, pl);
        }
    }
}

and so on. So if chkCapsEnforcer was not checked it would skip that part and go to chkRevealUrl and if that was checked would get that bit. Then once it has gone through all the checkboxes it would write the enabled bits to a text file.

make sense?
 
The thread title suggest you want to insert "anchors", but the post content indicates you want to retrieve them. Perhaps you can clarify?
 
Sorry for the title. I didnt know how else to explain it.

If you look at this form below. You will see there are a few options.

2weceua.jpg


Each of them chkboxes has a anchor (thats just what im calling it) in my script.

I have a compile button now depending on what checkboxes are selected i want to be able to read each section of the script (if its checkbox is checked)

Grab the bits that i selected and write them to a new textfile. Sort of like compiling a script. Does that make any more sense?
 
The logic could be something like this:
VB.NET:
Dim includeLine As Boolean
Dim newLines As New List(Of String)
For Each line As String In lines
    If line.StartsWith("#") Then
        includeLine = CType(Me.Controls(line.Substring(1)), CheckBox).Checked
    ElseIf includeLine Then
        newLines.Add(line)
    End If
Next
You can for example read/write all lines with File.ReadAllLines Method (String) (System.IO) and the corresponding WriteAllLines.
 
Back
Top