Home > front end >  How an element in the array reference another element?
How an element in the array reference another element?

Time:01-31

I think will be the number of each icon to open the monkeys are stored in oil, built an array to store the name of the icon, images, links, a pop-up message, pop-up information is a function of execution when clicking on the icon to open the link and statistical number

I need to quote the name of the current icon in function, how to use JavaScript to achieve? Or if there are other way?

On the basis of the script to https://greasyfork.org/zh-CN/scripts/404859

 
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'
Image: 'https://i.ibb.co/R9HMTyR/1-5.png',
Host: [' www.bing.com '],
Popup: function (text, name) {
Open (' https://www.bing.com/s? Wd='+ encodeURIComponent (text), name);
console.log(name);
}
},
]



 
The 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). The Times + 1
});
} else {
GM_setValue (a, {
1
'times' :});
}
The console. The log (' times - '+ GM_getValue (a). The Times).

} else {

}
{} the catch (error)
Return GM_openInTab (url, {loadInBackground: true, insert: true, setParent: true});
}
}

I want to store this data in grease monkey, open Google, Bing 4
 
{
"Google" : {
"Times" : "1",
},
"Bing" : {
"Times" : "4",
},

}
  • Related