尝试使用Tempermonkey随机更改Steam背景,总是出现“解析错误:意外令牌”错误

问题描述 投票:0回答:1

这里,我的代码

(function() {
    'use strict';

    var imagesArray = [

        "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/items/583660/361fda7dfb819158079afbf50b7ca13d1ffa6468.jpg",
        "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/items/203770/c6f5ea583b7883659e35fbedf1b21220dc230dda.jpg"

                  ];

function setBackground(){
    const background = document.querySelector('.profile_background_image_content')
    const randomImage = imagesArray[Math.floor(Math.random() * imagesArray.length + 1)]
    background.style.backgroundImage = url(${randomImage}) !important
}

setBackground()

})();

嗯,老实说,我不知道为什么会给出错误或我正在做正确的事情。我会很感谢您的帮助。

javascript css userscripts
1个回答
0
投票

您应该包装这个

url(${randomImage}) !important

带有这样的反引号

   `url(${randomImage}) !important`
© www.soinside.com 2019 - 2024. All rights reserved.