我下面的代码工作。然而,有什么方法可以浓缩/缩小它吗?
chrome.storage.local.get({wsitemnumberget: [], wstitleget: [], wspecialpriceget: [], wspecialprevpriceget: [], wspecialdeldateget: []}, function (result) {
var wsitemnumberget = result.wsitemnumberget;
var wstitleget = result.wstitleget;
var wspecialpriceget = result.wspecialpriceget;
var wspecialprevpriceget = result.wspecialprevpriceget;
var wspecialdeldateget = result.wspecialdeldateget;
var witenumfetch = $('#wsitemnumber').text();
var wspecialtitlefetch = $('#title').val();
var wspecialprice = $('.mwsb-wsp').text();
var wspecialprevprice = $('.mwsb-prevprice').text();
var wspecialdeldate = $('.mwsb-deldate').text();
wsitemnumberget.push({WSItemNumber: witenumfetch});
wstitleget.push({WSTitle: wspecialtitlefetch});
wspecialpriceget.push({WSPrice: wspecialprice});
wspecialprevpriceget.push({WSPrevPrice: wspecialprevprice});
wspecialdeldateget.push({WSDELDate: wspecialdeldate});
chrome.storage.local.set({ wsitemnumberget: wsitemnumberget, wstitleget: wstitleget, wspecialpriceget: wspecialpriceget, wspecialprevpriceget: wspecialprevpriceget, wspecialdeldateget: wspecialdeldateget });`
目前上面的代码使用push将所有的section放入数组中。然而,有一种方法来保持我的名字与数据,并减少代码和输出使用jquery?
设法缩小这个,它仍然可以工作。
可以更小吗?
chrome.storage.local.get({wsitemadded: []}, function (result) {
var wsitemadded = result.wsitemadded;
var witenumfetch = $('#wsitemnumber, .mwsb-wsp, .mwsb-prevprice, .mwsb-deldate').text();
var wspecialtitlefetch = $('#title').val();
var wspecialprice = $('.mwsb-wsp').text();
var wspecialprevprice = $('.mwsb-prevprice').text();
var wspecialdeldate = $('.mwsb-deldate').text();
var wspecialimg = $('#postad-img-0 div img').attr('src');
wsitemadded.push({WSItemNumber: witenumfetch, WSTitle: wspecialtitlefetch, WSImage: wspecialimg, WSPrice: wspecialprice, WSPrevPrice: wspecialprevprice, WSDELDate: wspecialdeldate});
chrome.storage.local.set({ wsitemadded: wsitemadded });
});`