-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWifiXmlToQR.user.js
126 lines (107 loc) · 3.33 KB
/
WifiXmlToQR.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//(function () {
// ==UserScript==
// @name WifiXmlToQR
// @description WifiXmlToQR
// @include https://lastpass.com/export.php?&hp=0
// @require qrcodejs/qrcode.js
// @namespace http://localhost.localdomain
// @version 1
// ==/UserScript==
//
// WiFi configuration to QR code tool
// Dual functionality:
// Either as grease monkey user script
//
// or as stand alone website.
//
function wpa_encoding_type(rawstring){
//Network types in xml are have other name in wifi object type
if(rawstring=="WPA2PSK"){
return("WPA")
}
return (rawstring);
}
// string hexstring(string)
// return hexadecimal representation of a string in a string.
//
function hexstring(rawstring){
var buffer="";
var i=0;
for(i=0; i<rawstring.length; i++){
buffer=buffer+rawstring.charCodeAt(i).toString(16);
}
return(buffer);
}
function WifiXmlToQR(){
var txt="xxx";
if (window.getSelection) {
txt = window.getSelection();
}
else if (document.getSelection) {
txt = document.getSelection();
}
else if (document.selection) {
txt = document.selection.createRange().text;
}
// Selection is an object and needs to be transformed into String before
// regexp transformations...
var txt2=txt.toString();
txt=txt2.replace(/""/g,"\"");
imagediv = document.getElementById("testcode");
if(imagediv){
imagediv.style.visibility = "hidden";
}
//alert(datastring);
datastring=WifiXmlToMeCard(txt);
genqr(datastring);
}
function WifiXmlToMeCard(txt){
// Datastring is generated here
var z=parseXml(txt);
var aa=z.getElementsByTagName("SSIDConfig")[0];
var datastring="WIFI:"
+"S:"+z.getElementsByTagName("SSIDConfig")[0].getElementsByTagName("name")[0].textContent+";"
+"P:"+(z.getElementsByTagName("security")[0].getElementsByTagName("keyMaterial")[0].textContent)+";"
+"T:"+wpa_encoding_type(z.getElementsByTagName("security")[0].getElementsByTagName("authentication")[0].textContent)+";"
;
return datastring;
}
function genqr(datastring,options){
mainDoc = top.document.body;
options=options || {};
var width = options.width || 500;
var height = options.height || 500;
var imagediv = document.getElementById("testcode");
if(! imagediv){
mainDoc.innerHTML = "<div id=outer_frame><table id=outertable border=0><tr><td><div id=testcode></div></td></tr><tr><td id=qrdatasubtitle></td></tr></table></div>" + mainDoc.innerHTML;
var myouter = document.getElementById("outer_frame");
myouter.style.position="fixed";
myouter.style.right=0;
myouter = document.getElementById("outertable");
myouter.style.border="80px solid white";
imagediv = document.getElementById("testcode");
imagediv.style.visibility = "visible";
}
document.getElementById("testcode").innerHTML="";
var oQRCode = new QRCode("testcode", {
text : datastring,
width : width,
height : height,
correctLevel : QRCode.CorrectLevel.M
})
imagediv.style.visibility = "visible";
}
//Main
//
if (typeof window.DOMParser != "undefined") {
parseXml = function(xmlStr) {
return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
};
}else{
alert("Did not find xml parser");
};
GM_registerMenuCommand("Convert wifi xml string to qr code", WifiXmlToQR, "e" );
// uncoment for debugging
// alert("All systems loaded");
// vim:ts=3
// }