SHARE
TWEET

Untitled

a guest Jun 25th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function randString(n) {
  2.     if(!n)
  3.     {
  4.         n = 5;
  5.     }
  6.  
  7.     var text = '';
  8.     var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  9.  
  10.     for(var i=0; i < n; i++)
  11.     {
  12.         text += possible.charAt(Math.floor(Math.random() * possible.length));
  13.     }
  14.  
  15.     return text;
  16. }
  17.  
  18. // Cookies
  19. function createCookie(name, value, days) {
  20.     if (days) {
  21.         var date = new Date();
  22.         date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  23.         var expires = "; expires=" + date.toGMTString();
  24.     }
  25.     else var expires = "";
  26.  
  27.     document.cookie = name + "=" + value + expires + "; path=/";
  28. }
  29.  
  30. function readCookie(name) {
  31.     var nameEQ = name + "=";
  32.     var ca = document.cookie.split(';');
  33.     for (var i = 0; i < ca.length; i++) {
  34.         var c = ca[i];
  35.         while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  36.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  37.     }
  38.     return null;
  39. }
  40.  
  41. function eraseCookie(name) {
  42.     createCookie(name, "", -1);
  43. }
  44.  
  45. function getUsername() {
  46.    
  47.      var cookie = readCookie('cookie_name');
  48.      if (!cookie) {
  49.         cookie =  randString(9);
  50.         createCookie('cookie_name', cookie, 30);
  51.      }
  52.  
  53.     var username = cookie;
  54.     if (!'localStorage' in window) {
  55.         return username;
  56.     }
  57.  
  58.     username = window.localStorage.getItem('username');
  59.     if (!username) {
  60.         username = randString(9);
  61.         window.localStorage.setItem('username', username);
  62.     }
  63.  
  64.     return username;
  65. }
  66.  
  67. kiwi.plugin('ident', function(kiwi) {
  68.     kiwi.state.$on('network.new', function(event) {
  69.         event.network.username = getUsername();
  70.  
  71.     });
  72. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top