Created
November 18, 2019 14:27
-
-
Save vmlinz/60759488b9f5fc3cefa1f36e5649b5b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, '\\$&'); | |
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
} | |
function contains(b, a) { | |
b = b.toLowerCase(); | |
a = a.toLowerCase(); | |
return b.indexOf(a) !== -1; | |
} | |
function getURLParameterWithDefault(b) { | |
var a = decodeURI( | |
(RegExp(b + '=(.+?)(&|$)').exec(location.search) || [, null])[1] || '' | |
); | |
if (b.indexOf('brand') !== -1 && contains(a, 'generic')) { | |
a = 'Phone'; | |
} | |
if (b.indexOf('model') !== -1 && contains(a, 'android')) { | |
a = 'Phone'; | |
} | |
if (b.indexOf('br') !== -1 && contains(a, 'android')) { | |
a = 'Internet Browser'; | |
} | |
if (b.indexOf('country') === -1) { | |
a = 'Unkonwn'; | |
} | |
return a; | |
} | |
function getURLParameter(a) { | |
a = a.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | |
var c = new RegExp('[\\?&]' + a + '=([^&#]*)'), | |
b = c.exec(location.search); | |
return b === null | |
? '' | |
: decodeURIComponent(b[1].replace(/\+/g, ' ')); | |
} | |
function move_next(a, to, obj) { | |
{ | |
if (!Object.keys) { | |
Object.keys = function(obj) { | |
var keys = []; | |
for (var i in obj) { | |
if (obj.hasOwnProperty(i)) { | |
keys.push(i); | |
} | |
} | |
return keys; | |
}; | |
} | |
// 7. update offer click url | |
var redirect_url = !!to ? to : window.redirect_url; | |
if (obj !== undefined) { | |
redirect_url += '&' + Object.keys(obj).map(k => k + '=' + encodeURIComponent(obj[k])).join('&'); | |
} | |
// 8. update prelanding redirect url, often for teaser pages | |
var background_url = window.background_url; | |
if (background_url === "" && window.sawpp !== true && window.dpush !== true) { | |
if (window.domain_has_valid_cert === true && | |
location.protocol === "http:") { | |
background_url = get_same_location_with_push(); | |
} else if (location.protocol === "https:") { | |
setTimeout(function() { | |
window.show_pushwru_show && window.show_pushwru_show(); | |
}, 1); | |
} | |
} | |
if (background_url !== '') { | |
setTimeout(function(){ | |
location.href = background_url; | |
}, 1); | |
} | |
$(window).off("beforeunload"); | |
a.preventDefault(); | |
a.stopPropagation(); | |
var open_target = ''; | |
open_target === 'self' ? | |
window.open(redirect_url, "_self") : | |
window.open(redirect_url); | |
} | |
} | |
/** | |
* Get the value of a cookie | |
* Source: https://gist.github.com/wpsmith/6cf23551dd140fb72ae7 | |
* @param {String} name The name of the cookie | |
* @return {String} The cookie value | |
*/ | |
var getCookie = function (name) { | |
var value = "; " + document.cookie; | |
var parts = value.split("; " + name + "="); | |
if (parts.length == 2) return parts.pop().split(";").shift(); | |
}; | |
/*! | |
* Create an expiration date timestamp for use with cookies. | |
* (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com | |
* @param {Number} time The amount of time in the future to set the expiration date for | |
* @return {String} The expiration date | |
*/ | |
var getExpirationDate = function (time) { | |
return new Date(+new Date() + time).toUTCString(); | |
}; | |
function setCookie(name, value, days) { | |
var d = new Date; | |
d.setTime(d.getTime() + 24*60*60*1000*days); | |
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); | |
} |
Author
vmlinz
commented
Nov 18, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment