Warning: The following content might be a bit too techinical.
You may want to skip this post if you're not interested in programming-related (JavaScript) stuff.In this post I'm going to introduce how to properly save links of Random Encounter events for later visits,
and all the details of how I implemented it in
one of my scripts.
There are three topics in this post:
(1) The reasons to do so.
(2) Where to save such links?
(3) How to display such links to a user?
(1) The reasons to do so.
Why does one ever want to keep track of the URLs of Random Encounter events?
The first reason is that one can easily miss them when browing the galleries:
QUOTE(Dan31 @ Aug 7 2014, 16:32)

Also, feature request: keep in memory unclicked RE links (you can easily miss them when browsing the galleries). And the links probably need to be clicked in order (?), so only display the older one. (I'm not sure how long a link is valid, is it till a more recent RE or DOTND is triggered?)
The second reason is that, let's say one is AFK for a long time, and when he is back at the computer, he can immediately engage in the battle of Random Encounter events, rather than having to wait for at most 30 minutes for a Random Encounter event to occur.
It is especially useful if one works in the morning and afternoon, and only has access to his computer in the evening.
(2) Where to save such links?
I decide to save those URLs to the disk rather than in memory, in order to make the data (semi-)persistent,
so that even if you accidentally close the web browser or your computer crashes unexpectedly,
you can still have access to the saved URLs.
What options do we have?
1) Cookies
In most modern web browsers, a domain can have at most (approximately) 4K size of cookies.
([
www.ietf.org]
RFC 2965 suggests that "at least 4096 bytes per cookie", though.)
Let's do some math:
One Random Encounter link has 129 characters,
after escape()-ing it and save it in a cookie, the cookie value has more or less 145 characters.
There are at most 24 such links everyday (correct me if I'm wrong), meaning that the total amount of characters needed is 145*24=3480,
which leaves not much room for other cookies. Uh-oh.
2) localStorage
Unlike cookies, one can save data with larger size using localStorage, but it's a little tricky to share informations between subdomains, even though there are some workarounds such as using iFrame (http://stackoverflow.com/questions/4026479/use-localstorage-across-subdomains).
3) GM_getValue() and GM_setValue()
This is proabably the best method among the three. One can easily share saved URLs between different domains (no same-origin policy YAY), and no limit to the size of data one wants to save. Its only downside is that one cannot print the saved URLs in the interactive shell provided by the web browser; with cookies or localStorage, I can easily pretty-print saved URLs using JSON.stringify(_variable_, null, '\t').
Having said that, I chose 1) as my solution.
I truncated the URL and only kept the base64-encoded part (the red part).
Let's do some math again:
One base64-encoded string contains 80 characters,
after escape()-ing it and save it in a cookie, the cookie value has more or less 82 characters.
Total = 82*24=1968, which is much less than 4K, good.
(3) How to display such links to a user?
According to Dan31, it's better to display the saved URLs from the oldest to the newest.
Hence it's a FIFO scenario, and the best data structure to store these URLs would be a queue:
Just push() URLs to an array, and later access the array from index 0 to length-1.
Next thing would be retrieving the date information from the URL and display it to the user.
Let's take a look at an example URL of a Random Encounter event:
http://hentaiverse.org/?s=Battle&ss=ba&encounter=MTk4ODQ3MS0xNDA3NDEzOTg3LTMzMGQ4N2JiOWYyOTViZWU3ZmVhYzA0ZGUzMDVlNGIxNmJiMWZlZGY=The
red part is a base64-encoded string. After decoding it using the atob() function provided by most modern web browsers, we get the following string:
1988471-
1407413987-
330d87bb9f295bee7feac04de305e4b16bb1fedfThe
blue part is a user ID, which is unique to every user on the forum. In this case it is my user ID.
https://forums.e-hentai.org/index.php?showuser=1988471The
purple part is a string produced by some hash function.
Since it's almost impossible for users to produce such string (because they have no clue about the hash function),
this string can prevent users from auto-generating any valid URL of a Random Encounter event.
Finally, the green part. It's the only part we want.
The
green part is a POSIX timestamp, also called Epoch time, it's the number of seconds since 1970/01/01 00:00:00.
This is the time this specific Random Encounter event has been created by the E-Hentai server,
and it has nothing to do with whether or not you have clicked the link of the Random Encounter event.
1407413987 is also what I see in the "event" cookie when I visit e-hentai.org or its subdomains (.e-hentai.org),
and that cookie will be set by the server to another value
only when another event (a Random Encounter event or "The Dawn of a New Day" event) happens.
It can be converted to human-readable data using the Date object in JS:
var epoch = '1407413987';
var da = new Date();
da.setTime(parseInt(epoch)*1000); // setTime takes milliseconds as its argument.
da = da.toLocaleTimeString();
"da" now contains a localized time string such as "Thu, 07 Aug 2014 12:19:47 GMT".
At this moment, we can just:
var a = document.createElement('A');
a.href = 'http://hentaiverse.org/?s=Battle&ss=ba&encounter=' + e; // e being the base64-encoded string (the red part)
a.target = '_blank';
a.text = da;
And then add "a" to a DIV or something for display.
This post has been edited by djackallstar: Aug 10 2014, 11:38