There are 2 previous versions of this script.
// HOT EPG user script
// version 0.3
// 2008-02-03
// Copyright (c) 2008, 2009 Yehuda B.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// http://www.gnu.org/licenses/gpl.html
//
// ==UserScript==
// @name HOT EPG fix
// @namespace http://yehudab.com
// @description Fix schedule display and search in HOT (Israel cable TV provider) electronic program guide pages. Version 0.3
// @include http://www.hot.net.il/*
// ==/UserScript==
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
var selectHash = new Array();
function fixSearch()
{
if (document.getElementById("searchMode1") != null)
{
setExclusiveSelect("searchMode", 1, 2, 2);
setExclusiveSelect("programsTimeScope", 0, 3, 0);
setExclusiveSelect("advSearchFilter", 0, 3);
fixListCB("listGCCB");
unsafeWindow.setSearchMode = function(n)
{
if (n==1)
document.getElementById("showprograms").style.display="block"
else
document.getElementById("showprograms").style.display="none"
for(var i=1; i<3; i++)
{
if(n!=i)
{
document.getElementById("searchModeContent"+i).style.display = "none";
}
else
{
document.getElementById("searchModeContent"+i).style.display = "block";
}
}
unsafeWindow.searchMode = n;
}
unsafeWindow.setProgramsTimeScope = function(n)
{
unsafeWindow.programsTimeScope = n;
}
unsafeWindow.openChannelsByGenrePop = function(n,lang)
{
var channelUrl = document.getElementById("channelUrl").value;
var genre = document.getElementById("listGCCB"+n).getAttribute("value");
window.open(channelUrl+"?lang="+lang+"&genre="+genre+"&o="+n,"pop","width=329,height=360px,top=100,left=100");
}
unsafeWindow.submitSearch = function()
{
switch(unsafeWindow.searchMode)
{
case 0:
var str = "";
var cnt = 0;
var btn;
while(true)
{
btn = document.getElementById("listGCB"+cnt);
if (btn == null)
break;
if (isSelected(btn))
{
str += btn.getAttribute("value") + "~";
}
cnt++;
}
if (str.length > 0)
str = str.substr(0,str.length-1);
unsafeWindow.goSearch(unsafeWindow.searchMode+"#"+str+"#"+unsafeWindow.programsTimeScope);
break;
case 1:
var str = "";
var cnt = 0;
var btn;
while(true)
{
btn = document.getElementById("listGCCB"+cnt);
if (btn == null)
break;
if (isSelected(btn))
{
str += btn.getAttribute("value");
if(btn.getAttribute("channelsData"))
{
str += "$"+btn.getAttribute("channelsData");
}
else
{
str += "$*";
}
str += "~";
}
cnt++;
}
if (str.length > 0)
str = str.substr(0,str.length-1);
GM_log(str)
unsafeWindow.goSearch(unsafeWindow.searchMode+"#"+str+"#"+unsafeWindow.programsTimeScope);
break;
case 2:
unsafeWindow.goSearch(unsafeWindow.searchMode+"##"+unsafeWindow.programsTimeScope);
break;
case 3:
unsafeWindow.goSearch(unsafeWindow.searchMode+"##");
break;
}
}
unsafeWindow.setSearchTab = function(n)
{
var oAll = document.all;
for(var i=1; i<=2; i++)
{
if(n!=i)
{
document.getElementById("searchTab"+i).src = document.getElementById("searchTab"+i).getAttribute("srcoff");
document.getElementById("tabContent"+i).style.display = "none";
}
else
{
document.getElementById("searchTab"+i).src = document.getElementById("searchTab"+i).getAttribute("srcon");
document.getElementById("tabContent"+i).style.display = "block";
}
}
if(n==1)
{
document.getElementById("timeSearch").style.display = "block";
unsafeWindow.searchMode = 2;
}
else
{
document.getElementById("timeSearch").style.display = "none";
unsafeWindow.searchMode = 3;
}
}
unsafeWindow.setAdvSearchFilter = function()
{
var str = "";
for(var i=0; i<4; i++)
{
var btn = document.getElementById("advSearchFilter"+i);
if(isSelected(btn))
{
str+=btn.getAttribute("value")+"~";
}
}
document.getElementById("advSearchFilter").value = str.substr(0,str.length-1);
}
unsafeWindow.setSearchMode(2);
unsafeWindow.setProgramsTimeScope(0);
addGlobalStyle(".program_search, .cal-input {background:white ; border:1px inset}");
}
}
function fixChannelList()
{
unsafeWindow.selectDeselectAllCB = function(obj)
{
toggleButtn(obj, !isSelected(obj));
var cnt = 0;
var btn;
while (true)
{
btn = document.getElementById("channelCB"+cnt);
if (btn == null)
break;
if (isSelected(btn) != isSelected(obj))
{
toggleButtn(btn, isSelected(obj));
}
cnt++;
}
unsafeWindow.saveChannelsData();
}
unsafeWindow.initChannelsData = function()
{
var channelsData = unsafeWindow.pObj.getAttribute("channelsData");
var cnt = 0;
var btn;
while(true)
{
btn = document.getElementById("channelCB"+cnt);
if (btn == null)
break;
if (channelsData != null && channelsData.indexOf(btn.getAttribute("value"))>-1)
{
toggleButtn(btn, true);
}
cnt++;
}
}
unsafeWindow.saveChannelsData = function()
{
var str = "";
var cnt = 0;
var btn;
while(true)
{
btn = document.getElementById("channelCB"+cnt);
if (btn == null)
break;
if (isSelected(btn)){
str += btn.getAttribute("value")+"^";
}
cnt++;
}
if (str.length > 0)
str = str.substr(0,str.length-1);
GM_log(str)
unsafeWindow.pObj.setAttribute("channelsData", str);
toggleButtn(unsafeWindow.pObj, str.length > 0);
}
unsafeWindow.clickCB = function(btn)
{
toggleButtn(btn, !isSelected(btn));
var selectAllCB = document.getElementById("selectAllCB");
if (isSelected(selectAllCB) && !isSelected(btn))
toggleButtn(selectAllCB, false);
unsafeWindow.saveChannelsData();
}
}
function setExclusiveSelect(prefix, from, to, initial)
{
var i;
for (i = from; i <= to; i++)
{
var btn = document.getElementById(prefix + i);
if (btn != null)
{
btn.addEventListener("click",
function()
{
var j;
for (j = from; j <= to; j++)
{
var otherBtn = document.getElementById(prefix + j);
toggleButtn(otherBtn, otherBtn == this);
}
},
false);
}
}
if (initial != null)
{
var initialBtn = document.getElementById(prefix + initial);
toggleButtn(initialBtn, true);
}
}
function fixListCB(prefix)
{
var i = 0;
while (fixElementInListCB(prefix, i))
i++;
}
function fixElementInListCB(prefix, i)
{
var cb = document.getElementById(prefix + i);
if (cb == null)
return false;
cb.addEventListener("click",
function()
{
toggleButtn(cb, !isSelected(cb));
},
false);
return true;
}
function toggleButtn(btn, isOn)
{
if (btn != null)
{
if (isOn)
{
btn.src = "/EPG/images/he/Programs/select_on.gif";
selectHash[btn.id] = true;
}
else
{
btn.src = "/EPG/images/he/Programs/select_off.gif";
selectHash[btn.id] = false;
}
}
}
function isSelected(btn)
{
if (btn != null)
{
if (btn.src.match(/undefined/))
{
if (selectHash[btn.id])
return true;
return false;
}
else if (btn.src.match(/select_on.gif/))
{
return true;
}
}
return false;
}
function fixTimeline()
{
var flashvars = "";
var EPGViewer = document.getElementById("EPGViewer");
if (EPGViewer != null)
{
var i;
for (i = 0; i < EPGViewer.childNodes.length; i++)
{
if (EPGViewer.childNodes[i].name == "flashvars")
{
flashvars = EPGViewer.childNodes[i].value;
break;
}
}
}
if (flashvars != "")
{
EPGViewer.innerHTML = EPGViewer.innerHTML.replace(/<embed/, "<embed flashvars=\"" + flashvars + "\"");
}
}
function fixHeaderSearch()
{
unsafeWindow.goToSearchResults = function()
{
var searchInput = document.getElementById("Header_searchText");
var searchSelect = document.getElementById("Header_searchSections");
document.location.href = searchSelect.getAttribute("searchPageURL")+"&Search="+searchInput.value.replace(/(^\s+)|(\s+$)/g,'')+"&Category="+searchSelect.value
return;
}
unsafeWindow.ValidateAndGoToSearchResults = function(textObjId, objTabId, objErrId)
{
var searchInput = document.getElementById(textObjId);
if (searchInput == null)
{
unsafeWindow.goToSearchResults();
return;
}
var searchSelect = document.getElementById("Header_searchSections");
document.location.href = searchSelect.getAttribute("newSearchPageURL").replace("PageNum","oldNum")+"&Search="+searchInput.value.replace(/(^\s+)|(\s+$)/g,'')+"&TabId="+objTabId;
}
}
function fixDayOfWeek()
{
var titleRow = document.getElementById("ucSearchTVTemplate_trTitle");
var days = ['\u05d0', '\u05d1', '\u05d2', '\u05d3', '\u05d4', '\u05d5', '\u05e9']; //['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'];
if (titleRow != null)
{
var dayCellIdx = -1, i, r, c, dayCell, l = titleRow.cells.length;
for (i = 0; i < l; i++)
{
c = titleRow.cells[i];
if (c.textContent == "\u05ea\u05d0\u05e8\u05d9\u05da \u05e9\u05d9\u05d3\u05d5\u05e8") //"תאריך שידור"
{
c.textContent = "\u05ea\u05d0\u05e8\u05d9\u05da"; //"תאריך"
dayCellIdx = i;
}
else if (c.textContent == "\u05e9\u05e2\u05ea \u05e9\u05d9\u05d3\u05d5\u05e8") // "שעת שידור"
{
c.textContent = "\u05e9\u05e2\u05d4"; //"שעה"
}
}
if (dayCellIdx < 0)
return;
dayCell = titleRow.insertCell(dayCellIdx);
dayCell.textContent = "\u05d9\u05d5\u05dd"; //"יום"
var colGroup = titleRow.parentNode;
while (colGroup != null)
{
GM_log(colGroup.tagName);
if (colGroup.tagName == "COLGROUP")
{
l = colGroup.childNodes.length;
var actualCol = 0;
for (i = 0; i < l; i++)
{
if (colGroup.childNodes[i].tagName == "COL")
{
GM_log(actualCol)
if (actualCol == dayCellIdx)
{
colGroup.childNodes[i+2].setAttribute("width", "60");
newCol = document.createElement("COL");
newCol.setAttribute("width", "35");
colGroup.insertBefore(newCol, colGroup.childNodes[i]);
break;
}
actualCol++;
}
}
break;
}
colGroup = colGroup.previousSibling;
}
if (dayCellIdx >= 0)
{
var tBody = titleRow.parentNode;
l = tBody.rows.length;
for (i = 1; i < l; i++)
{
r = tBody.rows[i];
dateStr = r.cells[dayCellIdx].textContent;
dArr = dateStr.split("/");
d = new Date();
d.setDate(parseInt(dArr[0], 10));
d.setMonth(parseInt(dArr[1], 10)-1);
d.setFullYear(parseInt(dArr[2], 10));
dayCell = r.insertCell(dayCellIdx);
dayCell.textContent = days[d.getDay()];
}
}
}
}
if (window.location.href.match(/Templates\/Homepage/i))
fixSearch();
else if (window.location.href.match(/Templates\/EPGTimeline/i))
fixTimeline();
else if (window.location.href.match(/channelsListByGenre/i))
fixChannelList();
if (document.getElementById("Header_searchSections"))
fixHeaderSearch();
if (document.getElementById("ucSearchTVTemplate_trTitle"))
fixDayOfWeek();
