javascript - 如何使用 JS 和 IMACROS 设置 localStorage 项?
问题描述
我的代码:
SET !VAR2 EVAL ("var title = document.getElementById(\"meta\").innerText; localStorage.setItem(\"title\", title);")
Imacros 控制台输出:
TypeError: result is undefined, line: 13
解决方案
这对我有用:
// get text from div with #divid
TAG POS=1 TYPE=DIV ATTR=ID:divid EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
// set text to localStorage
SET !VAR2 EVAL ("localStorage.setItem('title', \"{{!VAR2}}\"); \"{{!VAR2}}\";")
// reset iMacros variables for later use
SET !VAR2 NULL
SET !EXTRACT NULL