Ok wersja poprawiona, działanie niezależne przycisków.
/*
* This program is copyright © 2014 Cezary Jackiewicz and is distributed under the terms of the GNU GPL
* version 2.0 with a special clarification/exception that permits adapting the program to
* configure proprietary "back end" software provided that all modifications to the web interface
* itself remain covered by the GPL.
* See http://gargoyle-router.com/faq.html#qfoss for more information
*/
usbrelayS = new Object();
var flaga = new Array();
var flagaset = "1"
function createEnabledCheckbox()
{
enabledCheckbox = createInput('checkbox');
return enabledCheckbox;
}
function createEnabledTextbox()
{
enabledTextbox = createInput('textbox');
enabledTextbox.size = "1";
return enabledTextbox;
}
function getCookie(name){
var str = '; '+ document.cookie +';';
var index = str.indexOf('; '+ escape(name) +'=');
if (index != -1) {
index += name.length+3;
var value = str.slice(index, str.indexOf(';', index));
return unescape(value);
}
}
function setCookie(nazwa, wartosc, dni) {
if (dni) {
var data = new Date();
data.setTime(data.getTime()+(dni*24*60*60*1000));
var expires = "; expires="+data.toGMTString();
} else {
var expires = "";
}
document.cookie = nazwa+"=" + wartosc + expires + "; path=/";
}
function chboxcookie(node)
{
var row = node.parentNode.parentNode.firstChild.firstChild.data
var pulscheck = document.getElementById("push" + row);
setCookie("checkps" + row, pulscheck.checked, "7")
resetData();
}
function tboxcookie(node)
{
var row = node.parentNode.parentNode.firstChild.firstChild.data
var timeset = document.getElementById("times" + row);
setCookie("textps" + row, timeset.value, "7")
}
function resetData()
{
var columnNames = usbrelayS.Columns;
var usbrelayTableData = new Array();
var serviceIds = new Array();
if (ports.length == 0)
{
document.getElementById("no_usbrelay").style.display = "block";
return;
}
for (idx=0; idx<ports.length; idx++)
{
if (flagaset == "1")
{
flaga[ports[idx][0]] = "1"
}
var img = document.createElement("img");
img.style.cssText= "margin-top:5px;";
var enabledCheckbox = createEnabledCheckbox();
enabledCheckbox.id = "push" + ports[idx][0]
var enabledTextbox = createEnabledTextbox();
enabledTextbox.id = "times" + ports[idx][0]
if (getCookie("checkps" + ports[idx][0]) == "true")
{
enabledCheckbox.checked = true
} else {
enabledTextbox.disabled = true
}
if (getCookie("textps" + ports[idx][0]) != null)
{
enabledTextbox.value = getCookie("textps" + ports[idx][0]);
}
if (ports[idx][1] == "on")
{
img.src = "img/green-power-button.png";
img.onclick = function(){offRelay(this);}
} else {
img.src = "img/red-power-button.png";
img.onclick = function(){onRelay(this);}
}
enabledCheckbox.onchange = function(){chboxcookie(this);}
enabledTextbox.onchange = function(){tboxcookie(this);}
var tmp = uciOriginal.get("usbrelay", "desc", ''+ports[idx][0])
if (tmp == "") { tmp = "..."; }
var anchor = document.createElement("a");
anchor.href="usbrelay_schedule.sh?port=" + ports[idx][0];
anchor.innerHTML = tmp;
anchor.style.css = "a{text-decoration:none}";
usbrelayTableData.push([ports[idx][0], anchor, img, enabledCheckbox, enabledTextbox]);
}
flagaset = "0"
var usbrelayTable = createTable(columnNames, usbrelayTableData, "usbrelay_table", false, false);
var tableContainer = document.getElementById('usbrelay_table_container');
if (tableContainer.firstChild != null)
{
tableContainer.removeChild(tableContainer.firstChild);
}
tableContainer.appendChild(usbrelayTable);
}
function onRelay(node)
{
onoffRelay(node.parentNode.parentNode, "on");
}
function offRelay(node)
{
onoffRelay(node.parentNode.parentNode, "off");
}
function onoffRelay(row, action)
{
var port = row.firstChild.firstChild.data;
var czass = document.getElementById("times" + port).value;
var pulscheck = document.getElementById("push" + port);
var cmds = [ "/usr/lib/gargoyle/usbrelay.sh " + action + " " + port, "/usr/lib/gargoyle/usbrelay.sh status" ];
var param = getParameterDefinition("commands", cmds.join("\n")) + "&" + getParameterDefinition("hash", document.cookie.replace(/^.*hash=/,"").replace(/[\t ;]+.*$/, ""));
var stateChangeFunction = function(req)
{
if(req.readyState == 4)
{
var lines = req.responseText.split(/[\r\n]+/);
ports.length = 0;
for (idx=0; idx < lines.length; idx++)
{
if (lines[idx].match(/:o/))
{
stat=lines[idx].split(":");
ports.push([ stat[0], stat[1] ]);
}
}
if (pulscheck.checked)
{
if (flaga[port] == "1")
{
if (action == "on")
{
action = "off"
} else {
action = "on"
}
resetData();
flaga[port] = "0"
window.setTimeout( function() { onoffRelay(row, action); }, czass + "000");
} else {
flaga[port] = "1"
}
}
resetData();
setControlsEnabled(true);
}
}
runAjax("POST", "utility/run_commands.sh", param, stateChangeFunction);
}
P.S.
@roblad moje pojęcie o javascript jest takie ile przeczytam w internecie a przy tym się czegoś nauczę, a więc jak by Ci się chciało to sam byś to zrobił.
Pogrzeb sobie w skrypcie pomyśl jak to działa, a działa naprawdę intuicyjnie, a zobaczysz że dasz radę.
Tobie po prostu się nie chce, a nie nie potrafisz. 
TL-WR1043ND: HDD-USB, extroot, LCD, Pilot, MP3 - Radio Player, NAS, Torrent, FTP, Sterowanie głosem, Komunikaty Głosowe, Termometr, PowerSwitch - Sterownik oświetlenia, Budzik, LTE - ODU IDU 200
Raspberry Pi + HDMI-VGA + Lcd Controller + Lcd z laptopa = Pogodynka
