mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
49 lines
No EOL
903 B
QBasic
49 lines
No EOL
903 B
QBasic
Const LOCAL = "LOCAL"
|
|
Const SESSION = "SESSION"
|
|
|
|
Export LOCAL, SESSION
|
|
Export Clear, Get, Key, Length, Set, Remove
|
|
|
|
$If Javascript Then
|
|
function _storage(stype) {
|
|
return (stype == SESSION) ? sessionStorage : localStorage;
|
|
}
|
|
$End If
|
|
|
|
Sub Clear (stype)
|
|
$If Javascript Then
|
|
_storage(stype).clear();
|
|
$End If
|
|
End Sub
|
|
|
|
Function Get (key, stype)
|
|
$If Javascript Then
|
|
var result = _storage(stype).getItem(key);
|
|
if (result == null) { result = ""; }
|
|
Get = result
|
|
$End If
|
|
End Function
|
|
|
|
Function Key (idx, stype)
|
|
$If Javascript Then
|
|
Key = _storage(stype).key(idx);
|
|
$End If
|
|
End Function
|
|
|
|
Function Length (stype)
|
|
$If Javascript Then
|
|
Length = _storage(stype).length;
|
|
$End If
|
|
End Function
|
|
|
|
Sub Set (key, value, stype)
|
|
$If Javascript Then
|
|
_storage(stype).setItem(key, value);
|
|
$End If
|
|
End Sub
|
|
|
|
Sub Remove (key, stype)
|
|
$If Javascript Then
|
|
_storage(stype).removeItem(key);
|
|
$End If
|
|
End Sub |