问题描述
我想在 Tampermonkey 内存中保存一个 Array 的每个元素的打开次数信息,我创建了一个包含名称、图像、弹出元素的对象,弹出包含一个计算每个站点打开次数的函数。
需要在函数中通过popup元素引用name元素,JavaScript能实现吗?
或者有其他方法吗?
var iconArray = [
{
name: 'Google',image: 'https://i.ibb.co/R9HMTyR/1-5.png',host: ['www.google.com'],popup: function (text,name) {
open('https://www.google.com/s?wd=' + encodeURIComponent(text),name);
console.log(name);
}
},{
name: 'Bing',host: ['www.bing.com'],name) {
open('https://www.bing.com/s?wd=' + encodeURIComponent(text),]
function open(url,a) {
try {
if(GM_openInTab(url,{ loadInBackground: true,insert: true,setParent :true })){
if(GM_getValue(a).times){
GM_setValue(a,{
'times': GM_getValue(a).times + 1
});
}else{
GM_setValue(a,{
'times': 1
});
}
console.log('times-'+GM_getValue(a).times);
} else{
}
} catch (error) {
return GM_openInTab(url,setParent :true });
}
}
我希望Tampermonkey中保存的数据是这样的,如果我打开谷歌1次,打开bing 4次。
{
"Google": {
"times": "1",},"Bing": {
"times": "4",}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)