How to sort extension in the Chrome Web Store?

8,067

I have created a simple sorter js which works on Chrome Dev tools console. You can reach the GitHub page here.

It mainly sorts the extensions on the Chrome Web Store. It runs on Chrome Dev Tools console which is started by Ctrl+Shift+I.

After opening the search extensions page on the link https://chrome.google.com/webstore/search/PHRASE?_category=extensions with your search phrase replaced by PHRASE. And than the code under sorter.js is run on the chrome dev cosole.

It firstly loads all the extensions on the infinitly-scroll page by automatically scroll the page until not scroll. Then it sorts them by number of votes.

var i = 0;
var num_of_items = 0;
var stop = false;
function startCheck(max)
{
    i++;
    
    //document.querySelectorAll('div.h-a-Kd.a-Hd-mb')[0];
    var bottom = document.querySelectorAll('div.h-a-Hd-mb.a-Hd-mb')[0];
    bottom.scrollIntoView();
    //scrollTo(scrollX,scrollY+1000); 
    console.log(i.toString());  
    
    var items = document.querySelectorAll('.a-d-na.a-d.webstore-test-wall-tile.a-d-zc.Xd.dd');
    var new_num_of_items = items.length;
    if (num_of_items != new_num_of_items)
    {
        num_of_items = new_num_of_items;
        console.log('Loaded items : ' + new_num_of_items);
    }   
    
    if (i>max || stop) 
    {
        i = 0;
        num_of_items = 0;
        stop = false;
        items[new_num_of_items-1].scrollIntoView(false);
        sortsort();
        return;
    }
    
    var t = setTimeout(function (){startCheck(max);}, 100);
}

var MAX_COUNT = 25;
var counter = 0;
function stopCheck()
{   
    var spin = document.querySelectorAll('div.h-a-Kd.a-Hd-mb')[0];  
    var state_new = spin.attributes.style.value == "display: none;"
    
    if (state_new)
        counter++;
    else
        counter=0;
    
    console.log('Counter : ' + counter);
    if (counter > MAX_COUNT)
    {
        counter = 0;
        stop = true;        
        return;
    }
    
    var t = setTimeout(function (){stopCheck();}, 100);
}

var sortsort = function() {

    var ab = document.querySelectorAll('.a-d-na.a-d.webstore-test-wall-tile.a-d-zc.Xd.dd');
    console.log(ab.length);
    var ab_arry = Array.from(ab);

    var index_str;
    var star_str;
    ab_arry.forEach((star) => {
        
        index_str = star.attributes.hasOwnProperty("index") ? Number(star.attributes.index.value.toString().replace(/,/g, '')) : 0
        star_str  = star.getElementsByClassName("nAtiRe").length > 0 ? Number(star.getElementsByClassName("nAtiRe")[0].textContent.toString().replace(/,/g, '')).toString() : "Not voted";

        console.log( index_str + " = >>>> " + star_str);        
    });

    ab_arry.sort(function (a,b) {
        var a_star =  a.getElementsByClassName("nAtiRe").length > 0 ? Number(a.getElementsByClassName("nAtiRe")[0].textContent.toString().replace(/,/g, '')) : 0;
        var b_star =  b.getElementsByClassName("nAtiRe").length > 0 ? Number(b.getElementsByClassName("nAtiRe")[0].textContent.toString().replace(/,/g, '')) : 0;
        
        return (b_star - a_star);   
    });


    let row_nodes = document.querySelectorAll('.h-a-x > [role="grid"] > [role="row"]');
    var row_nodes_arry = Array.from(row_nodes);
    var sr;

    for (var rr = 0; rr < row_nodes_arry.length; rr++)
    {   
        sr_start = rr * 3;
        
        var msg = rr.toString() + ' <--- ';
        for (var sr = sr_start; sr < sr_start + 3 && sr < ab_arry.length ; sr++)
        {
            msg += '1:' + sr + ' ';
            row_nodes_arry[rr].appendChild(ab_arry[sr]);
        }   
        console.log(msg);
    }

}

startCheck(3000);
stopCheck();

Share:
8,067

Related videos on Youtube

winchendonsprings
Author by

winchendonsprings

Updated on September 18, 2022

Comments

  • winchendonsprings
    winchendonsprings almost 2 years

    The Google Chrome Web Store seems like a disaster to me. I cannot make sense of it.

    How can you sort extensions by popularity? By rating? By amount of downloads? By newest? By recently updated?

    Am I completely overlooking something?

    https://chrome.google.com/webstore/category/extensions

    • clhy
      clhy over 8 years
      You have feature to sort by rating but not by others
    • winchendonsprings
      winchendonsprings over 8 years
      How does the sort by rating work? I sort by 'Developer Tools' and on the first page I see "Capture webpage screenshot" with 12148 reviews which is about ten spots behind "CSS shapes editor" with 66. How does that even work? If I give an extension with a zero reviews a five star rating it gets bumped to the number one spot?
    • clhy
      clhy over 8 years
      I know its a little skewed but it has been like that for some time now. See this
    • winchendonsprings
      winchendonsprings over 8 years
      Last week the Firefox team was doing an AMA on reddit. I should have mentioned they have a serious leg up up