[RELEASE] Sort Topics by Creation Date

Discussion about Cock Hero and other sexy videos.

Moderator: andyp

User avatar
samfishercarl
Explorer
Explorer
Posts: 66
Joined: Sat Nov 13, 2021 10:24 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [RELEASE] Sort Topics by Creation Date

Post by samfishercarl »

Expression wrote: Fri Nov 26, 2021 2:48 am
lestrian wrote: Fri Nov 26, 2021 12:22 am
Expression wrote: Sun Nov 21, 2021 7:36 am ...
This code has some bug. I installed it in tampermonkey on chrome, and it looks like it works fine, but it only shows posts from Nov 24 and earlier. It misses the post made today on Nov 26.
Thanks for letting me know, looks like the HTML of topics change when they receive a reply. Here's the code that correctly handles new posts without replies. Original post will also have this same code.

Code: Select all

// ==UserScript==
// @name         Milovana Sorter
// @version      0.3
// @description  Sort Milovana topics by creation date
// @author       Expression
// @match        https://milovana.com/forum/viewforum.php?f=25
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function requestUrl(url) { /* send request to url and sends each post element to buildList processing */
        const http = new XMLHttpRequest();
        http.open("GET", url);
        http.send();
        http.onreadystatechange = function() {
            if(this.readyState == 4 && this.status == 200) {
                var temp_element = document.createElement("html");
                temp_element.innerHTML = http.responseText;
                var elementList = temp_element.getElementsByClassName("topiclist topics")[1].childNodes;
                elementList.forEach(buildList);
                }
            }
        }
    var post_arr = [];
    var display_arr = [];
    function getDate(el) { /* get date from element */
        for(var i = 0; i < el.length; i++) {
            for(var j = 0; j < el[i].children.length; j++) {
                if(el[i].children[j].nodeName == "TIME") {
                    return el[i].children[j].dateTime;
                }
            }
        }
        return "ERROR";
    }
    var count = 0;
    function buildList(el, idx, arr) { /* scrapes data from topics and stores it in post_arr or display_arr for sticky topics, immediately storing stickies retains their order at the top*/
        let match = /(?<=t\=)\d+(?=$)/;
        if(el.nodeType == 1) {
            try {
                count++;
                var className = el.className;
                var indexOffset = ((el.children[0].childNodes[1].children[0].className !== "list-inner") ? 1 : 0);
                var data = el.children[0].childNodes[1].children[0 + indexOffset].children;
                var url = data[0 + indexOffset].href;
                var postId = url.match(match)[0];
                var postDate = Date.parse(getDate(data));
                if(className.includes("sticky")) {
                    display_arr.push(el);
                } else {
                    post_arr.push([postDate, postId, el, className]);
                }
            } catch {
                return;
            }
        }
    }
    async function loop_requests() { /* requests first 5 pages of forum topics */
        var loopIncrement = 50;
        var numPages = 5;
        var count = 0;
        var req_url = "https://milovana.com/forum/viewforum.php?f=25&start=";
        for(var i = 0; i <= numPages; i++) {
            count++;
            var postFrom = i * loopIncrement;
            if(count > 100) {
                break;
            }
            var url = req_url + postFrom;
            await requestUrl(url);
        }
    }
    loop_requests();
    function replacePosts() { /* injects posts from an display_arr into the webpage */
        document.getElementsByClassName("topiclist topics")[1].innerHTML = "";
        for(var i = 0; i <= display_arr.length; i++) {
            try {
                document.getElementsByClassName("topiclist topics")[1].appendChild(display_arr[i]);
            } catch {}
        }
    }
    function getSortedElements() { /* sort elements in descending order by post date in post_arr and push them into display_arr */
        var sorted = post_arr.sort(function(a,b) {
            return a[0]-b[0]
        }).reverse();
        sorted.forEach(function(el, idx, arr) {
            display_arr.push(el[2]);
        });
        replacePosts(display_arr);
    }
    var timeout = setInterval(function() { /* check if post_arr can be sorted by checking its length */
        if(post_arr.length > 200) {
            getSortedElements();
            clearInterval(timeout);
        }
    }, 100);
})();
Similar fix to your code but it doesnt use a double for loop so it does not run in exponential time :-)

Code: Select all

// ==UserScript==
// @name         Milovana Sorter
// @version      0.3
// @description  Sort Milovana topics by creation date
// @author       Expression
// @match        https://milovana.com/forum/viewforum.php?f=25*
// @grant        none
// ==/UserScript==

var active = document.getElementsByClassName("active")[0].innerText;
(function() {
    'use strict';
    var test = document.getElementsByClassName("topiclist topics")[1].childNodes;
    var req_url = "https://milovana.com/forum/viewforum.php?f=25&start=";
    function requestUrl(url) { /* send request to url */
        const http = new XMLHttpRequest();
        http.open("GET", url);
        http.send();
        http.onreadystatechange = function() {
            if(this.readyState == 4 && this.status == 200) {
                var temp_element = document.createElement("html");
                temp_element.innerHTML = http.responseText;
                var elementList = temp_element.getElementsByClassName("topiclist topics")[1].childNodes;
                elementList.forEach(buildList);
                }
            }
        }
    var post_arr = [];
    var display_arr = [];
    function getDate(el) { /* get date from element */
        for(var i = 0; i < el.length; i++) {
            if(el[i].nodeName == "TIME") {
                return el[i].dateTime;
            }
        }
        throw new exception;
		}
    var count = 0;
    function buildList(el, idx, arr) { /* scrapes data from topics and stores it in post_arr or display_arr for sticky topics, immediately storing stickies retains their order at the top*/
        let match = /(?<=t\=)\d+(?=$)/;
        if(el.nodeType == 1) {
            try {
                count++;
                var className = el.className;
                var indexOffset = ((el.children[0].childNodes[1].children[0].className !== "list-inner") ? 1 : 0);
                var data = el.children[0].childNodes[1].children[0 + indexOffset].children;
                var url = data[0 + indexOffset].href;
                var postId = url.match(match)[0];
				var l = 0;
				try{
                var postDate = Date.parse(getDate(data[4 + indexOffset].children));
				}catch (e){
					try{
					var postDate = Date.parse(getDate(data[3 + indexOffset].children));
					}catch(e){
						console.log("ERROR!!!!!!");
					}
				}
                if(className.includes("sticky")) {
                    display_arr.push(el);
                } else {
                    post_arr.push([postDate, postId, el, className]);
                }
            } catch {
                return;
            }
        }
    }
    async function loop_requests() { /* requests first 5 pages of forum topics */
        var loopIncrement = 50;
        var loopCount = 5;
        var count = 0;
        for(var i = 0; i < loopCount; i++) {
            count++;
            var postFrom = i * loopIncrement;
            if(count > 100) {
                break;
            }
            var url = req_url + postFrom;
            await requestUrl(url);
        }
    }
    loop_requests();
    function replacePosts() { /* injects posts from an display_arr into the webpage */
        var replace_list = document.getElementsByClassName("topiclist topics")[1].children;
		for(var j = 0; j < 50*(active-1); j++){
		display_arr.shift();
		}
        for(var i = 0; i < replace_list.length; i++) {
            var new_post = document.createElement("li");
            new_post.className = replace_list[i].className;
            new_post.innerHTML = display_arr.shift().innerHTML;
            replace_list[i].parentNode.replaceChild(new_post, replace_list[i]);
        }
    }
    function getSortedElements() { /* sort elements in descending order by post date in post_arr and push them into display_arr */
        var sorted = post_arr.sort(function(a,b) {
            return a[0]-b[0]
        }).reverse();
        sorted.forEach(function(el, idx, arr) {
            display_arr.push(el[2]);
        });
        replacePosts(display_arr);
    }
    var timeout = setInterval(function() { /* check if post_arr can be sorted by checking its length */
        if(post_arr.length > 200) {
            getSortedElements();
            clearInterval(timeout);
        }
    }, 100);
})();

User avatar
book_guy
Experimentor
Experimentor
Posts: 1823
Joined: Sat Nov 26, 2011 2:42 am
Gender: Male
Sexual Orientation: Straight

Re: [RELEASE] Sort Topics by Creation Date

Post by book_guy »

This little code snippet is an interesting idea. And, it's an interesting idea, also, to post it under the "[RELEASE]" tag on the thread title. I don't think I'm complaining about those ideas.

But, I thought you could accomplish the same thing by finagling the options in the native search functions on the Advanced Search page. I recall having accomplished it once. Maybe it involves an intelligent use of search-strings in your browser window after you get the results page.
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
Are you missing a cock-hero video?
Me too. Since September 1, 2020, my Mega Sharing Zones contents are being removed by Mega.
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
User avatar
samfishercarl
Explorer
Explorer
Posts: 66
Joined: Sat Nov 13, 2021 10:24 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [RELEASE] Sort Topics by Creation Date

Post by samfishercarl »

book_guy wrote: Wed Dec 01, 2021 11:16 pm But, I thought you could accomplish the same thing by finagling the options in the native search functions on the Advanced Search page. I recall having accomplished it once. Maybe it involves an intelligent use of search-strings in your browser window after you get the results page.
I'm 95% positive you could since the search function does take regular expressions, this code was more for people who wanted a simple one and done solution. I personally only have it sort on the first page because I like seeing everything being posted or bumped it just being in order of creation date that way i see everything recent including comments on older stuff. With that configuration. new releases are like the top 5 results and the next like 10 are bumps or new comments
User avatar
book_guy
Experimentor
Experimentor
Posts: 1823
Joined: Sat Nov 26, 2011 2:42 am
Gender: Male
Sexual Orientation: Straight

Re: [RELEASE] Sort Topics by Creation Date

Post by book_guy »

samfishercarl wrote: Thu Dec 02, 2021 7:05 am I'm 95% positive you could since the search function does take regular expressions,
Well, the code is kewl and probably helpful to some readers (and anyway, I suspect you valued completing that project for the enjoyment and/or sense of coding genius accomplishment), but I'm not speaking about the use of regex or similar, not presently.

Instead, just do the following at the Advanced Search page:

search for keyword "release"
in the forum On Video
within Topic titles only
display results as Topics
sort results by post time, descending
limit results to previous: 7 days (f.e.)

This is the "intended" method. It relies on a few sacrifices, viz., (a) a user returning to Milovana every seven days or less, to perform the search again (or, if you don't get back in time, then, on ((a`)) increasing the time-limit appropriately); on (b) creators using the term "release" somewhere in the topic title; and on (c) digging through a few redundant results.

I'm unsure on one subject. Will the above process return (i) any thread entitled "release" which also has any new post in it, or (ii) only new threads entitled "release"? (Pretty sure it does the unwanted one of the two.) But any excess on this subject is alleviated easily: since the total results over a seven-day period seem to average around only six to ten posts total, it's not really much grief to simply scan the time-stamp of each thread's origination, which is info available on the initial search-results page. Eazy peazy.

Well, I don't mean to denigrate your code. It's a pretty neat thing. But I think the native search-function and advanced-search pages are "intended" to allow you to get what you want without relying on such a code. Or, perhaps, does my method above fail in some manner? Maybe I'm missing out on noticing scads of new releases by relying on it? I'd want to get fapping soon, if that's the case, so let me know!
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
Are you missing a cock-hero video?
Me too. Since September 1, 2020, my Mega Sharing Zones contents are being removed by Mega.
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
User avatar
samfishercarl
Explorer
Explorer
Posts: 66
Joined: Sat Nov 13, 2021 10:24 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [RELEASE] Sort Topics by Creation Date

Post by samfishercarl »

book_guy wrote: Sat Dec 04, 2021 10:26 pm
samfishercarl wrote: Thu Dec 02, 2021 7:05 am I'm 95% positive you could since the search function does take regular expressions,
search for keyword "release"
in the forum On Video
within Topic titles only
display results as Topics
sort results by post time, descending
limit results to previous: 7 days (f.e.)
You are right, I code it for fun and because people asked for it. I used it as a practical excuse to learn to make chrome extensions and practice html/javascript. IMO the forum is chill enough now that this code and even the advanced search method isn't really needed. :) it takes 2-3 weeks of not reading the forum to fill the front page with unread topics.
Expression
Explorer
Explorer
Posts: 8
Joined: Wed Nov 17, 2021 8:30 pm

Re: [RELEASE] Sort Topics by Creation Date

Post by Expression »

book_guy wrote: Sat Dec 04, 2021 10:26 pm Well, I don't mean to denigrate your code. It's a pretty neat thing. But I think the native search-function and advanced-search pages are "intended" to allow you to get what you want without relying on such a code. Or, perhaps, does my method above fail in some manner? Maybe I'm missing out on noticing scads of new releases by relying on it? I'd want to get fapping soon, if that's the case, so let me know!
Yeah, it's technically possible to do it with the advanced search options, but that feels a bit clunky and unnecessary. In my opinion sorting topics by date on a forum isn't an advanced feature, but I do recognize there are limitations in the forum software.

This code doesn't check if a thread has "release" in the title, it just sorts the first 5 pages of On Video by the topic's creation date. You're probably not missing much with your current method :-P
cockherocomments
Explorer At Heart
Explorer At Heart
Posts: 147
Joined: Thu Feb 16, 2012 11:44 pm

Re: [RELEASE] Sort Topics by Creation Date

Post by cockherocomments »

this is fucking brilliant
cockherocomments
Explorer At Heart
Explorer At Heart
Posts: 147
Joined: Thu Feb 16, 2012 11:44 pm

Re: [RELEASE] Sort Topics by Creation Date

Post by cockherocomments »

book_guy wrote: Sat Dec 04, 2021 10:26 pm
samfishercarl wrote: Thu Dec 02, 2021 7:05 am I'm 95% positive you could since the search function does take regular expressions,
Well, the code is kewl and probably helpful to some readers (and anyway, I suspect you valued completing that project for the enjoyment and/or sense of coding genius accomplishment), but I'm not speaking about the use of regex or similar, not presently.

Instead, just do the following at the Advanced Search page:

search for keyword "release"
in the forum On Video
within Topic titles only
display results as Topics
sort results by post time, descending
limit results to previous: 7 days (f.e.)

This is the "intended" method. It relies on a few sacrifices, viz., (a) a user returning to Milovana every seven days or less, to perform the search again (or, if you don't get back in time, then, on ((a`)) increasing the time-limit appropriately); on (b) creators using the term "release" somewhere in the topic title; and on (c) digging through a few redundant results.

I'm unsure on one subject. Will the above process return (i) any thread entitled "release" which also has any new post in it, or (ii) only new threads entitled "release"? (Pretty sure it does the unwanted one of the two.) But any excess on this subject is alleviated easily: since the total results over a seven-day period seem to average around only six to ten posts total, it's not really much grief to simply scan the time-stamp of each thread's origination, which is info available on the initial search-results page. Eazy peazy.

Well, I don't mean to denigrate your code. It's a pretty neat thing. But I think the native search-function and advanced-search pages are "intended" to allow you to get what you want without relying on such a code. Or, perhaps, does my method above fail in some manner? Maybe I'm missing out on noticing scads of new releases by relying on it? I'd want to get fapping soon, if that's the case, so let me know!
The problem is that this returns topics sorted by the date of their most recent reply, not by the topic creation date.
User avatar
book_guy
Experimentor
Experimentor
Posts: 1823
Joined: Sat Nov 26, 2011 2:42 am
Gender: Male
Sexual Orientation: Straight

Re: [RELEASE] Sort Topics by Creation Date

Post by book_guy »

cockherocomments wrote: Sat Dec 18, 2021 6:15 am The problem is that this returns topics sorted by the date of their most recent reply, not by the topic creation date.
Ah yes, indeed ... I was barking up that tree but didn't realize it.

So, your point is true, but my search will work fine under certain conditions anyway. F.e., if you are returning regularly, say once a week or more often, to engage in my search procedure, there will be scant few search results. Then a mere visual scan through the results will enable you to mentally sort by topic-creation date rather than by most-recent-reply date. I think I was assuming as much about the frequency of user action.

Generally, though, you are correct in pointing out the flaw in my algorithm. It's pretty annoying that the inherent search functions don't have the option we're seeking, the option to sort by creation date. You can't sort the threads of the forum page by their first-post-date either. Most forums have a clickable "date thread created" column, f.e..
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
Are you missing a cock-hero video?
Me too. Since September 1, 2020, my Mega Sharing Zones contents are being removed by Mega.
●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●▬▬▬▬▬▬▬▬▬●
Post Reply

Who is online

Users browsing this forum: Alma001, axxoto, Baidu [Spider] and 63 guests