🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Sort Steam Achievement

Makes Steam achievements sorted by unlock date.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Sort Steam Achievement
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Makes Steam achievements sorted by unlock date.
// @author       Makazeu
// @match        *://steamcommunity.com/id/*/stats/*
// @grant        none
// @require      https://cdn.bootcss.com/moment.js/2.18.1/moment.min.js
// ==/UserScript==

/* jshint esversion: 6 */

(function() {
    'use strict';

    let comparator = (a, b) => {
        let a_datetime = datetimeParser(
            a.children[1].children[0].children[0].innerText.trim());
        let b_datetime = datetimeParser(
            b.children[1].children[0].children[0].innerText.trim());
        return a_datetime.isBefore(b_datetime) ? -1 : 1;
    };

    let datetimeParser =  datetime => {
        datetime = datetime.substring('解锁日期 '.length);
    
        datetime = datetime.replace('上午', ' AM ');
        datetime = datetime.replace('下午', ' PM ');
    
        if (datetime.includes('年')) {
            return moment(datetime, 'YYYY年MM月DD日 A HH:mm');
        } else {
            return moment(datetime, 'MM月DD日 A HH:mm');
        }
    };

    let achieveFilter = (key, value) => {
        if (value.innerHTML === '') return false; 
        if (value.children[1].children[0].children.length < 3) return false;
        if (!value.children[1].children[0].children[0]
            .innerText.includes('解锁')) return false;
        return true;
    };

    let achieveSet = jQuery('#personalAchieve');
    let achieveRows = achieveSet.children().filter(achieveFilter);
    let arr = Array.from(achieveRows);
    
    arr.sort(comparator);

    for (let i = 0; i < achieveRows.length; i++) {
        let element = achieveRows[i];
        element.remove();
    }

    arr.forEach( achieve => {
        //console.log(achieve.children[1].children[0].children[1].innerText);
        achieveSet.prepend(achieve);
    });
    
})();