1function decodeUULEstr(uuleStr) { 2 var arr = uuleStr.split('+'); 3 if (arr.length != 2) { 4 console.log('length unexpected; should be 2 elements') 5 return false; 6 } 7 var prefix = arr[0]; 8 var b64Str = arr[1]; 9 switch (prefix) { 10 case 'w': 11 return decodeUULEw(b64Str); 12 break; 13 case 'a': 14 return decodeUULEa(b64Str); 15 break; 16 default: 17 console.log('unexpected prefix'); 18 return false; 19 } 20 // this should never happen 21 return false; 22} 23 24function decodeUULEw(b64Str) { 25 // decode URIencoding 26 b64Str = decodeURIComponent(b64Str); 27 // revert urlsafe changes for base64 28 b64Str = b64Str 29 .replace(/\-/g, '+') // Convert '-' to '+' 30 .replace(/\_/g, '/'); // Convert '_' to '/' 31 // base64 decode 32 var data = base64js.toByteArray(b64Str); 33 34 // protobuffer decode and return 35 return pbUULE.decode(data); 36} 37 38function encodeUULEw(data) { 39 // protobuffer encode 40 var pbArr = pbUULE.encode(data).finish(); 41 // base64 encode 42 var b64Str = base64js.fromByteArray(pbArr); 43 // make urlsafe 44 b64Str = b64Str 45 .replace(/\+/g, '-') // Convert '+' to '-' 46 .replace(/\//g, '_'); // Convert '/' to '_' 47 // encode as URI component 48 b64Str = encodeURIComponent(b64Str); 49 // prefix with 'w+' and return 50 return 'w+'+b64Str; 51} 52 53function decodeUULEa(b64Str) { 54 // decode URIencoding 55 b64Str = decodeURIComponent(b64Str); 56 // revert urlsafe changes for base64 57 b64Str = b64Str 58 .replace(/\-/g, '+') // Convert '-' to '+' 59 .replace(/\_/g, '/'); // Convert '_' to '/' 60 // base64 decode and return 61 return atob(b64Str); 62} 63 64function encodeUULEa(txt) { 65 // base64 encode 66 var b64Str = btoa(txt); 67 // make urlsafe 68 b64Str = b64Str 69 .replace(/\+/g, '-') // Convert '+' to '-' 70 .replace(/\//g, '_'); // Convert '/' to '_' 71 // encode as URI component 72 b64Str = encodeURIComponent(b64Str); 73 // prefix with 'a+' and return 74 return 'a+'+b64Str; 75} 76 77function linkGoogleSearch(uule) { 78 var href = 'https://www.google.com/search?q=where+am+i&hl=en&gl=US&uule='+uule; 79 return href; 80} 81 82var pbUULE; 83$(document).ready(function() { 84 protobuf.load("js/uule.proto?rnd="+Math.random(), function(err, root) { 85 if (err) throw err; 86 pbUULE = root.lookupType("Uule"); 87 }); 88 89 // version 1 'w+CAIQICIâ¦' 90 $('#button-decode-uule-w').on('click', function() { 91 var uuleStr = $('#uule-w-input').val(); 92 var href = linkGoogleSearch(uuleStr); 93 $('#anchor-uule-w').attr('href', href); 94 var data = decodeUULEstr(uuleStr); 95 if (data) { 96 $('#pbCanonical').val(data.canonicalName); 97 $('#pbProducer').val(data.producer); 98 $('#pbRole').val(data.role); 99 } else { 100 console.log('something went wrong'); 101 } 102 }); 103 $('#button-encode-uule-w').on('click', function() { 104 var data = { 105 role: $('#pbRole').val(), 106 producer: $('#pbProducer').val(), 107 canonicalName: $('#pbCanonical').val() 108 } 109 var b64Str = encodeUULEw(data); 110 $('#uule-w-input').val(b64Str); 111 var href = linkGoogleSearch(b64Str); 112 $('#anchor-uule-w').attr('href', href); 113 }); 114 115 // version 2 'a+CAIQICIâ¦' 116 $('#button-decode-uule-a').on('click', function() { 117 var uuleStr = $('#uule-a-input').val(); 118 var b64Str = decodeUULEstr(uuleStr); 119 if (b64Str) { 120 $('#uule-a-output').val(b64Str); 121 var href = linkGoogleSearch(uuleStr); 122 $('#anchor-uule-a').attr('href', href); 123 } else { 124 console.log('something went wrong'); 125 } 126 }); 127 $('#button-encode-uule-a').on('click', function() { 128 var txt = $('#uule-a-output').val(); 129 var b64Str = encodeUULEa(txt); 130 $('#uule-a-input').val(b64Str); 131 132 var href = linkGoogleSearch(b64Str); 133 $('#anchor-uule-a').attr('href', href); 134 }); 135});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.