如何使警告框的输入更改 localstorage 中的值?
How do I make an alert box's input change the value in localstorage?
我正在尝试制作一个 bookmarklet 来修改在线游戏的“本地存储”,但我想让它向用户询问“硬币”的数量用户想要通过警报。
这是代码
localStorage.setItem('mjs-drift-boss-game-v1.0.1-dailyreward',
'{"sound":0.7,"music":0,"score":-3,"hasShownTutorial":true,"collectedCoin":999999,"cars":[0,1,2,3,4,5,6,7],"currentCar":7,"currentTip":0,"booster1":99999999,"booster2":9999999,"booster3":999999,"ko":0,"hasShownBoosterTutorial":true}')
alert('Modifed Game!')
location.reload();
你可以这样做:
const data = JSON.parse(localStorage.getItem('mjs-drift-boss-game-v1.0.1-dailyreward'));
const coins = window.prompt('Set Coins', data.collectedCoin);
localStorage.setItem('mjs-drift-boss-game-v1.0.1-dailyreward',
'{"sound":0.7,"music":0,"score":-3,"hasShownTutorial":true,"collectedCoin":' + coins + ',"cars":[0,1,2,3,4,5,6,7],"currentCar":7,"currentTip":0,"booster1":99999999,"booster2":9999999,"booster3":999999,"ko":0,"hasShownBoosterTutorial":true}')
alert('Modifed Game!')
location.reload();
这样你就可以得到预填充的最后一个存储值,你可以将它更改为新值,该值存储在 localStorage 中。
我正在尝试制作一个 bookmarklet 来修改在线游戏的“本地存储”,但我想让它向用户询问“硬币”的数量用户想要通过警报。
这是代码
localStorage.setItem('mjs-drift-boss-game-v1.0.1-dailyreward',
'{"sound":0.7,"music":0,"score":-3,"hasShownTutorial":true,"collectedCoin":999999,"cars":[0,1,2,3,4,5,6,7],"currentCar":7,"currentTip":0,"booster1":99999999,"booster2":9999999,"booster3":999999,"ko":0,"hasShownBoosterTutorial":true}')
alert('Modifed Game!')
location.reload();
你可以这样做:
const data = JSON.parse(localStorage.getItem('mjs-drift-boss-game-v1.0.1-dailyreward'));
const coins = window.prompt('Set Coins', data.collectedCoin);
localStorage.setItem('mjs-drift-boss-game-v1.0.1-dailyreward',
'{"sound":0.7,"music":0,"score":-3,"hasShownTutorial":true,"collectedCoin":' + coins + ',"cars":[0,1,2,3,4,5,6,7],"currentCar":7,"currentTip":0,"booster1":99999999,"booster2":9999999,"booster3":999999,"ko":0,"hasShownBoosterTutorial":true}')
alert('Modifed Game!')
location.reload();
这样你就可以得到预填充的最后一个存储值,你可以将它更改为新值,该值存储在 localStorage 中。