1const hasLocalStorage = (function(){ 2 try { 3 localStorage.setItem('mod', 'mod'); 4 localStorage.removeItem('mod'); 5 return true; 6 } catch(e) { 7 return false; 8 } 9})() 10 11if (!hasLocalStorage) { 12 (function () { 13 var Storage = function (type) { 14 function createCookie(name, value, days) { 15 var date, expires; 16 17 if (days) { 18 date = new Date(); 19 date.setTime(date.getTime()+(days*24*60*60*1000)); 20 expires = "; expires="+date.toGMTString(); 21 } else { 22 expires = ""; 23 } 24 document.cookie = name+"="+value+expires+"; path=/"; 25 } 26 27 function readCookie(name) { 28 var nameEQ = name + "=", 29 ca = document.cookie.split(';'), 30 i, c; 31 32 for (i=0; i < ca.length; i++) { 33 c = ca[i]; 34 while (c.charAt(0)==' ') { 35 c = c.substring(1,c.length); 36 } 37 38 if (c.indexOf(nameEQ) == 0) { 39 return c.substring(nameEQ.length,c.length); 40 } 41 } 42 return null; 43 } 44 45 function setData(data) { 46 // Convert data into JSON and encode to accommodate for special characters. 47 data = encodeURIComponent(JSON.stringify(data)); 48 // Create cookie. 49 if (type == 'session') { 50 createCookie(getSessionName(), data, 365); 51 } else { 52 createCookie('localStorage', data, 365); 53 } 54 } 55 56 function clearData() { 57 if (type == 'session') { 58 createCookie(getSessionName(), '', 365); 59 } else { 60 createCookie('localStorage', '', 365); 61 } 62 } 63 64 function getData() { 65 // Get cookie data. 66 var data = type == 'session' ? readCookie(getSessionName()) : readCookie('localStorage'); 67 // If we have some data decode, parse and return it. 68 return data ? JSON.parse(decodeURIComponent(data)) : {}; 69 } 70 71 function getSessionName() { 72 // If there is no name for this window, set one. 73 // To ensure it's unquie use the current timestamp. 74 if(!window.name) { 75 window.name = new Date().getTime(); 76 } 77 return 'sessionStorage' + window.name; 78 } 79 80 // Initialise if there's already data. 81 var data = getData(); 82 83 return { 84 length: 0, 85 clear: function () { 86 data = {}; 87 this.length = 0; 88 clearData(); 89 }, 90 getItem: function (key) { 91 return data[key] === undefined ? null : data[key]; 92 }, 93 key: function (i) { 94 // not perfect, but works 95 var ctr = 0; 96 for (var k in data) { 97 if (ctr == i) return k; 98 else ctr++; 99 } 100 return null; 101 }, 102 removeItem: function (key) { 103 delete data[key]; 104 this.length--; 105 setData(data); 106 }, 107 setItem: function (key, value) { 108 data[key] = value+''; // forces the value to a string 109 this.length++; 110 setData(data); 111 } 112 }; 113 }; 114 115 // Replace window.localStorage and window.sessionStorage with out custom 116 // implementation. 117 var localStorage = new Storage('local'); 118 var sessionStorage = new Storage('session'); 119 120 Object.defineProperty(window, "localStorage", { value: localStorage }) 121 Object.defineProperty(window, "sessionStorage", { value: sessionStorage }) 122 })(); 123}
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.