Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created January 30, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/f97629fe1d29c8be51a1c39d66761c01 to your computer and use it in GitHub Desktop.
Save gioxx/f97629fe1d29c8be51a1c39d66761c01 to your computer and use it in GitHub Desktop.
Il codice utilizzato per trasformare l'esportazione dei filtri del mio Firefox (con a bordo AdBlock Plus) in lista disponibile per tutti.
' ABP X FILES Stable Maker 0.3 rev1
' GSolone - Ultima modifica: 09/01/17
'
' Lo script modifica la lista filtri esportata dall'Adblock Plus di Staging e la modifica per inserire le informazioni di rilascio, quindi la copia all'interno della cartella pubblica di Dropbox dove tutti i client puntano per l'aggiornamento.
'
' STORICO MODIFICHE
' 0.3 rev1- ho aggiunto un riferimento allo spazio hosting GitHub (per far notare all'utente che sta utilizzando il giusto repository). Aggiornato anche versione di Adblock richiesta (2.8).
' 0.3 - ho modificato la posizione del file di lista (si passa su Github!).
' 0.2 rev0- corregge il bug sullo sdoppiamento dei contenuti (Remove Empty Lines usava una variabile già piena e replicava ogni riga)
' 0.1 rev0- stadio iniziale di sviluppo.
'
' Sviluppo: Giovanni F. -Gioxx- Solone (dev@gfsolone.com)
' Testato su: Windows 7 Pro Sp1
'
' Non toccare nulla oltre questa riga!
' DO NOT touch anything below this line!
' Variables and constants definition
Dim i, objFile, objFSO, strFile, strMsg
Dim objWMIService, objProcess, colProcess
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Date and time
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
dtmLocalTime = objItem.LocalDateTime
dtmMonth = Mid(dtmLocalTime, 5, 2)
dtmDay = Mid(dtmLocalTime, 7, 2)
dtmYear = Left(dtmLocalTime, 4)
dtmHour = Mid(dtmLocalTime, 9, 2)
dtmMinutes = Mid(dtmLocalTime, 11, 2)
dtmSeconds = Mid(dtmLocalTime, 13, 2)
Next
update = dtmYear & dtmMonth & dtmDay & dtmHour & dtmMinutes
lastmodified = dtmDay & "-" & dtmMonth & "-" & dtmYear
' DEBUG: show $datetime
'Wscript.Echo update
' Expand Environment
' Create const's to spare time and place
Dim WshS
Set WshS = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")
strFile = usrProfile & "\Desktop\filtri.txt"
' DEBUG: Message to prove my string contains the path to my profile
'cartellaProfilo = usrProfile
'Msgbox strFile, 0, "Percorso lista"
' Staging filtri.txt is on my Desktop?
If objFSO.FileExists(strFile) Then
Else
MsgBox "Non ho trovato il file filtri.txt sul Desktop. Lo hai esportato da Firefox?",16,""
Wscript.Quit
End If
' Remove line 1 to 2, default header of Adblock Plus export
For i = 1 To 2
DeleteLine strFile, "", 1, 0
Next
' Add list header (ABP X Files Stable)
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
strContents = objFile.ReadAll
objFile.Close
strFirstLine = "[Adblock Plus 2.8]" & vbCrLf & "! Version: " & update & vbCrLf & "! Title: ABP X Files" & vbCrLf & "! X Files migliora la tua navigazione quotidiana!" & vbCrLf & "! Last modified: " & lastmodified & vbCrLf & "! Expires: 3 days" & vbCrLf & "! Homepage: http://noads.it" & vbCrLf & "! Home: http://noads.it" & vbCrLf & "! Blog: http://gioxx.org/tag/x-files" & vbCrLf & "! Hosting lista: GitHub.com" & vbCrLf & "! "
strNewContents = strFirstLine & vbCrLf & strContents
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
'objFile.WriteLine strNewContents
objFile.Write strNewContents
objFile.Close
' Remove empty lines at the end of file!
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strCleaned = strCleaned & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
objFile.Write strCleaned
objFile.Close
' Move updated X Files to Dropbox (and overwrite old file)
' (from %UserProfile%\Desktop\filtri.txt to C:\GitHub\xfiles\filtri.txt)
strDropbox = "C:\GitHub\xfiles\"
'Nuova posizione dal 12/2016, era strDropbox = "C:\Dropbox\Public\abpxfiles\"
If objFSO.FileExists(strFile) Then
objFSO.CopyFile strFile, strDropbox, True
Else
MsgBox "Non sono riuscito a muovere il file dei filtri. Verifica che i puntamenti siano corretti",48,""
End If
' Open the file (verification process) and delete "Staging X Files"
strDropboxFile = "C:\GitHub\xfiles\filtri.txt"
'Nuova posizione dal 12/2016, era strDropboxFile = "C:\Dropbox\Public\abpxfiles\filtri.txt"
CreateObject("WScript.Shell").Run strDropboxFile
objFSO.DeleteFile strFile, True
Sub Run(ByVal sFile)
' Variables definition
Dim shell
Set shell = CreateObject( "WScript.Shell" )
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub
Sub DeleteLine(strFile, strKey, LineNumber, CheckCase)
'Use strFile = "c:\file.txt" (Full path to text file)
'Use strKey = "John Doe" (Lines containing this text string to be deleted)
'Use strKey = "" (To not use keyword search)
'Use LineNumber = "1" (Enter specific line number to delete)
'Use LineNumber = "0" (To ignore line numbers)
'Use CheckCase = "1" (For case sensitive search )
'Use CheckCase = "0" (To ignore upper/lower case characters)
Const ForReading=1:Const ForWriting=2
Dim objFSO,objFile,Count,strLine,strLineCase,strNewFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(strFile,ForReading)
Do Until objFile.AtEndOfStream
strLine=objFile.Readline
If CheckCase=0 then strLineCase=ucase(strLine):strKey=ucase(strKey)
If LineNumber=objFile.Line-1 or LineNumber=0 then
If instr(strLine,strKey) or instr(strLineCase,strkey) or strKey="" then
strNewFile=strNewFile
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Else
strNewFile=strNewFile&strLine&vbcrlf
End If
Loop
objFile.Close
Set objFile=objFSO.OpenTextFile(strFile,ForWriting)
objFile.Write strNewFile
objFile.Close
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment