LAction

Last Action

当前为 2024-01-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         LAction
// @namespace    zero.la.torn
// @version      0.2
// @description  Last Action
// @author       -zero [2669774]
// @owner        Phillip_J_Fry [2184575]
// @license      Apache License 2.0
// @match        https://www.torn.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

// Made for Phillip_J_Fry [2184575].
// DO NOT EDIT.


const {fetch: origFetch} = window;
window.fetch = async (...args) => {
    console.log("fetch called with args:", args);

    const response = await origFetch(...args);

    /* work with the cloned response in a separate promise
     chain -- could use the same chain with `await`. */

    if (response.url.includes('/profiles.php?step=getMiniProfile')){
      //  console.log("REsponseL : "+response);

        response
            .clone()
            .json()
            .then(function(body){
            var time = body.user.lastAction.seconds;
            insert(time);


        })
            .catch(err => console.error(err))
        ;
    }



    return response;
};

function convert(t){
  //  console.log(t);
    var days = Math.floor(t/86400);
    t = t- 86400 * days;
    var hrs = Math.floor(t/3600);
    t = t - hrs*3600;
    var minutes = Math.floor(t/60);
    t = t - minutes *60;

    var result = '';
    if (days){
        result += `${days} days `;
    }
    if (hrs){
        result += `${hrs} hours `;
    }
    if (minutes){
        result += `${minutes} minutes `;
    }
    result += `${t} seconds`;
   // console.log(result);

    return result;

}
function insert(t){
   // console.log(t);
    if ($('.icons',$('#profile-mini-root')).length > 0){
        if ($('.laction',$('#profile-mini-root')).length == 0){
            var tt = convert(t);
            var ldata = `<p class='laction' style='float:"right";'>Last Action: ${tt}</p>`;
           // console.log(ldata);

            $('.icons',$('#profile-mini-root')).append(ldata);
        }

    }

    else{
        setTimeout(insert,300, t);
    }
}