我想將每個圖示打開的次數分別存盤在油猴里面,建了一個陣列分別存放圖示的名稱、圖片、鏈接、彈出的資訊,彈出的資訊是一個函式,點擊圖示時執行打開鏈接和統計次數
我需要在函式里面參考當前的圖示的名稱,如何通過 JavaScript 實作呢?或者是否有其他的辦法?
在這個腳本基礎上改的 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);
}
},
]
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, { loadInBackground: true, insert: true, setParent :true });
}
}
我想在油猴里面這樣存放資料,打開 Google 1 次,Bing 4 次
{
"Google": {
"times": "1",
},
"Bing": {
"times": "4",
},
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/254634.html
標籤:JavaScript
上一篇:ubuntu系統下tomcat8.5啟動 AJP /1.3 協議8009埠失敗,8080埠正常
下一篇:js陣列、物件解構,物件解構賦值
