指纹JS V3与访客ID Web一起保存其他变量

发布于 2025-01-26 07:56:46 字数 284 浏览 3 评论 0原文

我已经搜索了类似的问题,但是似乎不是在回答我正在寻找的内容,

因此基本上我有这个网站,在该网站上,表情符号(让我们使用表情符号以使其变得容易)被随机保存在本地存储中。如您所知,这是无效的,因为用户可以简单地清除其历史记录,并且随机价值正在删除。 然后,我发现了有关指纹JS的示例,

<script>

    var res = localStorage.getItem('img');
        if(res == null){
                const myList = ['
              

I have searched through similar questions, but non seems to be answering what I am looking for

So basically I have this website, where an emoji (lets use emoji for it to be easy) is generated randomly was saved in local storage. As you know, it is not effective, since a user can simply clear his/her history and that random value was deleting.
Example of the code

<script>

    var res = localStorage.getItem('img');
        if(res == null){
                const myList = ['????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????'];
                res  = myList[Math.floor(Math.random() * myList.length)];
                localStorage.setItem('img', res);
            }
    console.log(res);
       
    document.querySelectorAll('.emoji').forEach(span => span.textContent = res)

</script>  

Then I found out about the fingerprint JS and was very happy about it, since the user's ID doesnt delete even if the history has been deleted.

However, I don't seem to understand of how to do exact same emoji generation with the fingerprint JS

<script>
    // Initialize the agent at application startup.
    const fpPromise = import('https://openfpcdn.io/fingerprintjs/v3')
      .then(FingerprintJS => FingerprintJS.load())
  
    // Get the visitor identifier when you need it.
    fpPromise
      .then(fp => fp.get())
      .then(result => {
        // This is the visitor identifier:
        const visitorId = result.visitorId
        console.log(visitorId)
        alert(visitorId)
      })
  </script>

I understand that I have to add a const, however, all the time I tried to implement the code for random emoji generation to the fingerprint js, everything failed

Could you give me some advice or an example of the working alike code/idea?

So that at the end the stored values would be like:

ID : 12312312313123

Emoji : ????

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半山落雨半山空 2025-02-02 07:56:47

获取哈希号(我使用此CRC实现),表情符号列表的MODULO长度,然后选择给定的Emoji。

<script>
// Initialize the agent at application startup.
const fpPromise = import('https://openfpcdn.io/fingerprintjs/v3')
.then(FingerprintJS => FingerprintJS.load())

const crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};

// Get the visitor identifier when you need it.
fpPromise
.then(fp => fp.get())
.then(result => {
// This is the visitor identifier:
const visitorId = result.visitorId

const myList = ['

Get the hash number (I used this CRC implementation), modulo length of your emoji list and just pick the given emoji.

<script>
// Initialize the agent at application startup.
const fpPromise = import('https://openfpcdn.io/fingerprintjs/v3')
  .then(FingerprintJS => FingerprintJS.load())

const crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};


// Get the visitor identifier when you need it.
fpPromise
  .then(fp => fp.get())
  .then(result => {
    // This is the visitor identifier:
    const visitorId = result.visitorId

    const myList = ['????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????', '????'];
    const listLength = myList.length

    const visitorIdNumber = crc32(visitorId);
    const selectedEmoji = myList[visitorIdNumber % listLength];
    localStorage.setItem('img', selectedEmoji);
  })
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文