如何在刷新时开始编号 [英] How to start number on refresh

查看:31
本文介绍了如何在刷新时开始编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码适用于 Tamper-monkey,适用于亚马逊.它只是改变了你有多少钱的外观并且它会计数,我想知道是否有可能使它成为这样,当你刷新计数器时,无论它是什么数字.

This code is for Tamper-monkey and it works amazon. It just changes the look of how much money you have and it counts up, I wanted to know if it is possible to make it so whatever number it is on when you refresh the counter starts at that number.

var oof = document.getElementById("gc-ui-balance-gc-balance-value");
oof.innerHTML = "0";
function animateValue(id){
var obj = document.getElementById(id);
var current = parseInt(obj.innerHTML);

setInterval(function(){
    obj.innerHTML =current++;
},0.1);
}

animateValue('gc-ui-balance-gc-balance-value');

推荐答案

您需要将数字保存在浏览器的内存中,您有两个选择:

You need to save the number in browser's memory, you have two options:

如果没有存储任何内容,初始值将是存储值或默认值.

And the initial value would be the stored value or the default value if nothing's stored.

localStorage 示例:

Example with localStorage:

var oof = document.getElementById("gc-ui-balance-gc-balance-value");

var lastCount = localStorage.getItem("lastCount");

oof.innerHTML = lastCount || "0";

function animateValue(id) {
    var obj = document.getElementById(id);
    var current = parseInt(obj.innerHTML);

    setInterval(function () {
        var nextCount = current++;
        localStorage.setItem("lastCount", nextCount);
        obj.innerHTML = nextCount;
    }, 0.1);
}

这篇关于如何在刷新时开始编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆