I am creating a web site using the Amadeus Web Service. I have created a SOAP and tested by using SOAP UI. And I got the complete response. After that I tried to get response in web browser. Then I created a below files. But, when I input all the data and clicks the Search button, it gives me these 2 errors -
OPTIONS https://noded1.test.webservices.amadeus.com/XXXXX 500
(Other Error) Failed to load
https://noded1.test.webservices.amadeus.com/XXXXX: Response for
preflight has invalid HTTP status code 500.
How can I Fix these errors ??
Here is the PHP file.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="http://www.timestampgenerator.com/js/common.js"></script>
</head>
<body>
<form class="form-horizontal" method="POST" action="#" enctype="multipart/form-data" id="signupForm">
<div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
Message Id : <input class="form-control" id="messageid" type="text" placeholder="Results will be placed here..." readonly size="40"/> <br>
</div>
<div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
Nonce : <input class="form-control" id="nonceshow" type="text"/> <br>
</div>
<div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
Timestamp : <input class="form-control" type="text" name="timestampama" id="timestampama"/> <br>
</div>
<div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
Text : <input type="text" class="form-control" name="strex" id="strex" size="20" /> <br>
</div>
<div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
SHA-1 : <input type="text" class="form-control" name="strcrypt" id="strcrypt" size="33" /> <br>
</div>
Search
<p id="errorModal"></p> <br>
<div id="ghapidata" class="clearfix"></div>
</form>
<p id="body"></p>
<script type="text/javascript">
//Main Function
$(document).ready(function () {
$.getScript("PwJs.js", function () {
});
$('#ghsubmitbtn').on('click', function(e) {
var country = $('#country').val();
var year = $('#year').val();
var month = $('#month').val();
var messageid = guid();
//var nonce = nonceid();
//var nonceremove = nonce.slice(0, -4); //Remove last 4 characters
//var n = nonceremove.length; //Length
var pw = 'SSSSSS';
var str = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://xml.amadeus.com/2010/06/Security_v1" xmlns:typ="http://xml.amadeus.com/2010/06/Types_v1" xmlns:iat="http://www.iata.org/IATA/2007/00/IATA2010.1" xmlns:app="http://xml.amadeus.com/2010/06/AppMdw_CommonTypes_v3" xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1" xmlns:ses="http://xml.amadeus.com/2010/06/Session_v3" xmlns:fmp="http://xml.amadeus.com/FMPTBQ_14_3_1A">' +
'<soapenv:Header>' +
'<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">' + messageid + '</add:MessageID>' +
'<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/ZZZZZ</add:Action>' +
'<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://nodeD1.test.webservices.amadeus.com/XXXXXX</add:To>' +
'<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>' +
'<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' +
'<oas:UsernameToken oas1:Id="UsernameToken-1" xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">' +
'<oas:Username>WSEOLMTT</oas:Username>' +
'<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">' + noncemove + '</oas:Nonce>' +
'<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">' + hashedPw + '</oas:Password>' +
'<oas1:Created>' + timestampama + '</oas1:Created>' +
'</oas:UsernameToken>' +
'</oas:Security>' +
'<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">' +
'<UserID AgentDutyCode="SU" POS_Type="1" PseudoCityCode="CMBI228AJ" RequestorType="U"/>' +
'</AMA_SecurityHostedUser>' +
'</soapenv:Header>' +
'<soapenv:Body>' +
'<Fare_MasterPricerTravelBoardSearch>' +
'<numberOfUnit xmlns="http://xml.amadeus.com/FMPTBQ_14_3_1A">' +
'<unitNumberDetail>' +
'<numberOfUnits>1</numberOfUnits>' +
'<typeOfUnit>PX</typeOfUnit>' +
'</unitNumberDetail>' +
'<unitNumberDetail>' +
'<numberOfUnits>250</numberOfUnits>' +
'<typeOfUnit>RC</typeOfUnit>' +
'</unitNumberDetail>' +
'</numberOfUnit>' +
'<paxReference>' +
'<ptc>ADT</ptc>' +
'<traveller>' +
'<ref>1</ref>' +
'</traveller>' +
'</paxReference>' +
'<fareOptions>' +
'<pricingTickInfo>' +
'<pricingTicketing>' +
'<priceType>ET</priceType>' +
'<priceType>TAC</priceType>' +
'<priceType>RP</priceType>' +
'</pricingTicketing>' +
'</pricingTickInfo>' +
'</fareOptions>' +
'<itinerary>' +
'<requestedSegmentRef>' +
'<segRef>1</segRef>' +
'</requestedSegmentRef>' +
'<departureLocalization>' +
'<departurePoint>' +
'<locationId>DEL</locationId>' +
'</departurePoint>' +
'</departureLocalization>' +
'<arrivalLocalization>' +
'<arrivalPointDetails>' +
'<locationId>BOM</locationId>' +
'</arrivalPointDetails>' +
'</arrivalLocalization>' +
'<timeDetails>' +
'<firstDateTimeDetail>' +
'<date>161018</date>' +
'</firstDateTimeDetail>' +
'</timeDetails>' +
'<flightInfo>' +
'<cabinId>' +
'<cabin>Y</cabin>' +
'</cabinId>' +
'</flightInfo>' +
'</itinerary>' +
'</Fare_MasterPricerTravelBoardSearch>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
//console.log(departureDate);
$.ajax({
url: 'https://nodeD1.test.webservices.amadeus.com/XXXXXX',
method: 'POST',
contentType:"text/xml; charset=utf-8",
data: str,
//headers: {"Authorization": 'Bearer ' + bat},
beforeSend: function (xhr) {
xhr.setRequestHeader('SOAPAction', 'http://webservices.amadeus.com/ZZZZZ');
},
success: function (data) {
console.log(data);
}
});
});
});
</script>
</body>
</html>
Here is the JavaScript File.
//Nonce
function nonceid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var n = 0; n < 12; n++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return btoa(text).slice(0, -4);
}
var n = nonceid().length; //Length
var noncemove = nonceid();
console.log("Nonce - " +noncemove);
console.log("Nonce Characters - " +n);
document.getElementById('ghsubmitbtn').addEventListener('click', function() {
document.getElementById('nonceshow').value = nonceid();
})
//Timestamp
var timestampama = new Date().toISOString();
console.log("Timestamp - " +timestampama);
console.log(new Date());
document.getElementById('ghsubmitbtn').addEventListener('click', function() {
document.getElementById('timestampama').value = timestampama;
})
//register onclick events for Encrypt button
document.getElementById('ghsubmitbtn').addEventListener('click', function() {
document.getElementById('strcrypt').value = completepw;
})
/* document.getElementById('ghsubmitbtn').onclick = function() {
var txt_string = document.getElementById('strex').value; // gets data from input text
//encrypts data and adds it in #strcrypt element
document.getElementById('strcrypt').value = completepw;
console.log("SHA1 - " +SHA1(txt_string));
return false;
} */
//SHA1
function rotate_left(n,s) {
var t4 = ( n<<s ) | (n>>>(32-s));
return t4;
}
function lsb_hex(val) {
var str="";
var i;
var vh;
var vl;
for( i=0; i<=6; i+=2 ) {
vh = (val>>>(i*4+4))&0x0f;
vl = (val>>>(i*4))&0x0f;
str += vh.toString(16) + vl.toString(16);
}
return str;
}
function cvt_hex(val) {
var str="";
var i;
var v;
for( i=7; i>=0; i-- ) {
v = (val>>>(i*4))&0x0f;
str += v.toString(16);
}
return str;
}
function SHA1 (msg) {
function Utf8Encode(string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
var blockstart;
var i, j;
var W = new Array(80);
var H0 = 0x67452301;
var H1 = 0xEFCDAB89;
var H2 = 0x98BADCFE;
var H3 = 0x10325476;
var H4 = 0xC3D2E1F0;
var A, B, C, D, E;
var temp;
msg = Utf8Encode(msg);
var msg_len = msg.length;
var word_array = new Array();
for( i=0; i<msg_len-3; i+=4 ) {
j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
word_array.push( j );
}
switch( msg_len% 4 ) {
case 0:
i = 0x080000000;
break;
case 1:
i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
break;
case 2:
i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
break;
case 3:
i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
break;
}
word_array.push( i );
while( (word_array.length% 16)!= 14 ) word_array.push( 0 );
word_array.push( msg_len>>>29 );
word_array.push( (msg_len<<3)&0x0ffffffff );
for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
A = H0;
B = H1;
C = H2;
D = H3;
E = H4;
for( i= 0; i<=19; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=20; i<=39; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=40; i<=59; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=60; i<=79; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
H0 = (H0 + A) & 0x0ffffffff;
H1 = (H1 + B) & 0x0ffffffff;
H2 = (H2 + C) & 0x0ffffffff;
H3 = (H3 + D) & 0x0ffffffff;
H4 = (H4 + E) & 0x0ffffffff;
}
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toUpperCase();
}
function SHA1Bytes (msg) {
var blockstart;
var i, j;
var W = new Array(80);
var H0 = 0x67452301;
var H1 = 0xEFCDAB89;
var H2 = 0x98BADCFE;
var H3 = 0x10325476;
var H4 = 0xC3D2E1F0;
var A, B, C, D, E;
var temp;
var msg_len = msg.length;
var word_array = new Array();
for( i=0; i<msg_len-3; i+=4 ) {
if (msg[i] > 255 || msg[i+1] > 255 || msg[i+2] > 255 || msg[i+3] > 255) alert('Not a byte!');
j = msg[i]<<24 | msg[i+1]<<16 |
msg[i+2]<<8 | msg[i+3];
word_array.push( j );
}
switch( msg_len% 4 ) {
case 0:
i = 0x080000000;
break;
case 1:
i = msg[msg_len-1]<<24 | 0x0800000;
break;
case 2:
i = msg[msg_len-2]<<24 | msg[msg_len-1]<<16 | 0x08000;
break;
case 3:
i = msg[msg_len-3]<<24 | msg[msg_len-2]<<16 | msg[msg_len-1]<<8 | 0x80;
break;
}
word_array.push( i );
while( (word_array.length% 16)!= 14 ) word_array.push( 0 );
word_array.push( msg_len>>>29 );
word_array.push( (msg_len<<3)&0x0ffffffff );
for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
A = H0;
B = H1;
C = H2;
D = H3;
E = H4;
for( i= 0; i<=19; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=20; i<=39; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=40; i<=59; i++ ) {
temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
for( i=60; i<=79; i++ ) {
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B,30);
B = A;
A = temp;
}
H0 = (H0 + A) & 0x0ffffffff;
H1 = (H1 + B) & 0x0ffffffff;
H2 = (H2 + C) & 0x0ffffffff;
H3 = (H3 + D) & 0x0ffffffff;
H4 = (H4 + E) & 0x0ffffffff;
}
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toUpperCase();
}
var gHexa = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64Bytes(input) {
var output = '';
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input[i++];
chr2 = input[i++];
chr3 = input[i++];
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
}
return output;
}
function parseHexaBytes(iText) {
var aResult = [];
for (var i=0; i < iText.length; i = i+2)
{
var aValue = parseInt(iText.substr(i, 2), 16);
//if (aValue > 255) alert('Too large!');
//if (aValue == 0) alert('Null value!');
aResult.push(aValue);
}
return aResult;
}
function stringToArray(iText) {
var aResult = [];
for (var i=0; i < iText.length; i = i+1)
{
aResult.push(iText.charCodeAt(i));
}
return aResult;
}
var pw = 'SSSSS';
var clearpw = 'AAAAA';
//Verify SHA1
var noncee = 'WnMwUUlVSkQ=';
var timestampamae = '2018-08-28T09:24:10:030Z';
var pwe = '123';
var shapwe = noncee+ ' + ' +timestampamae+ ' + ' +pwe; //5 + 6 + 123
// Base64 ( SHA-1 ( nonce + created + SHA-1 ( password ) ) )
var shapw = noncemove+ ' + ' +timestampama+ ' + ' +pw;
console.log("SHA1 Pw - " +SHA1(shapw));
console.log("SHA1Bytes Pw - " +SHA1Bytes(shapwe));
var completepw = btoa(SHA1(shapw));
console.log("Comple Pw - " +completepw);
var completepwWithAma = btoa(encode64Bytes(shapwe));
console.log("Complete Pws Ama Code - " +completepwWithAma);
function WbsPassword(clearpw,timestampama,noncemove) {
var aPwd = parseHexaBytes(SHA1(clearpw));
var aNonce = decode64Bytes(noncemove);
var aTime = stringToArray(timestampama);
var aHash = SHA1Bytes(aNonce.concat(aTime.concat(aPwd)));
var HshPwd = encode64Bytes(parseHexaBytes(aHash));
return HshPwd;
}
var hashedPw = WbsPassword(clearpw,timestampama,noncemove);
console.log(WbsPassword("WbsPassword - " +clearpw,timestampama,noncemove));
console.log("hashedPw - " +hashedPw);
Related
I'm so lost.
I keep getting this error:
"SAVED SCREEN NETWORK ERROR: , [SyntaxError: JSON Parse error: Unrecognized token '<']
at node_modules/color-string/index.js:90:16 in cs.get.rgb" (Line 90 is right below my console.log in the code down below)
This part:
console.log(match)
if (match[4]) {
if (match[5]) {
rgb[3] = parseFloat(match[4]) * 0.01;
} else {
rgb[3] = parseFloat(match[4]);
}
}
} else if (match = string.match(per)) {
for (i = 0; i < 3; i++) {
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
}
But when I check the node_modules, I can't understand at all where its even using JSON. I console logged the match and all I'm getting is this:
Array [
"rgb(28, 28, 30)",
"28",
"28",
"30",
undefined,
undefined,
]
I literally don't know what to do anymore, so I'm hoping someone more experienced can help me out on this.
/* MIT license */
var colorNames = require('color-name');
var swizzle = require('simple-swizzle');
var hasOwnProperty = Object.hasOwnProperty;
var reverseNames = {};
// create a list of reverse color names
for (var name in colorNames) {
if (hasOwnProperty.call(colorNames, name)) {
reverseNames[colorNames[name]] = name;
}
}
var cs = module.exports = {
to: {},
get: {}
};
cs.get = function (string) {
var prefix = string.substring(0, 3).toLowerCase();
var val;
var model;
switch (prefix) {
case 'hsl':
val = cs.get.hsl(string);
model = 'hsl';
break;
case 'hwb':
val = cs.get.hwb(string);
model = 'hwb';
break;
default:
val = cs.get.rgb(string);
model = 'rgb';
break;
}
if (!val) {
return null;
}
return {model: model, value: val};
};
cs.get.rgb = function (string) {
if (!string) {
return null;
}
var abbr = /^#([a-f0-9]{3,4})$/i;
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
var keyword = /^(\w+)$/;
var rgb = [0, 0, 0, 1];
var match;
var i;
var hexAlpha;
if (match = string.match(hex)) {
hexAlpha = match[2];
match = match[1];
for (i = 0; i < 3; i++) {
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
var i2 = i * 2;
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
}
if (hexAlpha) {
rgb[3] = parseInt(hexAlpha, 16) / 255;
}
} else if (match = string.match(abbr)) {
match = match[1];
hexAlpha = match[3];
for (i = 0; i < 3; i++) {
rgb[i] = parseInt(match[i] + match[i], 16);
}
if (hexAlpha) {
rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
}
} else if (match = string.match(rgba)) {
for (i = 0; i < 3; i++) {
rgb[i] = parseInt(match[i + 1], 0);
}
console.log(match)
if (match[4]) {
if (match[5]) {
rgb[3] = parseFloat(match[4]) * 0.01;
} else {
rgb[3] = parseFloat(match[4]);
}
}
} else if (match = string.match(per)) {
for (i = 0; i < 3; i++) {
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
}
if (match[4]) {
if (match[5]) {
rgb[3] = parseFloat(match[4]) * 0.01;
} else {
rgb[3] = parseFloat(match[4]);
}
}
} else if (match = string.match(keyword)) {
if (match[1] === 'transparent') {
return [0, 0, 0, 0];
}
if (!hasOwnProperty.call(colorNames, match[1])) {
return null;
}
rgb = colorNames[match[1]];
rgb[3] = 1;
return rgb;
} else {
return null;
}
for (i = 0; i < 3; i++) {
rgb[i] = clamp(rgb[i], 0, 255);
}
rgb[3] = clamp(rgb[3], 0, 1);
return rgb;
};
cs.get.hsl = function (string) {
if (!string) {
return null;
}
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
var match = string.match(hsl);
if (match) {
var alpha = parseFloat(match[4]);
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
var s = clamp(parseFloat(match[2]), 0, 100);
var l = clamp(parseFloat(match[3]), 0, 100);
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
return [h, s, l, a];
}
return null;
};
cs.get.hwb = function (string) {
if (!string) {
return null;
}
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
var match = string.match(hwb);
if (match) {
var alpha = parseFloat(match[4]);
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
var w = clamp(parseFloat(match[2]), 0, 100);
var b = clamp(parseFloat(match[3]), 0, 100);
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
return [h, w, b, a];
}
return null;
};
cs.to.hex = function () {
var rgba = swizzle(arguments);
return (
'#' +
hexDouble(rgba[0]) +
hexDouble(rgba[1]) +
hexDouble(rgba[2]) +
(rgba[3] < 1
? (hexDouble(Math.round(rgba[3] * 255)))
: '')
);
};
cs.to.rgb = function () {
var rgba = swizzle(arguments);
return rgba.length < 4 || rgba[3] === 1
? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
: 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
};
cs.to.rgb.percent = function () {
var rgba = swizzle(arguments);
var r = Math.round(rgba[0] / 255 * 100);
var g = Math.round(rgba[1] / 255 * 100);
var b = Math.round(rgba[2] / 255 * 100);
return rgba.length < 4 || rgba[3] === 1
? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
: 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
};
cs.to.hsl = function () {
var hsla = swizzle(arguments);
return hsla.length < 4 || hsla[3] === 1
? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
: 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
};
// hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
// (hwb have alpha optional & 1 is default value)
cs.to.hwb = function () {
var hwba = swizzle(arguments);
var a = '';
if (hwba.length >= 4 && hwba[3] !== 1) {
a = ', ' + hwba[3];
}
return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
};
cs.to.keyword = function (rgb) {
return reverseNames[rgb.slice(0, 3)];
};
// helpers
function clamp(num, min, max) {
return Math.min(Math.max(min, num), max);
}
function hexDouble(num) {
var str = Math.round(num).toString(16).toUpperCase();
return (str.length < 2) ? '0' + str : str;
}
I am using this script on a blogger blog but since my posts are more than 150 it shows only the first 150. Can I change that?
<div class='pagenavi'>
<script type='text/javascript'>
var pageNaviConf = {
perPage: 10,
numPages: 9,
firstText: "First",
lastText: "Last",
nextText: "Next",
prevText: "Prev"
}
</script>
<script type='text/javascript'>
//<![CDATA[
function pageNavi(o) {
var m = location.href,
l = m.indexOf("/search/label/") != -1,
a = l ? m.substr(m.indexOf("/search/label/") + 14, m.length) : "";
a = a.indexOf("?") != -1 ? a.substr(0, a.indexOf("?")) : a;
var g = l ? "/search/label/" + a + "?updated-max=" : "/search?updated-max=",
k = o.feed.entry.length,
e = Math.ceil(k / pageNaviConf.perPage);
if (e <= 1) {
return
}
var n = 1,
h = [""];
l ? h.push("/search/label/" + a + "?max-results=" + pageNaviConf.perPage) : h.push("/?max-results=" + pageNaviConf.perPage);
for (var d = 2; d <= e; d++) {
var c = (d - 1) * pageNaviConf.perPage - 1,
b = o.feed.entry[c].published.$t,
f = b.substring(0, 19) + b.substring(23, 29);
f = encodeURIComponent(f);
if (m.indexOf(f) != -1) {
n = d
}
h.push(g + f + "&max-results=" + pageNaviConf.perPage)
}
pageNavi.show(h, n, e)
}
pageNavi.show = function(f, e, a) {
var d = Math.floor((pageNaviConf.numPages - 1) / 2),
g = pageNaviConf.numPages - 1 - d,
c = e - d;
if (c <= 0) {
c = 1
}
endPage = e + g;
if ((endPage - c) < pageNaviConf.numPages) {
endPage = c + pageNaviConf.numPages - 1
}
if (endPage > a) {
endPage = a;
c = a - pageNaviConf.numPages + 1
}
if (c <= 0) {
c = 1
}
var b = '<span class="pages">Pages ' + e + ' of ' + a + "</span> ";
if (c > 1) {
b += '' + pageNaviConf.firstText + ""
}
if (e > 1) {
b += '' + pageNaviConf.prevText + ""
}
for (i = c; i <= endPage; ++i) {
if (i == e) {
b += '<span class="current">' + i + "</span>"
} else {
b += '' + i + ""
}
}
if (e < a) {
b += '' + pageNaviConf.nextText + ""
}
if (endPage < a) {
b += '' + pageNaviConf.lastText + ""
}
document.write(b)
};
(function() {
var b = location.href;
if (b.indexOf("?q=") != -1 || b.indexOf(".html") != -1) {
return
}
var d = b.indexOf("/search/label/") + 14;
if (d != 13) {
var c = b.indexOf("?"),
a = (c == -1) ? b.substring(d) : b.substring(d, c);
document.write('<script type="text/javascript" src="/feeds/posts/summary/-/' + a + '?alt=json-in-script&callback=pageNavi&max-results=9999"><\/script>')
} else {
document.write('<script type="text/javascript" src="/feeds/posts/summary?alt=json-in-script&callback=pageNavi&max-results=9999"><\/script>')
}
})();
//]]>
</script>
Below is my code, when I try to convert 23, it converted to عشرين تلاته, but I want it converted to ثلاثة وعشرون وهكذا.
var th = ['', 'ألف', 'مليون', 'مليار', 'تريليون'];
var dg = ['صفر', 'واحد', 'اثنين', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'سبعة', 'ثمانية', 'تسعة'];
var tn = ['عشرة', 'أحد عشر', 'اثني عشر', 'ثلاثة عشر', 'أربعة عشر', 'خمسة عشر', 'ستة عشر', 'سبعة عشر', 'ثمانية عشر', 'تسعة عشر'];
var tw = ['عشرون', 'ثلاثون', 'الأربعين', 'خمسين', 'ستين', 'السبعين', 'ثمانين', 'تسعين'];
function toWords(s) {
s = s.toString();
s = s.replace(/[\, ]/g, '');
if (s != parseFloat(s)) return 'لیس عدد';
var x = s.indexOf('.');
if (x == -1) x = s.length;
if (x > 15) return 'كبير جدا';
var n = s.split('');
var str = '';
var sk = 0;
for (var i = 0; i < x; i++) {
if ((x - i) % 3 == 2) {
if (n[i] == '1') {
str += tn[Number(n[i + 1])] + ' ';
i++;
sk = 1;
} else if (n[i] != 0) {
str += tw[n[i] - 2] + ' ';
sk = 1;
}
} else if (n[i] != 0) {
str += dg[n[i]] + ' ';
if ((x - i) % 3 == 0) str += 'مائة ';
sk = 1;
}
if ((x - i) % 3 == 1) {
if (sk) str += th[(x - i - 1) / 3] + ' ';
sk = 0;
}
}
if (x != s.length) {
var y = s.length;
str += 'نقطة ';
for (var i = x + 1; i < y; i++) str += dg[n[i]] + ' ';
}
return str.replace(/\s+/g, ' ');
}
console.log(toWords(23))
var th = ['', 'ألف', 'مليون', 'مليار', 'تريليون'];
var dg = ['صفر', 'واحد', 'اثنين', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'سبعة', 'ثمانية', 'تسعة'];
var tn = ['عشرة', 'أحد عشر', 'اثني عشر', 'ثلاثة عشر', 'أربعة عشر', 'خمسة عشر', 'ستة عشر', 'سبعة عشر', 'ثمانية عشر', 'تسعة عشر'];
var tw = ['عشرون', 'ثلاثون', 'الأربعين', 'خمسين', 'ستين', 'السبعين', 'ثمانين', 'تسعين'];
//console.log(th);
function toWords(s) {
s = s.toString();
s = s.replace(/[\, ]/g,'');
if (s != parseFloat(s)) return 'ليس رقم';
var x = s.indexOf('.');
if (x == -1)
x = s.length;
if (x > 15)
return 'too big';
var n = s.split('');
var str = '';
var sk = 0;
for (var i=0; i < x; i++) {
if ((x-i)%3==2) {
if (n[i] == '1') {
str += tn[Number(n[i+1])] + ' '+ ' ';
i++;
sk=1;
} else if (n[i]!=0) {
str += tw[n[i]-2] + ' ';
sk=1;
}
} else if (n[i]!=0) { // 0235
str = dg[n[i]] + ' ' + str + ' ';
if ((x-i)%3==0) str += 'مائة و ';
sk=1;
}
if ((x-i)%3==1) {
if (sk)
str += th[(x-i-1)/3] + ' ';
sk=0;
}
}
if (x != s.length) {
var y = s.length;
str += 'point ';
for (var i=x+1; i<y; i++)
str += dg[n[i]] +' ';
}
return str.replace(/\s+/g,' ');
}
console.log("23 : "+ toWords(23));
console.log("120: "+ toWords(120));
Hi I don't understand Arabic but I guess the solution to this can be find in this particular question/solution.
Convert digits into words with JavaScript
I am working on a blog with custom template which includes this numbered page navigation script below. Script is working in all pages except search results for queries and labels!!! I tried some changes but as I am not a javascript expert and I couldn't make it work... So, any kind of help would be really appreciated!!!
var pageCount = 9;
var displayPageNum = 3;
var upPageWord = "<i class='fa fa-angle-left'></i>";
var downPageWord = "<i class='fa fa-angle-right'></i>";
function showpageCount(x) {
var C = home_page_url;
var E = new Array();
var y = 1;
var H = 1;
var v = 0;
var p = 0;
var G = 0;
var F = "";
var J = "";
var w = "";
for (var z = 0, A; A = x.feed.entry[z]; z++) {
var u = A.published.$t.substring(0, 19) + A.published.$t.substring(23, 29);
timestamp = encodeURIComponent(u);
var i = A.title.$t;
if (i != "") {
if (v == 0 || (v % pageCount == (pageCount - 1))) {
if (C.indexOf(timestamp) != -1) {
y = H
}
if (i != "") {
H++
}
E[E.length] = "/search?updated-max=" + timestamp + "&max-results=" + pageCount
}
}
v++
}
for (var D = 0; D < E.length; D++) {
if (D >= (y - displayPageNum - 1) && D < (y + displayPageNum)) {
if (p == 0 && D == y - 2) {
if (y == 2) {
J = '<span class="showpage">' + upPageWord + "</span>"
} else {
J = '<span class="showpage">' + upPageWord + "</span>"
}
p++
}
if (D == (y - 1)) {
F += '<span class="showpagePoint">' + y + "</span>"
} else {
if (D == 0) {
F += '<span class="showpageNum">1</span>'
} else {
F += '<span class="showpageNum">' + (D + 1) + "</span>"
}
}
if (G == 0 && D == y) {
w = '<span class="showpage"> ' + downPageWord + "</span>";
G++
}
}
}
if (y > 1) {
F = "" + J + " " + F + " "
}
F = '<div class="showpageArea">' + F;
if (y < (H - 1)) {
F += w
}
if (H == 1) {
H++
}
F += "</div>";
var I = document.getElementsByName("pageArea");
var B = document.getElementById("blog-pager");
if (H <= 2) {
F = ""
}
for (var D = 0; D < I.length; D++) {
I[D].innerHTML = F
}
if (I && I.length > 0) {
F = ""
}
if (B) {
B.innerHTML = F
}
}
function showpageCount2(A) {
var F = home_page_url;
var G = new Array();
var J = F.indexOf("/search/label/") != -1;
var M = J ? F.substr(F.indexOf("/search/label/") + 14, F.length) : "";
M = M.indexOf("?") != -1 ? M.substr(0, M.indexOf("?")) : M;
var B = 1;
var L = 1;
var y = 0;
var p = 0;
var K = 0;
var I = "";
var P = "";
var z = "";
var N = '<span class="showpageNum"><a href="/search/label/' + M + "?&max-results=" + pageCount + '">';
var F = home_page_url;
for (var C = 0, D; D = A.feed.entry[C]; C++) {
var x = D.published.$t.substring(0, 19) + D.published.$t.substring(23, 29);
timestamp = encodeURIComponent(x);
var i = D.title.$t;
if (i != "") {
if (y == 0 || (y % pageCount == (pageCount - 1))) {
if (F.indexOf(timestamp) != -1) {
B = L
}
if (i != "") {
L++
}
G[G.length] = "/search/label/" + M + "?updated-max=" + timestamp + "&max-results=" + pageCount
}
}
y++
}
for (var H = 0; H < G.length; H++) {
if (H >= (B - displayPageNum - 1) && H < (B + displayPageNum)) {
if (p == 0 && H == B - 2) {
if (B == 2) {
P = N + upPageWord + "</a></span>"
} else {
P = '<span class="showpage">' + upPageWord + "</span>"
}
p++
}
if (H == (B - 1)) {
I += '<span class="showpagePoint">' + B + "</span>"
} else {
if (H == 0) {
I = N + "1</a></span>"
} else {
I += '<span class="showpageNum">' + (H + 1) + "</span>"
}
}
if (K == 0 && H == B) {
z = '<span class="showpage"> ' + downPageWord + "</span>";
K++
}
}
}
if (B > 1) {
if (!J) {
I = "" + P + " " + I + " "
} else {
I = "" + P + " " + I + " "
}
}
I = '<div class="showpageArea">' + I;
if (B < (L - 1)) {
I += z
}
if (L == 1) {
L++
}
I += "</div>";
var O = document.getElementsByName("pageArea");
var E = document.getElementById("blog-pager");
if (L <= 2) {
I = ""
}
for (var H = 0; H < O.length; H++) {
O[H].innerHTML = I
}
if (O && O.length > 0) {
I = ""
}
if (E) {
E.innerHTML = I
}
}
var home_page_url = location.href;
var thisUrl = home_page_url;
if (thisUrl.indexOf("/search/label/") != -1) {
if (thisUrl.indexOf("?updated-max") != -1) {
var lblname1 = thisUrl.substring(thisUrl.indexOf("/search/label/") + 14, thisUrl.indexOf("?updated-max"))
} else {
var lblname1 = thisUrl.substring(thisUrl.indexOf("/search/label/") + 14, thisUrl.indexOf("?&max"))
}
}
var home_page = "/";
if (thisUrl.indexOf("?q=") == -1) {
if (thisUrl.indexOf("/search/label/") == -1) {
document.write('<script src="' + home_page + 'feeds/posts/summary?alt=json-in-script&callback=showpageCount&max-results=99999" ><\/script>')
} else {
document.write('<script src="' + home_page + "feeds/posts/full/-/" + lblname1 + '?alt=json-in-script&callback=showpageCount2&max-results=99999" ><\/script>')
}
};
We are currently facing the same problem. The pagination links are good for even pages, but not for off pages. The whole script seems quite buggy, but only for 'search keywords'. Will post results if we achieve any progress.
var employees = [];
function add() {
a = {
tr: document.getElementById("trans").value,
namex: document.getElementById("name").value,
pd: document.getElementById("pd").value,
age: document.getElementById("age").value,
income: document.getElementById("income").value
};
employees.push(a.tr + "" + a.namex + "" + a.pd + "" + a.age + "" + a.income + "");
}
function show() {
q = "";
q = q + "";
q = q + "Transaction NumberNameCivil StatusAgeIncome";
q = q + "";
q = q + "";
b = -1;
while (b < (employees.length - 1)) {
b = b + 1;
q = q + "";
q = q + "" + employees[b] + "";
q = q + "";
}
q = q + "";
document.getElementById("qqq").innerHTML = q;
}
function del() {
for (i = 0; i <= a.length; i++) {
e = employees[0];
f = employees[1];
g = employees[2];
h = employees[3];
k = employees[4];
if (e[i] == document.getElementById("trans").value) {
e.splice(i, 1);
f.splice(i, 1);
g.splice(i, 1);
h.splice(i, 1);
k.splice(i, 1);
}
}
}