Convertisort

De Prima-jdr Wiki
Aller à : navigation, rechercher

Convertisort est un script script vbs qui converti le texte copié du .pdf du Livre du Joueur dans le presse-papier pour qu'il puisse être intégrer dans le Wiki.

il suffit de copier le sort depuis le .pdf, de lancer le script et de coller directement sur le Wiki.

Il faut juste modifier le code pour changer l'élément.

Script[modifier]

'Element du sort :
Const ELEMENT = "Air"

'Lecture depuis le presse-papier :
Set Clipboard = CreateObject("htmlfile")
X = Clipboard.ParentWindow.ClipboardData.GetData("text")
Set Clipboard = nothing

'Création d'un fichier texte de sortie :
Set fso = CreateObject("scripting.FileSystemObject")
Set output = fso.CreateTextFile("output.txt", True)
output_path = mid(WScript.ScriptFullName, 1, len(WScript.ScriptFullName) - len(WScript.ScriptName)) & "output.txt"
Set fso = nothing

'Déclaration des mots clés qui vont servir de balises :
Dim KeyWord(7)
KeyWord(0) = "Temps d'incantation-"
KeyWord(1) = "Portée-"
KeyWord(2) = "Durée-"
KeyWord(3) = "Zone-"
KeyWord(4) = "Effet-"
KeyWord(5) = "Spécial-"
KeyWord(6) = "Utilisation alternative-"

'Création de la chaine de sortie :
output.write "{{DISPLAYTITLE:<span>" & ELEMENT & " : {{PAGENAME}} -Coût " & getStr("-Coût ", " cL", X) & " cL</span>}}" & vbcrlf
For i = 0 to 6
	For j = i+1 to 6
		A = "-"
		debut = KeyWord(i)
		fin = KeyWord(j)

		if i >= 4 then
			A = vbCrLf
			if j >= 6 then
				fin = vbNullString
			end if
		end if
	Y = getStr(debut, fin, X)
	Y = Replace(Y, "    ", " ")
	Y = Replace(Y, "   ", " ")
	Y = Replace(Y, "  ", " ")

	if Y <> "" then
		output.write "*" & mid(KeyWord(i), 1, len(KeyWord(i)) - 1) & A & Y
		exit for
	end if
	Next
Next
output.write vbcrlf & "[[Catégorie:Sorts " & ELEMENT & "]]" & vbcrlf & "[[Catégorie:Livre du Joueur]]"
output.close

'Ecriture dans le presse-papier :
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c clip < " & output_path, 0, TRUE
Set WshShell = nothing

'Fonction permettant de récupérer le texte entre deux balises :
Function getStr(strStart, strEnd, text)
	posStart = inStr(text, strStart)
	lenStart = len(strStart)
	posEnd = inStr(text, strEnd)
	lenGet = posEnd - posStart - lenStart
	if posStart = 0 then
		ret = ""
	elseIf posEnd = 0 then
		ret = ""
	elseIf lenGet < 0 then
		ret = mid(text, posStart + lenStart)
	else
		ret = mid(text, posStart + lenStart, lenGet)
	end if
	getStr = ret
End Function