我有一个用户脚本,我用它来添加预定义搜索的自定义列表。为此,我使用dat.gui创建了一个GUI,并通过对象的键迭代来创建按钮列表。键的值用作搜索查询。
我的JavaScript:
NodeList.prototype.forEach = Array.prototype.forEach;
var shows = {
'Agents of S.H.I.E.L.D.' : 'marvels agents of s.h.i.e.l.d.',
'Arrow' : 'arrow s',
'Brooklyn Nine-Nine' : 'brooklyn nine-nine',
'Castle' : 'castle 2009',
'Chicago Fire' : 'chicago fire',
'Chicago P.D.' : 'chicago p.d.',
'Constantine' : 'contanstine s',
'Doctor Who' : 'doctor who',
'Gotham' : 'gotham s',
'Grimm' : 'grimm s',
'Madam Secretary' : 'madam secretary',
'NCIS LA' : 'ncis los angeles',
'Resurrection' : 'resurrection',
'Saturday Night Live' : 'saturday night live',
'Scandal' : 'scandal s',
'Scorpion' : 'scorpion s',
'Stalker' : 'stalker s',
'The 100' : 'the 100 s',
'The Big Bang Theory' : 'the big bang theory',
'The Blacklist' : 'the blacklist',
'The Flash' : 'the flash',
'The Tonight Show Starring Jimmy Fallon' : 'jimmy fallon',
'Z Nation' : 'z nation'
},
show = function() {
for (var k in shows) {
this[k] = function() {
document.getElementById('tsstac').value = shows[k].replace(/ /g, '.');
document.querySelectorAll('[type=submit]')[0].click();
};
}
};
window.onload = function() {
var text = new show(),
gui = new dat.GUI();
for (var k in shows) {
gui.add(text, k);
}
document.querySelectorAll('li.cr>div>span.property-name').forEach(function(v) {
v.style.width = '100%';
});
};
基本上,每当我点击“关闭控件”按钮时,它就会决定永远跟随我的鼠标调整大小,直到刷新为止。即使我尝试重新打开GUI,它仍然跟随鼠标。我想它会对按钮做同样的事情,虽然它们在点击时会转到新页面,因此会重置gui。
我该如何解决这个问题?此外,是否有用于dat.GUI的API或任何文档?
答案 0 :(得分:0)
通过更改以下内容来解决此问题:
gui = new dat.GUI({
resizable : false
});